From: Simon Krahnke Date: 2008-04-19T20:35:05+09:00 Subject: Re: thread question * Heesob Park (2008-04-17) schrieb: > Here is a working code: Why are you using { } for multi line blocks? > def poison > $poisoned = Thread.new { Argh, global variables. @poisoned = Thread new { > hp = 100 > maxhp = 300 > loop { > Thread.stop if Thread.current["state"]=="stop" You can just call return instead of Thread.stop. > hp -= (rand(hp * (10 - 5 + 1)/100) + hp*5/100) hp = (hp * (0.95 + 0.02 * rand)).round > puts 'Your HP dropped! ' + hp.to_s + '/' + maxhp.to_s puts "Your HP dropped to #{hp} of #{maxhp}!" > sleep 1 > } > } > end > def antidote raise "no thread!" unless @poisoned > puts "call antidote" @poisoned["state"] = "stop" > end mfg, simon .... l