I am making a target shooting game for an ICT project on BYOB, and i dont know how to put this as coding as there are no blocks for it. Could anyone help me. Thanks. The coding that i want to enter is: If target(one of the sprites) not clicked, change lives by -1. Or something like this: If target not clicked for ...seconds, change lives by -1.
There is only the <when[ ]clicked> control block and not the opposite
Offline
Instead of using 'When sprite1 clicked', you could put:
If touching mouse and mouse down
It won't be exactly the same, but it's similar.
Offline
<when[ ]clicked>
<reset timer>
<when green flag clicked>
<reset timer>
<forever if><( <timer> <>> 5 )>
<change{ health }by( -1 )>
<reset timer>
<end>
Offline
There is no way to tell if the sprite is showing or hiding, unless you keep track with a variable.
Oh, and you should know that the timer is universal, so that script will only work for one enemy. Do you want it to work for more?
<when green flag clicked>
<reset timer>
<forever>
<if><( <{ showing? }> <>> 5 )>
<change{ health }by( -1 )>
<wait( 2 )secsc>
<else>
<reset timer>
<end>
<end>
Last edited by MoreGamesNow (2011-11-13 17:42:01)
Offline
manoz wrote:
yes, for more than one target, i need it for 8 targets. and how do u keep track of the hiding and showing with a variable?
Whenever you use the "hide" block for the sprite, change a variable too, and whenever you use the "show" block change the same variable. For instance
[show] [change variable (hidden) to (false) ] [hide] [change variable (hidden) to (true) ]
Offline
Here's the code for multiple sprites:
set [private variable] to( timer ) forever { if( [ ((timer)-(private variable)) > (5) ] AND [(hidden) = (false)] ) { change [health] by (-1) wait( 2 ) secs } <else> { set [private variable] to (timer) } }
Last edited by MoreGamesNow (2011-11-13 18:40:39)
Offline
manoz wrote:
what is the "private variable" meant to be??
Scratch Wiki wrote:
Local, (or private/personal,) variables are created the same way as global, but in the variable creation dialog, choose "For this sprite only". Personal variables can only be changed by their owner, but can be read by other sprites using the () of () block. The Stage cannot have personal variables.
http://wiki.scratch.mit.edu/wiki/Variable
Offline
My previous script may have been incorrect, sorry. Here's a revised script with comments
[When I receive ("show")] // when I (the enemy) am told to come out set [hidden] to [false] // tell myself that I am not hidden set [t] to (timer) // set a private variable to the timer wait until < (timer - t > 4) OR ( hidden = "true" ) > // wait until it has been four seconds or I am hidden repeat until < hidden = true > // repeat until I am hidden { change [health] by (-1) // change health by -1 wait (1) secs }
In essence, it waits 4 seconds using the timer, unless the sprite is killed (e.g. "hidden"). If it isn't killed in 4 seconds, it starts dealing damage until it is killed. The script could probably be simplified by replacing the "wait until <>" line with "wait 4 secs", but this way, if it is killed sooner, the script immediately stops, which may or may not be necessary.
Offline