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

#1 2012-11-18 09:51:51

arvidabystrom
New Scratcher
Registered: 2012-11-18
Posts: 9

as a button

ok i want one of my sprites to work as a button.
so lets say that sprite 1 says hello when mous-pointer touches it but then i want to change sprite 1 reaction to the mouse-pointer if sprite 2 have been pressed.
how do one do that?

thank you,
A.

Offline

 

#2 2012-11-18 10:01:07

Gravitation
New Scratcher
Registered: 2012-09-26
Posts: 500+

Re: as a button

It's easy; use a variable.

Create a variable named "setting". Put this script in your button:

when gf clicked
set [setting v] to [1]

when [Sprite2] clicked
change [setting v] by (1)
set [setting v] to (((setting) mod (2)) + (1)) // Change the 2 to your amount of possibilities.
Put this in Sprite1:

when [Sprite1] clicked
if <(setting) = [1]>
 say [hello]
end
if <(setting) = [2]> //Do this for all possibilities
 say [bye]
end
smile

Offline

 

#3 2012-11-18 10:04:09

soniku3
Scratcher
Registered: 2011-12-08
Posts: 1000+

Re: as a button

I don't understand it.


internet's all about cats today.

Offline

 

#4 2012-11-18 10:22:12

arvidabystrom
New Scratcher
Registered: 2012-11-18
Posts: 9

Re: as a button

Gravitation wrote:

It's easy; use a variable.

Create a variable named "setting". Put this script in your button:

when gf clicked
set [setting v] to [1]

when [Sprite2] clicked
change [setting v] by (1)
set [setting v] to (((setting) mod (2)) + (1)) // Change the 2 to your amount of possibilities.
Put this in Sprite1:

when [Sprite1] clicked
if <(setting) = [1]>
 say [hello]
end
if <(setting) = [2]> //Do this for all possibilities
 say [bye]
end
smile

i don't seem to have "when sprite2 clicked" were i can change the sprite. that control simply seem to want to use only the spirit which script i'm on, if that makes sense?
thank you anyways i do understand it all a little bit more, haha

Offline

 

#5 2012-11-18 10:49:22

Paddle2See
Scratch Team
Registered: 2007-10-27
Posts: 1000+

Re: as a button

arvidabystrom wrote:

Gravitation wrote:

It's easy; use a variable.

Create a variable named "setting". Put this script in your button:

when gf clicked
set [setting v] to [1]

when [Sprite2] clicked
change [setting v] by (1)
set [setting v] to (((setting) mod (2)) + (1)) // Change the 2 to your amount of possibilities.
Put this in Sprite1:

when [Sprite1] clicked
if <(setting) = [1]>
 say [hello]
end
if <(setting) = [2]> //Do this for all possibilities
 say [bye]
end
smile

i don't seem to have "when sprite2 clicked" were i can change the sprite. that control simply seem to want to use only the spirit which script i'm on, if that makes sense?
thank you anyways i do understand it all a little bit more, haha

Right, the top two scripts that Gravitation gave you there would be found under a sprite called "sprite 2" - but it would be setting a variable that could be seen by all sprites, so sprite 1 scripts can make use of the results.


http://i39.tinypic.com/2nav6o7.gif

Offline

 

#6 2012-11-18 12:27:46

arvidabystrom
New Scratcher
Registered: 2012-11-18
Posts: 9

Re: as a button

Paddle2See wrote:

arvidabystrom wrote:

Gravitation wrote:

It's easy; use a variable.

Create a variable named "setting". Put this script in your button:

when gf clicked
set [setting v] to [1]

when [Sprite2] clicked
change [setting v] by (1)
set [setting v] to (((setting) mod (2)) + (1)) // Change the 2 to your amount of possibilities.
Put this in Sprite1:

when [Sprite1] clicked
if <(setting) = [1]>
 say [hello]
end
if <(setting) = [2]> //Do this for all possibilities
 say [bye]
end
smile

i don't seem to have "when sprite2 clicked" were i can change the sprite. that control simply seem to want to use only the spirit which script i'm on, if that makes sense?
thank you anyways i do understand it all a little bit more, haha

Right, the top two scripts that Gravitation gave you there would be found under a sprite called "sprite 2" - but it would be setting a variable that could be seen by all sprites, so sprite 1 scripts can make use of the results.

ok cool!
sorry for basically try to make people lead me through exactly step by step.
but the case now is that i made the sprite2 a button cuz it responds by changing the setting from 1 to 2. but when doing that i want sprite1's sound to change and that wont happen by some reason.

in sprite1 i have:

when space key pressed
if settings=1
   forever if touching mouse-pointer
   play sound (sound1)
if settings=2
   forever if touching mouse-pointer
   play sound (sound2)


and in sprite2:
when space key pressed
forever settings to 1

when sprite2 clicked
play sound (sound3)
forever
   change settings by 2
   set settings to settings mod 2 + 1

Offline

 

#7 2012-11-18 14:18:16

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

Re: as a button

arvidabystrom wrote:

Paddle2See wrote:

arvidabystrom wrote:

i don't seem to have "when sprite2 clicked" were i can change the sprite. that control simply seem to want to use only the spirit which script i'm on, if that makes sense?
thank you anyways i do understand it all a little bit more, haha

Right, the top two scripts that Gravitation gave you there would be found under a sprite called "sprite 2" - but it would be setting a variable that could be seen by all sprites, so sprite 1 scripts can make use of the results.

