Discuss Scratch

RogulskiSPC2020
Scratcher
44 posts

Problems with changing variables

I'm making a Mario game, I have a few buttons for an editor mode, In this editor mode you can place down tiles on the map however, I'm trying to make this not able to happen near the buttons so I can only do what the buttons do without placing a block behind it.

These buttons check if the mouse is near them, this works but the variable associated with it doesn't work as intended which is to change to 1 if the mouse is near any and be 0 at any other time. Right now, if I don't let it change constantly and leave it at 0, it does change to 1 but when I leave the mouse near it still and put the set to 0 back in it will go straight to 0 even though the statement is true for it to be 1. Then the variable is used at a different sprite to stop the placing. I'm not sure why this doesn't work.

If you need more detail about the code, here is the project.

https://scratch.mit.edu/projects/525800061/editor/

Please help!!!
deck26
Scratcher
1000+ posts

Problems with changing variables

Please identify the varioable and sprites concerned.
RogulskiSPC2020
Scratcher
44 posts

Problems with changing variables

GUI is the sprite with the buttons, the buttons use costumes 9 and 10. You can get into editor mode by pressing m and the second sprite is an editor with (when I receive move player the bit of code)

sorry about the late response
deck26
Scratcher
1000+ posts

Problems with changing variables

One potential problem is the GUI sprite and clone(s) are running the script so, for example, you might set the variable to 1 and then set it to 0 again for the second object. Not sure if that is what is happening.
RogulskiSPC2020
Scratcher
44 posts

Problems with changing variables

Yeah it really is stumping me, I have moved the detection to the main when I start as a clone and it works the same way with it always going to zero. What you said worked, I tried to do that at first when I started but I guess that wasn't the problem.

Last edited by RogulskiSPC2020 (July 30, 2021 12:15:31)

deck26
Scratcher
1000+ posts

Problems with changing variables

Not sure you've understood me. I take it you have two buttons - clones or sprite plus clone. Let's call them A and B.

So if the mouse is near A and A runs the script first it sets the variable to 0, checks the distance an sets it to 1. Then B does the same but leaves it set to 0 because the mouse is too far away.

You need to set the variable to 0 before getting A and B to run the script and they only change the variable to 1 if within the distance and otherwise don't change it..
RogulskiSPC2020
Scratcher
44 posts

Problems with changing variables

yeah, that's what I understood. But for some reason, Sprite B doesn't stop the script if it equals 1 even though it does, if you see this could you help.

Powered by DjangoBB