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

#1 2009-12-11 18:58:15

webgal15
Scratcher
Registered: 2009-06-17
Posts: 1000+

My scripts aren't working?

First, I am not sure if this belongs here or in Troubleshooting. Please forgive me (and move this topic if you are a mod) if if does.

Second, if this has already been posted, I'm sorry- I didn't feel like looking through 122 pages of search results.

Third, the thing this topic is about, my scripts aren't working. If it helps, these are the scripts in question:

<when green flag clicked>
<if> <color[ gray ]is over[ red
<broadcast[ FINISH
<hide>
<end>
<if> <color[ gray ]is over[ green
<stop all>
<end>

They aren't working, as you know.


Now only using this account to post in Miscellaneous, but when Miss_Webgal becomes a Scratcher I'm ditching this account.

Offline

 

#2 2009-12-11 19:08:31

hmnwilson
Scratcher
Registered: 2007-07-04
Posts: 1000+

Re: My scripts aren't working?

That script shouldn't be causing problems.

A common mistake with the <color _ is touching _> script is that the <color _> part has to be part of the sprite that has the script, and the <is touching _> part has to be on the other sprite/background. That's the only reason I can think of that it wouldn't be working.

Last edited by hmnwilson (2009-12-11 19:09:20)


I'm taking a break from Scratch until 2.0 comes out. Any messages sent between then and now probably won't be read - sorry.
(Oct. 20, 2011)

Offline

 

#3 2009-12-11 19:14:16

webgal15
Scratcher
Registered: 2009-06-17
Posts: 1000+

Re: My scripts aren't working?

One of the colors WAS wrong, so I fixed that and I still have the problem.

Well, I do have another part of the script that is working. I didn't post it up there because it had nothing to do with my problem. This was the part that I left out:

<show>
<point in direction( 90
<go to x sad  -199 )y sad  -107


Now only using this account to post in Miscellaneous, but when Miss_Webgal becomes a Scratcher I'm ditching this account.

Offline

 

#4 2009-12-12 10:13:11

Larry828
Scratcher
Registered: 2007-05-30
Posts: 100+

Re: My scripts aren't working?

And the only thing I can imagine has to do with the time the colors are touching.

The script literally says "as long as (gray) is touching (red)" wait, and then do something.
And later says, "as long as (gray) is touching (green)" wait, and then do something.

This has the potential to cause problems if the colors keep on touching for a longer period of time than you expected.  (Or if one lands on the other and *never* quits touching!  Then nothing is going to happen!)

I wrote a tutorial called "Two Scores" to illustrate the problem. http://scratch.mit.edu/projects/Larry828/633783.  It shows how one way of writing the script results in scores in the hundreds (because the sprites are touching for a couple of seconds); the other way results in a score of "1" when they've touched.  The scripts are included right in the project itself so it doesn't have to be downloaded.

If you check out the project, you could leave a comment there or you could leave another posting here.

Offline

 

#5 2009-12-12 10:19:55

BWOG
Scratcher
Registered: 2008-09-19
Posts: 1000+

Re: My scripts aren't working?

I think you're missing a forever loop.

Offline

 

#6 2009-12-12 10:54:50

Larry828
Scratcher
Registered: 2007-05-30
Posts: 100+

Re: My scripts aren't working?

BWOG wrote:

I think you're missing a forever loop.

I agree.  I just built a quick [(color) touching (color)] project and the only way I could make it work was to have two "parallel" scripts that began when the Green Flag was clicked. 

The first script made a red sprite move across the screen and then stop.  It repeated the movement 5 times.  And each time it crossed a green stripe on the Stage.)

The second script had the *forever* loop and said,
FOREVER
IF red touches green
WAIT UNTIL [NOT red touches green]
Change score by 1

And that worked.  One script does the moving, the other sets the result....forever.

I hope we're making progress!  :-)

Offline

 

#7 2009-12-12 11:06:23

Larry828
Scratcher
Registered: 2007-05-30
Posts: 100+

Re: My scripts aren't working?

And can I make another reply?

Your first script seems to read this way:
When the Green Flag is clicked
Then IF AT THAT VERY MOMENT gray is over red, then broadcast Finish and Hide.
And IF AT THAT VERY MOMENT gray is over green, then Stop Everything.

So, when you click the Green Flag if your colors are touching then the project ends almost instantly.

And IF AT THAT FIRST MOMENT they *aren't* touching.....then whatever happens after that doesn't make any difference because your script isn't checking any longer.

That's why BWOG pointed out that you need a FOREVER loop in there: so that your script will keep checking to see if the colors are touching.

(I keep working on this topic because the very same thing puzzled me for a long time until it was finally answered in the Forum.  I'll try to look up the posting, but I think credit is also given in my project "Two Scores".)  It was The-Whiz who helped me, but The-Whiz has 71 pages of Forum posts so that's too many to search!!  :-)

Last edited by Larry828 (2009-12-12 11:09:31)

Offline

 

Board footer