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

#1 2013-02-21 18:03:02

oliviergo
New Scratcher
Registered: 2013-02-21
Posts: 2

global variable seems to be local

Hi guys,

This is my first Scratch project. It's a great game, I'll definitively show it my kids ! I have a simple question, yet I cannot find a working answer in the forum.

I want the click on sprite1 to trigger an action on sprite2, such as showing sprite2 for one second then hide it again. Something seems to be wrong but I havent been able to find what for the last 2 hours. Could you guys help me to figure out what's wrong with my scripts ?

this is the script for sprite1 :

when Sprite1 clicked
   set (Click) to [1]
   wait [1] secs
   set (Click) to [0]

for script2 :

if <(Click) = [1]>
   show
end
else
   hide
end
Thanks for your help,

Olivier

Offline

 

#2 2013-02-21 20:49:56

dusty22
Scratcher
Registered: 2012-09-28
Posts: 49

Re: global variable seems to be local

For script 2, you need to enclose it in a forever loop. That makes it keep checking forever as long as the script is active.

Offline

 

#3 2013-02-22 03:22:31

oliviergo
New Scratcher
Registered: 2013-02-21
Posts: 2

Re: global variable seems to be local

Thanks !

Offline

 

#4 2013-02-22 08:52:34

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

Re: global variable seems to be local

oliviergo wrote:

Hi guys,

This is my first Scratch project. It's a great game, I'll definitively show it my kids ! I have a simple question, yet I cannot find a working answer in the forum.

I want the click on sprite1 to trigger an action on sprite2, such as showing sprite2 for one second then hide it again. Something seems to be wrong but I havent been able to find what for the last 2 hours. Could you guys help me to figure out what's wrong with my scripts ?

this is the script for sprite1 :

when [Sprite1 v] clicked//Yes, nod ropdown menu should be here, but it's for the blockmrendering purposes.
   set [Click v] to [1]
   wait [1] secs
   set [Click v] to [0]

for script2 :

if <(Click) = [1]>
   show
else
   hide
end
Thanks for your help,

Olivier

I fixed your scratchblocks.

Anyway, to add on, hello oliviergo and welcome to Scratch! I hope that you'll find your way around Scratch easily enough!  smile

With regards,

ErnieParke

Last edited by ErnieParke (2013-02-22 09:10:54)


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

Offline

 

#5 2013-02-22 09:31:07

dusty22
Scratcher
Registered: 2012-09-28
Posts: 49

Re: global variable seems to be local

Just so you know, scripts only execute once the first time they're cued unless you enclose them in something to keep looping or repeating, like a "Repeat Until" or "Forever" block.

Offline

 

#6 2013-02-22 13:38:37

lalala3
Scratcher
Registered: 2008-10-03
Posts: 100+

Re: global variable seems to be local

Translation: Very few non-programmers realize that "if" is not synonymous to "when". Which just goes to show how illogical the human race is.

Also, if you haven't noticed, there's an indent at the top of the "if" block. This should have indicated to you that it goes in the middle of a script and doesn't activate itself; it's activated by the block above it.

Last edited by lalala3 (2013-02-22 13:38:52)


http://img515.imageshack.us/img515/9374/signature2nt.png

Offline

 

#7 2013-02-22 13:47:15

FeatherWind
Scratcher
Registered: 2012-10-24
Posts: 100+

Re: global variable seems to be local

How about doing

When sprite1 clicked
Broadcast: showthenhide

For sprite 2:

When I receive: Showthenhide
show
wait 1 secs
hide.

Hope that helps!  smile


http://stream1.gifsoup.com/view/37620/shugo-chara-amu-o.gif [url=http://gifsoup.com/view/37620/shugo-chara-amu.html]

Offline

 

#8 2013-02-22 13:54:24

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

Re: global variable seems to be local

FeatherWind wrote:

How about doing

When [sprite1 v] clicked
Broadcast [showthenhide v]

For sprite 2:

When I receive [Showthenhide v]
show
wait (1) secs
hide

Hope that helps!  smile

Turned into scratchblocks.

Last edited by ErnieParke (2013-02-22 13:54:49)


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

Offline

 

#9 2013-02-22 20:29:18

ImagineIt
Scratcher
Registered: 2011-02-28
Posts: 1000+

Re: global variable seems to be local

lalala3 wrote:

Translation: Very few non-programmers realize that "if" is not synonymous to "when". Which just goes to show how illogical the human race is.
That's very rude... Not everyone can figure that out.
Also, if you haven't noticed, there's an indent at the top of the "if" block. This should have indicated to you that it goes in the middle of a script and doesn't activate itself; it's activated by the block above it.
This is their first game. They probably don't know much about scratch...

Offline

 

#10 2013-02-22 20:41:38

uglysquidward
Scratcher
Registered: 2012-09-30
Posts: 100+

Re: global variable seems to be local

lalala3 wrote:

Translation: Very few non-programmers realize that "if" is not synonymous to "when". Which just goes to show how illogical the human race is.

Also, if you haven't noticed, there's an indent at the top of the "if" block. This should have indicated to you that it goes in the middle of a script and doesn't activate itself; it's activated by the block above it.

He is from france. He probaby isnt the best at english.


Moved back to qwerts9000

Offline

 

#11 2013-02-23 10:40:58

zammer990
Scratcher
Registered: 2012-01-22
Posts: 500+

Re: global variable seems to be local

ImagineIt wrote:

lalala3 wrote:

Translation: Very few non-programmers realize that "if" is not synonymous to "when". Which just goes to show how illogical the human race is.
That's very rude... Not everyone can figure that out.
Also, if you haven't noticed, there's an indent at the top of the "if" block. This should have indicated to you that it goes in the middle of a script and doesn't activate itself; it's activated by the block above it.
This is their first game. They probably don't know much about scratch...

I hardly think he was trying to offend, the human race and English in particular is a very jumbled up language, so the first statement was entirely true, secondly, he was elaborating, not saying "everyone knows this you're stupid for not", even if it was somewhat offensively phrased.


http://i45.tinypic.com/2ynq7nn.jpg Play now!

Offline

 

#12 2013-02-23 10:44:13

estile
Scratcher
Registered: 2013-01-26
Posts: 100+

Re: global variable seems to be local

yes, but isnt this a little off topic


http://i45.tinypic.com/s4nvxl.png

Offline

 

Board footer