ok cool!
sorry for basically try to make people lead me through exactly step by step.
but the case now is that i made the sprite2 a button cuz it responds by changing the setting from 1 to 2. but when doing that i want sprite1's sound to change and that wont happen by some reason.

in sprite1 i have:

when key [space v] pressed
if <(settings)=(1)>
   forever if (touching [mouse-pointer v]?)
   play sound [sound1 v]
end
end
if <(settings)=(2)>
   forever if (touching [mouse-pointer v]?)
   play sound [sound2 v]
end
and in sprite2:
when [space v] key pressed
forever 
set [settings v] to (1)

when [sprite2 v] clicked
play sound [sound3 v]
forever
   change [settings v] by (2)
   set [settings v] to ((settings) mod ((2) + (1)))

First of all, you have a forever block surrounding the [set settings to (1)] block in your second script, which is going to constantly set it to 1 once you press space. Try removing that. Also, you might want to change the [when space pressed] to [when gf clicked].

Moving on, your first script is going to always play sound1 the way you built it. To fix that, try replacing the forever if's with regular if's. Then, you might want to add this to the end of the script:

wait until <not (key [space v] pressed?)>
I hope that this helps!


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

Offline

 

#8 2012-11-18 14:42:45

arvidabystrom
New Scratcher
Registered: 2012-11-18
Posts: 9

Re: as a button

ErnieParke wrote:

arvidabystrom wrote:

Paddle2See wrote:


Right, the top two scripts that Gravitation gave you there would be found under a sprite called "sprite 2" - but it would be setting a variable that could be seen by all sprites, so sprite 1 scripts can make use of the results.

ok cool!
sorry for basically try to make people lead me through exactly step by step.
but the case now is that i made the sprite2 a button cuz it responds by changing the setting from 1 to 2. but when doing that i want sprite1's sound to change and that wont happen by some reason.

in sprite1 i have:

when key [space v] pressed
if <(settings)=(1)>
   forever if (touching [mouse-pointer v]?)
   play sound [sound1 v]
end
end
if <(settings)=(2)>
   forever if (touching [mouse-pointer v]?)
   play sound [sound2 v]
end
and in sprite2:
when [space v] key pressed
forever 
set [settings v] to (1)

when [sprite2 v] clicked
play sound [sound3 v]
forever
   change [settings v] by (2)
   set [settings v] to ((settings) mod ((2) + (1)))

First of all, you have a forever block surrounding the [set settings to (1)] block in your second script, which is going to constantly set it to 1 once you press space. Try removing that. Also, you might want to change the [when space pressed] to [when gf clicked].

Moving on, your first script is going to always play sound1 the way you built it. To fix that, try replacing the forever if's with regular if's. Then, you might want to add this to the end of the script:

wait until <not (key [space v] pressed?)>
I hope that this helps!

but when i don't have the forever if's when pressing the green flag and then putting my mouse-pointer over whatever was suppose to sound it simply doesn't sound? since one only have one mouse-pointer one can simply not press the green flag constantly and take the mouse-pointer and hold it over the object at the same time, so i don't really get why it works like that. geh

Offline

 

#9 2012-11-19 09:40:21

awesomeness321
Scratcher
Registered: 2012-08-10
Posts: 100+

Re: as a button

arvidabystrom wrote:

ErnieParke wrote:

arvidabystrom wrote:

ok cool!
sorry for basically try to make people lead me through exactly step by step.
but the case now is that i made the sprite2 a button cuz it responds by changing the setting from 1 to 2. but when doing that i want sprite1's sound to change and that wont happen by some reason.

in sprite1 i have:

when key [space v] pressed
if <(settings)=(1)>
   if (touching [mouse-pointer v]?)
   play sound [sound1 v]
end
end
if <(settings)=(2)>
   if (touching [mouse-pointer v]?)
   play sound [sound2 v]
end
end
wait until <not <key [space v] pressed?>>
and in sprite2:
when gf clicked

set [settings v] to (1)

when [sprite2 v] clicked
play sound [sound3 v]
   change [settings v] by (2)
   set [settings v] to (((settings) mod (2)) + (1))

First of all, you have a forever block surrounding the [set settings to (1)] block in your second script, which is going to constantly set it to 1 once you press space. Try removing that. Also, you might want to change the [when space pressed] to [when gf clicked].

Moving on, your first script is going to always play sound1 the way you built it. To fix that, try replacing the forever if's with regular if's. Then, you might want to add this to the end of the script:

wait until <not (key [space v] pressed?)>
I hope that this helps!

but when i don't have the forever if's when pressing the green flag and then putting my mouse-pointer over whatever was suppose to sound it simply doesn't sound? since one only have one mouse-pointer one can simply not press the green flag constantly and take the mouse-pointer and hold it over the object at the same time, so i don't really get why it works like that. geh

He meant he wanted to replace the second 'when space key pressed' to 'when green flag clicked'.

Oh, and I just edited your scripts so it will work.


My newest project:http://blocks.scratchr.org/API.php?user=awesomeness321&amp;action=projects&amp;type=newest&amp;return=image&amp;num=1Color:#30F9A5 I am currently http://blocks.scratchr.org/API.php?user=awesomeness321&amp;action=onlineStatus&amp;type=text

Offline

 

#10 2012-11-19 13:38:12

arvidabystrom
New Scratcher
Registered: 2012-11-18
Posts: 9

Re: as a button

well i want sprite1 to start sound1 right away so that i either with the green flag or with the space key. so not only start it when pressed space.
and when i did it like you said the sound2 never goes off and sound1 is always sounding when mouse-pointer is over sprite1

Offline

 

Board footer