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/app/main.rb | |
| 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/app/main.rb')
| -rw-r--r-- | samples/10_advanced_debugging/01_trace_debugging/app/main.rb | 53 |
1 files changed, 53 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 |
