Discuss Scratch

jkris11
New to Scratch
1 post

If(touching) not working

So I have to make a simple game for my summer homework, basically I'm making a game where you as a bat have to catch blue dots to gain score, but the problem is that this does not work, here's a screenshot
http://imageshack.com/scaled/large/809/is19.png
drmcw
Scratcher
1000+ posts

If(touching) not working

The script needs to be inside a forever loop with a when green flag clicked to start it or you could try putting it inside your existing forever loop.

10 !
ScratchVaders or Galaga?
Maybe Eliza can help you decide?
clubpenguin552222
Scratcher
100+ posts

If(touching) not working

You need a forever loop:
forever // This is in the control tab
if < touching color [#0000FF] >
change [Score v] by (1)
end
end
Also you don't need an
stop script
on the final of the
when [arrow v] key pressed
change y by (1)
or
change x by (1)

Last edited by clubpenguin552222 (Aug. 31, 2013 17:01:46)


<Scratch block share> <- Click on that
Projects i really love: CAA14's Engine center
ats-ll
Scratcher
75 posts

If(touching) not working

fix:
when gf clicked
forever
forever
if <touching [Spirte2 v]?>

i am got in! Maki-Tak!
DotDash
Scratcher
1000+ posts

If(touching) not working

ats-ll wrote:

fix:
when gf clicked
forever
forever
if <touching [Spirte2 v]?>
That would just slow it down.

My browser / operating system: MacOS Macintosh X 10.8.5, Chrome 29.0.1547.76, Flash 11.8 (release 800)
davidkt
Scratcher
1000+ posts

If(touching) not working

Try this:
when gf clicked
forever
if <touching [Dot v]>
change [Score v] by (1)

Remember when I looked like this? I still do.


Float, my Scratch 2.0 mod | My (somewhat under-construction) blog
ats-ll
Scratcher
75 posts

If(touching) not working

DotDash wrote:

ats-ll wrote:

fix:
when gf clicked
forever
forever
if <touching [Spirte2 v]?>
That would just slow it down.
beacuse
when gf clicked
forever
if <touching color [#58A571]> then
turn right (15) degrees
end

Last edited by ats-ll (Sept. 1, 2013 23:33:02)


i am got in! Maki-Tak!
ohelab
New to Scratch
2 posts

If(touching) not working

i aslo had a touble with a game i made i made it so that if my cat touchs red then it shrinks
if <> then
say [MEOW] for (2) secs
set size to (10) %
end
ohelab
New to Scratch
2 posts

If(touching) not working

sorry
if <touching color [#f0f]?> then

set size to (10) %

end

end

Last edited by ohelab (Jan. 23, 2014 04:30:15)

miku2020
Scratcher
1 post

If(touching) not working

Hey you need to add wait something like 0.0001 so it can register that it touches
mickylee
New to Scratch
3 posts

If(touching) not working

I had a similar problem with a project. It worked on one of the sprites, but not the other. When I put the forever block around it, as suggested above, it worked just fine on the second one. Can anyone explain why this is needed?
daffy1234
Scratcher
100+ posts

If(touching) not working

There's two issues here.
1) the code is never being ran. Every block of code needs a "when " block right above it. In this case, you'll probably want this one
when green flag clicked
Otherwise, the code will never run unless you run it directly by clicking it.
2) Once it is ran, it stops. It needs to be in a loop
when green flag clicked
if (touching [... v] ?) then // this check is done once, then the script stops.
code
end

when green flag clicked
forever
if (touching [... v] ?) then // this check is done constantly, and runs the code whenever it's true
code
end
end

And this works, however, I have a little bit of advice to make the code run better. Doing it this way will have the code constantly checking, over and over and over, and if you ever decide to make a big game with a lot of scripts, these add up. I suggest trying this.

when green flag clicked
forever
wait until <touching [... v] ?>
code
wait until <not <touching [... v] ?>>
end

What this does is it waits patiently until it's touching the other sprite, then it runs the code, then it waits patiently until it's no longer touching the sprite. After that, the process repeats. In your case, where you're counting up a score, this is probably what you want.

Powered by DjangoBB

Standard | Mobile