Discuss Scratch

K4ffekoppen
New Scratcher
44 posts

Switching into the wrong background

Hello, I've ran into an issue and I bet there's an easy fix to it but I can't figure it out.

I have code like this;
when backdrop switches to [Forest v]
if <[backdrop [number v] = [14]> then
wait until <(x position) > [220]>
switch backdrop to [Desert v]
stop [this script v]

end

Now this works great when I'm actually in the Outside backdrop, however, if I go to “Desert” which would be backdrop nr 15 and then touch x>220 then I will still trigger this code eventhough I'm not in backdrop nr 14 anymore.

I've tried using “If -> Else if backdrop number not 14 then stop this script” and also just adding stop this script after the code I wrote above but it's still not working, I guess that's because it's just “waiting until” I reach 220 regardless of what backdrop I'm out.

I'm guessing I need to use the “If not backdrop 14” in some other way but I can't figure it out.
Thanks for any help.
/K4ffekoppen

Last edited by K4ffekoppen (Nov. 14, 2024 10:00:29)

deck26
Scratcher
1000+ posts

Switching into the wrong background

But once you enter the if block with backdrop number = 14 (can't see any reason to check that when you know the backdrop has just switched!) the wait until doesn't care what backdrop is displayed when the x>220 happens - the backdrop could have switched multiple times while that block is waiting.

Perhaps what you want is wait until (x > 220) OR (not (backdrop=14)) and then only switch backdrop if the current backdrop is 14. You don't need the ‘stop this script’.
K4ffekoppen
New Scratcher
44 posts

Switching into the wrong background

deck26 wrote:

But once you enter the if block with backdrop number = 14 (can't see any reason to check that when you know the backdrop has just switched!) the wait until doesn't care what backdrop is displayed when the x>220 happens - the backdrop could have switched multiple times while that block is waiting.

Perhaps what you want is wait until (x > 220) OR (not (backdrop=14)) and then only switch backdrop if the current backdrop is 14. You don't need the ‘stop this script’.

I think I used that “if backdrop = 14” because I didn't want the script to keep going if the backdrop wasn't 14 in case I kept going into different backdrops.
Will “or” work, you mean both both “wait until (x > 220) OR (not (backdrop=14)” together?
I basically would like to have a script that says "Only If backdrop = 14 and x >220 switch backdrop to
K4ffekoppen
New Scratcher
44 posts

Switching into the wrong background

I solved it by making a new variable called “current backdrop” then I wrote the code like this for all the different backdrops;

when backdrop switches to [outside v]
set [current backdrop v] to [outside]

when backdrop switches to [Outside v]
forever
if <(current backdrop) = [Outside]> then
if <(x position) > [220]> then
switch backdrop to [Desert v]
stop [this script v]

end

end
end

So then by using that variable there was no confusion as to what backdrop I was in or when the code should be working, each time the player gets into a new backdrop the current backdrop variable changes to that one.

Last edited by K4ffekoppen (Nov. 16, 2024 15:05:23)

Powered by DjangoBB