Hello, Scratchers!
I am brand new to Scratch- to any programming, actually.
I'm making your basic dog-chase-cat game. My plan is to give the dog a set amount of Health Points, and if the cat can peg the dog with a ball of yarn enough times, the dog will pass out and the cat will win. Otherwise, if the dog catches the cat, the game is over.
I created a variable called "Dog Health Points" and set it to start at 5. I've managed to make the variable count down by 1 every time a ball of yarn hits the dog. However, what I CAN'T figure out how to do is to set up a command that recognizes that the variable is set to 0 so that the cat can win.
I want something like:
If Dog Health Points = 0
broadcast "I won!"
...and that would trigger the "Game Over- You won!" message.
Thanks so much to anyone that can help!
Offline
Hi SiroccoDream
What you must do is...
Create a 'Game Over' Background...
Put an IF command from control tag in where you want to check the variable in the main menu...
Then put an operator < which is less than inside it....
On the left side put in the 'Dog health Points' bubble which is from Variables menu...
On the right put in 1... this is better than =0 because you could miss the trigger but try it as an alternative to avoid repetition.
Inside the 'pacman mouth' put Broadcast 'Game End'
In the Stage area put in...
When I receive 'Game End' from Control tab...
join...
switch to background 'Game Over'
Hope that helps
Regards
MrDCO
Offline
Ahhh thank you, MrDCO!
Green operators are my friends.
Offline
You should actually do this:
when green flag clicked wait until <(Dog Health Points) = [0]> broadcast [I won! v]
The if block would run as soon as the project started, causing it to always evaluate false.
Offline