Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Clicking: Once, do one thing, another time, do something else
- Rlucy
-
58 posts
Clicking: Once, do one thing, another time, do something else
I am making a sandbox game with a hotbar that opens when you click the green line, and then when it is clicked again, it closes. But that doesn't work. I want to make it work, but I can't. Please help!!!
Last edited by Rlucy (May 31, 2015 14:26:52)
- deck26
-
1000+ posts
Clicking: Once, do one thing, another time, do something else
Have a variable that keeps track of the state (0 and 1 makes it easy to toggle between the values)
- Rlucy
-
58 posts
Clicking: Once, do one thing, another time, do something else
Wait… It doesn't work. The State=0 won't fit into the if then block. Have a variable that keeps track of the state (0 and 1 makes it easy to toggle between the values)
- Sigton
-
1000+ posts
Clicking: Once, do one thing, another time, do something else
Can you please explain what you mean by “it wont fit”?Wait… It doesn't work. The State=0 won't fit into the if then block. Have a variable that keeps track of the state (0 and 1 makes it easy to toggle between the values)
Sigton
- -Scratcher-
-
100+ posts
Clicking: Once, do one thing, another time, do something else
It will, it's just not the correct shape. You will find it inside the operators tab and rather looks like < ▒ = ▒ > Wait… It doesn't work. The State=0 won't fit into the if then block.

Last edited by -Scratcher- (June 3, 2015 20:11:26)
- languagegal14
-
500+ posts
Clicking: Once, do one thing, another time, do something else
To make it easier on you, she is talking about this one:It will, it's just not the correct shape. You will find it inside the operators tab and rather looks like < ▒ = ▒ > Wait… It doesn't work. The State=0 won't fit into the if then block.
Except that one is always a diamond thing when you use it, no the oval… oh well.
- -Scratcher-
-
100+ posts
Clicking: Once, do one thing, another time, do something else
She?To make it easier on you, she is talking about this one:It will, it's just not the correct shape. You will find it inside the operators tab and rather looks like < ▒ = ▒ > Wait… It doesn't work. The State=0 won't fit into the if then block.Except that one is always a diamond thing when you use it, no the oval… oh well.
That's the reason why I didn't use the scratchblocks feature, to show how it actually looks like..
- Rlucy
-
58 posts
Clicking: Once, do one thing, another time, do something else
What I mean is that it won't let me insert that specific block into the if then block.Can you please explain what you mean by “it wont fit”?Wait… It doesn't work. The State=0 won't fit into the if then block. Have a variable that keeps track of the state (0 and 1 makes it easy to toggle between the values)
Sigton
- Rlucy
-
58 posts
Clicking: Once, do one thing, another time, do something else
Oh!!! Wow! I must be blind… I did not see the < ▒ = ▒ > block in the operators…. Thanks all who helped! 

- Rlucy
-
58 posts
Clicking: Once, do one thing, another time, do something else
Sorry if it sounds like I'm complaining, but it still doesn't work. It just does what I want it to do, but then goes back to the original thing that it did when it was clicked once. Thank you for helping!
- -Scratcher-
-
100+ posts
Clicking: Once, do one thing, another time, do something else
Could you show the project? It would be easier to find out what's wrong Sorry if it sounds like I'm complaining, but it still doesn't work. It just does what I want it to do, but then goes back to the original thing that it did when it was clicked once. Thank you for helping!

- Rlucy
-
58 posts
Clicking: Once, do one thing, another time, do something else
I will. It is a work in progress and it is not shared. I will share it now!Could you show the project? It would be easier to find out what's wrong Sorry if it sounds like I'm complaining, but it still doesn't work. It just does what I want it to do, but then goes back to the original thing that it did when it was clicked once. Thank you for helping!
- Rlucy
-
58 posts
Clicking: Once, do one thing, another time, do something else
https://scratch.mit.edu/projects/55676400/#player Okay. This is the project. As it says in the instructions, it is the clicking the green line. Thank you!
- -Scratcher-
-
100+ posts
Clicking: Once, do one thing, another time, do something else
https://scratch.mit.edu/projects/55676400/#player Okay. This is the project. As it says in the instructions, it is the clicking the green line. Thank you!Got it, there is a mistake in deck26's script. You set the variable “status” to ((1) - (state)), but of course that doesn't change the variable state, so you need to set the own variable, “state” to ((1) - (state)). So it alternates between 0 and 1.
Another tip, instead of using costume changing, use just one costume, but the motion blocks. And to make it safer, put the set status block into the if else-condition, just like that:
Last edited by -Scratcher- (June 5, 2015 17:41:07)
- Rlucy
-
58 posts
Clicking: Once, do one thing, another time, do something else

