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

#1 2012-01-13 18:50:09

howitsdone
New Scratcher
Registered: 2012-01-11
Posts: 7

Multiple "if <touching sprite #>" blocks not working as planned, help?

So, I'm working on a language project. One of the activities requires the user to click the correct fruit sprites from a list, which will then move to the basket sprite. Once all the fruit sprites are touching the basket sprite, it's supposed to broadcast a message which will trigger the fruit sprites and basket to disappear and change the background. This is my script for one of the "correct" fruit sprites (the ones that are supposed to be clicked) :

[blocks]<when[  Sprite30  ]clicked>
<switch to costume[  costume5  ]>
<wait(0.25)secsc>
<switch to costume[  costume6  ]>
<go to[  Sprite27  ]>[/blocks]

That script works. All 4 of the correct sprites are programmed like this, so they all go to the basket sprite (Sprite27). (The costume blocks are just for "prettiness" in the final result.) Here is the coding that doesn't work for Sprite27:

[blocks]<if><touching[  Sprite30  ]>
<if><touching[  Sprite33  ]>
<if><touching[  Sprite34  ]>
<if><touching[  Sprite35  ]>
<broadcast[ firstcorrect ]>[/blocks]

I have it programmed so the stage background changes and the sprites disappear, but when I click the fruits it won't work. Am I missing a block?

Offline

 

#2 2012-01-13 19:48:46

AtomicBawm3
Scratcher
Registered: 2009-06-27
Posts: 1000+

Re: Multiple "if <touching sprite #>" blocks not working as planned, help?

If the sprites are hidden, they're not being touched, no matter where they are...it sounds like this might be your problem, but I can't be sure.


http://i50.tinypic.com/j0yw0p.jpg

Offline

 

#3 2012-01-13 19:54:00

howitsdone
New Scratcher
Registered: 2012-01-11
Posts: 7

Re: Multiple "if <touching sprite #>" blocks not working as planned, help?

No, that's not it. They don't hide until they're touching. Thanks anyways.

Offline

 

#4 2012-01-13 20:41:18

SJRCS_011
Scratcher
Registered: 2011-02-07
Posts: 1000+

Re: Multiple "if <touching sprite #>" blocks not working as planned, help?

Use
[blocks] <wait until> << << << <touching[  Sprite30  ]>  <and> <touching[  Sprite33  ]>  >> <and> <touching[  Sprite34  ]>  >> <and> <touching[  Sprite35  ]>  >> [/blocks]
Or, in simpler terms,
Wait until touching sprite 30 AND touching sprite 33 AND touching sprite 34 AND touching sprite 35.

Reason: once you start the project, the if statements would have been evaluated.  therefore, there is only once chance at beating it, and that is in less than a second after the script is triggered unless single-stepping is on.

Last edited by SJRCS_011 (2012-01-13 20:44:40)


http://i.imgur.com/vQqtH.png
Learning to Program in a Nutshell:  "You're missing a closing parentheses" - LS97

Offline

 

#5 2012-01-13 21:49:31

howitsdone
New Scratcher
Registered: 2012-01-11
Posts: 7

Re: Multiple "if <touching sprite #>" blocks not working as planned, help?

SJRCS_011, thanks but I'm afraid that it still doesn't work. I think I need to add  a block like <when green flag clicked> to correct it, but I really don't want to do that  tongue

Offline

 

#6 2012-01-14 10:27:10

SJRCS_011
Scratcher
Registered: 2011-02-07
Posts: 1000+

Re: Multiple "if <touching sprite #>" blocks not working as planned, help?

That's what I was inferring.  Have it under the green flag hat block, and it'll work.
Or at least should work.


http://i.imgur.com/vQqtH.png
Learning to Program in a Nutshell:  "You're missing a closing parentheses" - LS97

Offline

 

#7 2012-01-14 11:01:01

joefarebrother
Scratcher
Registered: 2011-04-08
Posts: 1000+

Re: Multiple "if <touching sprite #>" blocks not working as planned, help?

it will be easier if you name the sprites descriptively like "fruit20" or "basket"


My latest project is called http://tinyurl.com/d2m8hne! It has http://tinyurl.com/d395ygk views, http://tinyurl.com/cnasmt7 love-its, and http://tinyurl.com/bwjy8xs comments.
http://tinyurl.com/756anbk   http://tinyurl.com/iplaychess

Offline

 

#8 2012-01-14 18:19:51

howitsdone
New Scratcher
Registered: 2012-01-11
Posts: 7

Re: Multiple "if <touching sprite #>" blocks not working as planned, help?

joefarebrother wrote:

it will be easier if you name the sprites descriptively like "fruit20" or "basket"

...How does that matter?

Offline

 

Board footer