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

#1 2012-12-01 15:14:05

jamroller
New Scratcher
Registered: 2012-11-17
Posts: 3

If Not Clicked?

Have created a first person shooter game in which sprites appear, glide across the screen, and hide if not clicked.

Each time it is clicked, a sprite will appear again randomly until the shooter misses it on an appearance.

If it is not clicked, it will not appear again.

The game will end when no more sprites appear... and that is the catch. I don't know how to alert the program that the sprite was NOT clicked. There is no "When Not Clicked" block.

As such, now the game simply goes on with nothing left to shoot at. I've considered a number of options, but all seem stymied by the inability to indicate that something didn't happen (sprite clicked).

Thoughts?

Thanks in advance...

Offline

 

#2 2012-12-01 16:02:13

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: If Not Clicked?

One method you could use is using a variable. Once a sprite gets shot, it'll set the variable to 1, and once it reappears, it'll reset the variable to 0. When you do this, just make sure that each shootable object gets their own variable. And if you want, you could create a twist off of this to give objects health so that they survive more than 1 shot, or you could use a list instead of several variables.

I hope that this helps, and welcome to the Scratch forums!


http://i46.tinypic.com/35ismmc.png

Offline

 

#3 2012-12-01 16:38:35

jamroller
New Scratcher
Registered: 2012-11-17
Posts: 3

Re: If Not Clicked?

ErnieParke wrote:

One method you could use is using a variable. Once a sprite gets shot, it'll set the variable to 1, and once it reappears, it'll reset the variable to 0. When you do this, just make sure that each shootable object gets their own variable. And if you want, you could create a twist off of this to give objects health so that they survive more than 1 shot, or you could use a list instead of several variables.

I hope that this helps, and welcome to the Scratch forums!

I thought about that, but then what? 

The sprite appears in its first iteration. Variable Sprite1Alive = 0

From there, there are two options:

1) Sprite is not shot and disappears. Then variable still = 0

2) Sprite is shot and disappears. Variable set to 1. Sprite reappears and sets variable to 0. Repeat until sprite is not shot.

So, what do you do next? That is where I am stuck...

If variable = 0 what?  And what do you do when there are 4 or 5 other sprites?

If Sprite1Alive = 0 and Sprite2Alive = 0, etc, then Game Over?

Offline

 

#4 2012-12-01 16:58:58

TorbyFork234
Scratcher
Registered: 2012-03-01
Posts: 1000+

Re: If Not Clicked?

jamroller wrote:

ErnieParke wrote:

One method you could use is using a variable. Once a sprite gets shot, it'll set the variable to 1, and once it reappears, it'll reset the variable to 0. When you do this, just make sure that each shootable object gets their own variable. And if you want, you could create a twist off of this to give objects health so that they survive more than 1 shot, or you could use a list instead of several variables.

I hope that this helps, and welcome to the Scratch forums!

I thought about that, but then what? 

The sprite appears in its first iteration. Variable Sprite1Alive = 0

From there, there are two options:

1) Sprite is not shot and disappears. Then variable still = 0

2) Sprite is shot and disappears. Variable set to 1. Sprite reappears and sets variable to 0. Repeat until sprite is not shot.

So, what do you do next? That is where I am stuck...

If variable = 0 what?  And what do you do when there are 4 or 5 other sprites?

If Sprite1Alive = 0 and Sprite2Alive = 0, etc, then Game Over?

It doesn't need to be between 1 & 0.
you could have it kind of like this.

when gf clicked
set [time v] to [0]
forever
set [time v] to (timer)
wait (0.2) secs


when gf clicked
set [checking v] to [0]
set [variable v] to [1]
forever
reset timer
repeat until <<(time) > (time you want it to show up for per iteration)> or <(checking)=[1]>>
if <(variable)=[1]>
show and move scripts
if (shot?) //whatever scripts you have for shot
set [variable v] to [0]
hide
set [checking v] to [1]
end
end
if <(variable)=[0]>
set [variable v] to [1] //have it show up again
set [checking v] to [0]
else
set [variable v] to [2] //to have it not show up again
set [checking v] to [1] //just incase setting variable to 2 doesn't work
end
I'm almost completely sure this will work, if not, please post what's wrong.

Offline

 

#5 2012-12-02 09:24:14

jamroller
New Scratcher
Registered: 2012-11-17
Posts: 3

Re: If Not Clicked?

Thanks. I'll give it a shot later today to see.

Offline

 

Board footer