Robert Klemme
4/17/2008 7:50:00 AM
2008/4/17, Zoe Phoenix <dark_sgtphoenix@hotmail.com>:
> Okay, I took someone's advice in an earlier post I made on how to poison
> a character in a test game I wanted to make by making a thread. I'm not
> sure if this is correct or not, but this is what I have:
>
> def poison
> poisoned = thread.new
"thread" needs to be spelled uppercase and it needs a block.
> poisoned do
What is "poisoned"?
> Character.hp - (rand(Character.hp * (10 - 5 + 1)/100) +
> Character.hp*5/100)
You are using a constant for the character? I would guess that there
will be multiple characters in your game.
Also, you are not updating Character.hp (there is no assignment). And
if you do, you have a synchronization issue, i.e. you need mutual
exclusion for the update since I am assuming you will access hp from
other threads as well.
> puts 'Your HP dropped!' + Character.hp + '/' + Character.maxhp
> sleep 20 #thread sleeps for 20 seconds
> end
> end
>
>
> Can I do it this way, so "Character.poison" would start the thread? If
> this would work, how would I use an "antidote" item to stop the thread?
It won't work for various reasons mentioned above.
Kind regards
robert
--
use.inject do |as, often| as.you_can - without end