diff options
| author | Amir Rajan <[email protected]> | 2020-09-11 02:02:01 -0500 |
|---|---|---|
| committer | Amir Rajan <[email protected]> | 2020-09-11 02:02:57 -0500 |
| commit | 33ec37b141e896b47ed642923fd33b0c658ae9fb (patch) | |
| tree | a40d3e5d41beeb06508200078f6f26b0ee57d6a4 /samples/10_advanced_debugging/01_trace_debugging | |
| parent | 958cf43779d2bf528869e80511c4c4f2a433b2db (diff) | |
| download | dragonruby-game-toolkit-contrib-33ec37b141e896b47ed642923fd33b0c658ae9fb.tar.gz dragonruby-game-toolkit-contrib-33ec37b141e896b47ed642923fd33b0c658ae9fb.zip | |
synced samples
Diffstat (limited to 'samples/10_advanced_debugging/01_trace_debugging')
| -rw-r--r-- | samples/10_advanced_debugging/01_trace_debugging/app/main.rb | 53 | ||||
| -rw-r--r-- | samples/10_advanced_debugging/01_trace_debugging/license-for-sample.txt | 9 |
2 files changed, 62 insertions, 0 deletions
diff --git a/samples/10_advanced_debugging/01_trace_debugging/app/main.rb b/samples/10_advanced_debugging/01_trace_debugging/app/main.rb new file mode 100644 index 0000000..33f15b3 --- /dev/null +++ b/samples/10_advanced_debugging/01_trace_debugging/app/main.rb @@ -0,0 +1,53 @@ +class Game + attr_gtk + + def method1 num + method2 num + end + + def method2 num + method3 num + end + + def method3 num + method4 num + end + + def method4 num + if num == 1 + puts "UNLUCKY #{num}." + state.unlucky_count += 1 + if state.unlucky_count > 3 + raise "NAT 1 finally occurred. Check app/trace.txt for all method invocation history." + end + else + puts "LUCKY #{num}." + end + end + + def tick + state.roll_history ||= [] + state.roll_history << rand(20) + 1 + state.countdown ||= 600 + state.countdown -= 1 + state.unlucky_count ||= 0 + outputs.labels << [640, 360, "A dice roll of 1 will cause an exception.", 0, 1] + if state.countdown > 0 + outputs.labels << [640, 340, "Dice roll countdown: #{state.countdown}", 0, 1] + else + state.attempts ||= 0 + state.attempts += 1 + outputs.labels << [640, 340, "ROLLING! #{state.attempts}", 0, 1] + end + return if state.countdown > 0 + method1 state.roll_history[-1] + end +end + +$game = Game.new + +def tick args + trace! $game # <------------------- TRACING ENABLED FOR THIS OBJECT + $game.args = args + $game.tick +end diff --git a/samples/10_advanced_debugging/01_trace_debugging/license-for-sample.txt b/samples/10_advanced_debugging/01_trace_debugging/license-for-sample.txt new file mode 100644 index 0000000..100dcec --- /dev/null +++ b/samples/10_advanced_debugging/01_trace_debugging/license-for-sample.txt @@ -0,0 +1,9 @@ +Copyright 2019 DragonRuby LLC + +MIT License + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
