This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2011-11-13 14:03:15

manoz
New Scratcher
Registered: 2011-11-13
Posts: 13

Help

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

 

#2 2011-11-13 14:34:03

RedRocker227
Scratcher
Registered: 2011-10-26
Posts: 1000+

Re: Help

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.


Why

Offline

 

#3 2011-11-13 15:25:03

manoz
New Scratcher
Registered: 2011-11-13
Posts: 13

Re: Help

thanks, might work. could you write out the script for that so i don't get it wrong

Offline

 

#4 2011-11-13 15:25:28

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: Help

<when[  ]clicked>
<reset timer>

<when green flag clicked>
<reset timer>
<forever if><(  <timer>  <>>  5  )>
     <change{ health }by( -1 )>
     <reset timer>
<end>


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#5 2011-11-13 16:27:46

manoz
New Scratcher
Registered: 2011-11-13
Posts: 13

Re: Help

what is the 'timer' thing??

Offline

 

#6 2011-11-13 16:31:24

manoz
New Scratcher
Registered: 2011-11-13
Posts: 13

Re: Help

i want to do: If sprite(the target) not clicked, change lives by -1. or something along those lines so it has a similar outcome.

Offline

 

#7 2011-11-13 16:55:54

manoz
New Scratcher
Registered: 2011-11-13
Posts: 13

Re: Help

Ok ignore those last 2 comments just tried it, works brilliantly thanks!!!

Offline

 

#8 2011-11-13 17:01:02

manoz
New Scratcher
Registered: 2011-11-13
Posts: 13

Re: Help

Its good but i only want it to decrease a life if the sprite is on 'show' and not 'hide'

Offline

 

#9 2011-11-13 17:40:44

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: Help

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)


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#10 2011-11-13 18:10:40

manoz
New Scratcher
Registered: 2011-11-13
Posts: 13

Re: Help

and i have put the timings for the sprite to 'show' as 'pick random between... and...'

Offline

 

#11 2011-11-13 18:14:09

manoz
New Scratcher
Registered: 2011-11-13
Posts: 13

Re: Help

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?

Offline

 

#12 2011-11-13 18:35:25

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: Help

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

Code:

[show]
[change variable (hidden) to (false) ]

[hide]
[change variable (hidden) to (true) ]

http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#13 2011-11-13 18:37:30

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: Help

Here's the code for multiple sprites:


Code:

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)


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#14 2011-11-17 15:03:19

manoz
New Scratcher
Registered: 2011-11-13
Posts: 13

Re: Help

I still dont get the hide show variable thing so could u use the blocks to show me this and could u explain the code for multiple sprites as i dont understand it and what is the "private variable" meant to be??

Offline

 

#15 2011-11-17 15:06:39

RedRocker227
Scratcher
Registered: 2011-10-26
Posts: 1000+

Re: Help

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


Why

Offline

 

#16 2011-11-20 12:05:58

manoz
New Scratcher
Registered: 2011-11-13
Posts: 13

Re: Help

i Know what it is but i dont know what it is meant to be substituted for  and could you explain the other bits of coding aswell???

Offline

 

#17 2011-11-20 14:21:54

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: Help

My previous script may have been incorrect, sorry.  Here's a revised script with comments

Code:

[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.


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

Board footer