Discuss Scratch

Rlucy
Scratcher
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
Scratcher
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)

whenthisspriteclickedifstate=0 thendosomethingelsedosomethingelsesetstatusto1-state
Rlucy
Scratcher
58 posts

Clicking: Once, do one thing, another time, do something else

Thank you!
Rlucy
Scratcher
58 posts

Clicking: Once, do one thing, another time, do something else

deck26 wrote:

Have a variable that keeps track of the state (0 and 1 makes it easy to toggle between the values)

whenthisspriteclickedifstate=0 thendosomethingelsedosomethingelsesetstatusto1-state
Wait… It doesn't work. The State=0 won't fit into the if then block.
Sigton
Scratcher
1000+ posts

Clicking: Once, do one thing, another time, do something else

Rlucy wrote:

deck26 wrote:

Have a variable that keeps track of the state (0 and 1 makes it easy to toggle between the values)

whenthisspriteclickedifstate=0 thendosomethingelsedosomethingelsesetstatusto1-state
Wait… It doesn't work. The State=0 won't fit into the if then block.
Can you please explain what you mean by “it wont fit”?

Sigton
-Scratcher-
Scratcher
100+ posts

Clicking: Once, do one thing, another time, do something else

Rlucy wrote:

Wait… It doesn't work. The State=0 won't fit into the if then block.
It will, it's just not the correct shape. You will find it inside the operators tab and rather looks like < ▒ = ▒ >

Last edited by -Scratcher- (June 3, 2015 20:11:26)

languagegal14
Scratcher
500+ posts

Clicking: Once, do one thing, another time, do something else

-Scratcher- wrote:

Rlucy wrote:

Wait… It doesn't work. The State=0 won't fit into the if then block.
It will, it's just not the correct shape. You will find it inside the operators tab and rather looks like < ▒ = ▒ >
To make it easier on you, she is talking about this one:
=
Except that one is always a diamond thing when you use it, no the oval… oh well.
-Scratcher-
Scratcher
100+ posts

Clicking: Once, do one thing, another time, do something else

languagegal14 wrote:

-Scratcher- wrote:

Rlucy wrote:

Wait… It doesn't work. The State=0 won't fit into the if then block.
It will, it's just not the correct shape. You will find it inside the operators tab and rather looks like < ▒ = ▒ >
To make it easier on you, she is talking about this one:
=
Except that one is always a diamond thing when you use it, no the oval… oh well.
She?
That's the reason why I didn't use the scratchblocks feature, to show how it actually looks like..
Rlucy
Scratcher
58 posts

Clicking: Once, do one thing, another time, do something else

Sigton wrote:

Rlucy wrote:

deck26 wrote:

Have a variable that keeps track of the state (0 and 1 makes it easy to toggle between the values)

whenthisspriteclickedifstate=0 thendosomethingelsedosomethingelsesetstatusto1-state
Wait… It doesn't work. The State=0 won't fit into the if then block.
Can you please explain what you mean by “it wont fit”?

Sigton
What I mean is that it won't let me insert that specific block into the if then block.
Rlucy
Scratcher
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
Scratcher
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-
Scratcher
100+ posts

Clicking: Once, do one thing, another time, do something else

Rlucy wrote:

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!
Could you show the project? It would be easier to find out what's wrong
Rlucy
Scratcher
58 posts

Clicking: Once, do one thing, another time, do something else

-Scratcher- wrote:

Rlucy wrote:

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!
Could you show the project? It would be easier to find out what's wrong
I will. It is a work in progress and it is not shared. I will share it now!
Rlucy
Scratcher
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-
Scratcher
100+ posts

Clicking: Once, do one thing, another time, do something else

Rlucy wrote:

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:
whenclickedgotox:-240y:0setstateto0whenthisspriteclickedifstate=0thenglide0.2secstox:-150y:0setstateto1elseglide0.2secstox:-240y:0setstateto0

Last edited by -Scratcher- (June 5, 2015 17:41:07)

Rlucy
Scratcher
58 posts

Clicking: Once, do one thing, another time, do something else

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!

Last edited by Rlucy (June 5, 2015 18:00:07)

deck26
Scratcher
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.
-Scratcher-
Scratcher
100+ posts

Clicking: Once, do one thing, another time, do something else

Rlucy wrote:

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!
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.
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
whenthisspriteclickedifstate<3thenchangestateby1elsesetstateto1For 3 different states
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.
whenclickedhidegotox:-130y:-15setstateto1
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
Scratcher
58 posts

Clicking: Once, do one thing, another time, do something else

deck26 wrote:

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.
That is fine! That happens to everyone! Thanks for the help, I will try it out!
Rlucy
Scratcher
58 posts

Clicking: Once, do one thing, another time, do something else

-Scratcher- wrote:

Rlucy wrote:

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!
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.
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
whenthisspriteclickedifstate<3thenchangestateby1elsesetstateto1For 3 different states
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.
whenclickedhidegotox:-130y:-15setstateto1
And one last thing, make sure the y-coordinates in all glide blocks are the same, to avoid other problems
Thank you thank you thank you thank you!!!!!!!!!!!!! It works!!!!!! Thank you soooooooooo much! I will give you credit in the project!

Powered by DjangoBB