Last edited by Rlucy (June 5, 2015 18:00:07)
- deck26
-
1000+ posts
Clicking: Once, do one thing, another time, do something else
Apologies for the error in my script, I changed my mind about the variable name.
What you have at the moment sets state to 0 in both cases so it will never change from 0 once set to 0. If you change the first bit to set it to 1 you need to make sure you're using an if/else or the second bit will activate every time.
That's why I prefer the single line method - state = 1 - state which changes 1 to 0 and 0 to 1.
What you have at the moment sets state to 0 in both cases so it will never change from 0 once set to 0. If you change the first bit to set it to 1 you need to make sure you're using an if/else or the second bit will activate every time.
That's why I prefer the single line method - state = 1 - state which changes 1 to 0 and 0 to 1.
- -Scratcher-
-
100+ posts
Clicking: Once, do one thing, another time, do something else
Like @deck26 already said, you have to use the if-else block, otherwise it's not going to work, because it always runs both if-states.I keep saying this, but sorry if I sound like I'm complaining, but here is the improved link- https://scratch.mit.edu/projects/55676400/#editor I think I did what you said to do, but it still doesn't seem to work. I tried changing the if else block to two if blocks. That didn't work either. Thank you for helping me!
Also, make sure to set up the variables correctly:
If <(state) = (0)>
set to (1)
else
set to (0)
Or you use the "set to ((1) - (state))" method. Still, I prefer the if-else method, because even there is going something wrong with the state value (when it's not 1 or 0), it's not going to mess up everything. Also, you can add more than just two states for special buttons, like
A third thing is, you have to set the state to 1 when the green flag is clicked, not to 0, because 1 means closed bar.
And one last thing, make sure the y-coordinates in all glide blocks are the same, to avoid other problems

Last edited by -Scratcher- (June 5, 2015 20:02:15)
- Rlucy
-
58 posts
Clicking: Once, do one thing, another time, do something else
That is fine! That happens to everyone! Thanks for the help, I will try it out! Apologies for the error in my script, I changed my mind about the variable name.
What you have at the moment sets state to 0 in both cases so it will never change from 0 once set to 0. If you change the first bit to set it to 1 you need to make sure you're using an if/else or the second bit will activate every time.
That's why I prefer the single line method - state = 1 - state which changes 1 to 0 and 0 to 1.
- Rlucy
-
58 posts
Clicking: Once, do one thing, another time, do something else
Thank you thank you thank you thank you!!!!!!!!!!!!! It works!!!!!! Thank you soooooooooo much! I will give you credit in the project!Like @deck26 already said, you have to use the if-else block, otherwise it's not going to work, because it always runs both if-states.I keep saying this, but sorry if I sound like I'm complaining, but here is the improved link- https://scratch.mit.edu/projects/55676400/#editor I think I did what you said to do, but it still doesn't seem to work. I tried changing the if else block to two if blocks. That didn't work either. Thank you for helping me!
Also, make sure to set up the variables correctly:
If <(state) = (0)>
set to (1)
else
set to (0)
Or you use the "set to ((1) - (state))" method. Still, I prefer the if-else method, because even there is going something wrong with the state value (when it's not 1 or 0), it's not going to mess up everything. Also, you can add more than just two states for special buttons, likeA third thing is, you have to set the state to 1 when the green flag is clicked, not to 0, because 1 means closed bar.And one last thing, make sure the y-coordinates in all glide blocks are the same, to avoid other problems





- Discussion Forums
- » Help with Scripts
-
» Clicking: Once, do one thing, another time, do something else