Discuss Scratch

MichaelPCgamer
New to Scratch
19 posts

Maze game glitches

I need to share my project I know, I need to rebuild it online because I'm using the offline editor. Nope, it uploads automatically. I'm making a simple maze game where you control the sprite using the arrow keys and navigate to a goal. In the beginning, the levels are easy and short, but eventually, you will first need to touch a button in order for a door to open and allow access to certain rooms with keys and stuff. You can't move through walls. Each new level contains a different sprite (originally I only had one sprite as the goal which moved to diff spot for each level, but some glitch happened and I thought the best way to avoid it was to make one new sprite per level). My problem occurs where after reaching the 2nd level, the controlled sprite fails to move. I notice frames of attempts but it jumps back 4 units (the code to prevent moving through walls is something like “if touching specific color (all walls are the same color throughout the entire game), move back the same number of steps as attempted going into the wall”). One question I have is should I make the maps built through backdrops or sprites? If it's backdrops I can't make the code for not going through walls “if touching backdrop” I gotta use “if touching color” but if I use sprites as my maps I can use “if touching sprite”… but I think when I can't move in 2nd level its bc the game thinks I'm still “forever touching” a color.

https://scratch.mit.edu/projects/238879052/#editor
DD-8861
Scratcher
100+ posts

Maze game glitches

I would recommend having all the walls be in one sprite, it is more efficient that way. On level 2 I don't think the problem is that is it still touching the color black, because it doesn't look like it is. It looks like it could be easy to fix, but you need to share the project so we can see what is preventing the cat from moving.
mstone326
Scratcher
1000+ posts

Maze game glitches

Project is not shared. Also, can you break down your issue into paragraphs. I have read the above 3 times but keep getting lost as it is one thing after the next all together.

High School Athletic Director / Middle School Tech Teacher / High School Baseball Coach
Kung Fu by Nintendo 1984 - https://scratch.mit.edu/projects/369994801/
Taco Defense - Speed Typing - https://scratch.mit.edu/projects/316795450/
Halloween Boss Battle - Taking Back our Woods - https://scratch.mit.edu/projects/257155118/
Almost Pong - https://scratch.mit.edu/projects/656276979/
Studio - My Best Projects - https://scratch.mit.edu/studios/4125978/
Forum Help Project Examples - https://scratch.mit.edu/studios/4133335
DD-8861
Scratcher
100+ posts

Maze game glitches

For some reason, people are able to view unshared projects in the scratch 3.0 beta, if they have the link, so I saw your project there. The reason why you can't move in level 2 is because there is a forever go to 150, 100 block that you probably forgot about, or didn't mean to put it there. It is in sprite1. The script you have looks like this:
when green flag clicked
forever
if <(stage) = [2]> then
go to x: (150) y: (100)
set size to (35) %
if <touching [stage2 v] ?> then
say [Stage 2 complete!] for (2) secs
set [stage v] to [3]
stop [this script v]
end
end
end


So in that script, you will want to remove the block
go to x: (150) y: (100)
and that should fix the problem.

Last edited by DD-8861 (Aug. 13, 2018 02:12:38)

MichaelPCgamer
New to Scratch
19 posts

Maze game glitches

I hope this message is sent to everyone cuz I appreciate the heck outa everyone helping.

I did share the project link however that may not have been enough…
I need that “go to 100,150” there cuz each level starts with a definite starting point. I thought getting rid of the beginning “forever” block surrounding everything would help but it just doesn't start level 2 where it should and u gotta move the sprite in level 1 to the perfect spot.
I may try placing all the “if level #, go to (starting position)” in one block of code but something tells me it'll glitch.

DD-8861, All the walls can be 1 sprite by simply changing costume, and I will be shifting walls a lot in later levels so I need to allow movement possibilities.

Sry for the long paragraph that's how my mind works I rant.

Here it is again. https://scratch.mit.edu/projects/238879052/
DerpyHead0
Scratcher
1000+ posts

Maze game glitches

you need to at least move the block otherwise it'll be completely stuck there. it seems like you want to only do it ONCE, so you probably want this script instead.

when green flag clicked
wait until <(stage) = [2]>
go to x: (150) y: (100)
set size to (35) %
wait until <touching [stage2 v] ?>
say [Stage 2 complete!] for (2) secs
set [stage v] to [3]

when I start as a clone
delete this clone
MichaelPCgamer
New to Scratch
19 posts

Maze game glitches

DerpyHead0 wrote:

you need to at least move the block otherwise it'll be completely stuck there. it seems like you want to only do it ONCE, so you probably want this script instead.

when green flag clicked
wait until <(stage) = [2]>
go to x: (150) y: (100)
set size to (35) %
wait until <touching [stage2 v] ?>
say [Stage 2 complete!] for (2) secs
set [stage v] to [3]

That coding still doesn't make the size change, or place the sprite in the correct place. The sprite remains exactly where it was during the last frame of level 1, and if it's touching even a pixel of “wall” it doesn't move at all, and if the final frame of level 1 happens to be in a non-wall area of level 2 the size doesnt change and u cant access most of the map anyhow.

Either I need to change the walls (map) from background to sprite… or the entirety of the logic.
DD-8861
Scratcher
100+ posts

Maze game glitches

I posted a remix of your project. In that remix, I fixed the glitches that you had, and I also made the code way more efficient. If you have any questions about what I changed, or about any other scripting problems, feel free to ask. Here is the link to my remix: https://scratch.mit.edu/projects/239101762/
MichaelPCgamer
New to Scratch
19 posts

Maze game glitches

Ok I've learned quite a bit about all the logic and what works what doesnt.

To start, I created a simple version of this game right here in which I only experiment with level changes https://scratch.mit.edu/projects/239398037/ . The script for sprites changing to next-level places might be a problem, so I made it simple and made the most effective version I could. I've noticed that in every remix, the code in which the moving character cant go beyond the walls only includes “if touching color”, not “if touching sprite”, cuz ur always touching the sprite and the if touching color has worked for everyone the whole time.

When transitioning from level to level, the difference between “if touching goal” and “wait until touching goal” confuses me. Isn't it the same thing? Ye I put both logics into my scratch and it worked for both. I think both r equally efficient. My next step is to implement the next several levels which I've separately been drawing out for days.

I'm done with drawing the map in the backdrop, it'll be done with sprites.

Ok the “broadcast next level” thing doesn't make sense. Yes grammatically it does but the way I have it in my simple project doesn't require one.
DD-8861
Scratcher
100+ posts

Maze game glitches

You have everything running in forever loops. This is why ‘if’ and ‘wait until’ are doing practically the same thing, which isn't really a problem. There are many different ways to program the exact same thing.

The way that I programmed my remix was for efficiency. There is no need for something to “forever go to 180, 100”, like you have. It can just be set it to go there once and it will stay. Either way works for a simple project, so it is just opinion on which one you want to do. If my broadcast method is confusing to you, or you don't like it, then don't use it.
MichaelPCgamer
New to Scratch
19 posts

Maze game glitches

I need to change the maps from sprites to backgrounds. here's why.

Since I can tell character not to move through a certain color, I can use the backdrops. But sprites become tricky to use when you accidentally grab hold of it in the window and move it, which happened. Now all my other sprites are “behind” it and my variables aren't visible. To my knowledge backdrops don't move when clicked so some drawing of maps needs to be done again.
DD-8861
Scratcher
100+ posts

Maze game glitches

Yes, that is quite annoying (and I wish there was a way to turn it off) when you accidentally drag something and it moves to the front layer. You can just put this script and it will move to the back again.
when green flag clicked
go back (100) layers
And you are correct in saying that you can not drag the backdrops.
Also, you do not need to redraw the maps, you can just copy the costumes to the backdrop.

Last edited by DD-8861 (Aug. 18, 2018 03:20:32)

MichaelPCgamer
New to Scratch
19 posts

Maze game glitches

https://scratch.mit.edu/projects/239417336/

list of glitches happening, These are not all happening at the same time, nor every time I run the game:

Press green flag, level 3 gate appears and immediately glides up like it's supposed to in level 3 after touching key.

Random sprites appear at wrong maps at the beginning.

Goal 3 doesn't appear in level 3 at all, making clearing level 3 impossible. The gate just disappeared too. After restarting, the gate appears in level 1 and doesn't move. Restarted, everything went well until level 3, where the gate should disappear, it doesn't. Restart, everything goes good til level 3 gate and goal arent there, restart, the gate in level 1.

In level 3 gate's script, there should be a “stop this script” at end of level 3, then “if stage > 3, hide”, after hide came a “stop this script”, and I moved it to the very end of the forever loop, which resulted in never seeing the gate ever.

Each sprite is on a perfect sequential “level1, level2, etc” but somehow things are glitching and popping in and out incorrectly.
DD-8861
Scratcher
100+ posts

Maze game glitches

You have a script in the level 3 goal that includes this
when green flag clicked
forever
if <(level)> [3]> then
hide
stop [this script v]
end
end
If you are at level 4 and then click the green flag, the level is still set to 4 for one frame before a different script sets it back to 1. Since the level is therefore greater than 3, it stops that script and the level 3 goal never appears. To fix this, either just take out the ‘stop this script’, or put a Wait at the top, like this
when green flag clicked
wait (0.1) secs
forever
end

As for the gate, you simply put a “stop this script” at the bottom of the forever loop. So it just stops. That's why it doesn't show on level 3, and it doesn't hide on level 1. Take out the Stop This Script at the bottom, and put in another wait 0.1 secs at the top, for the same reason as the goal. It is technically level 3 for the first frame, so it shows and glides on level 1.
MichaelPCgamer
New to Scratch
19 posts

Maze game glitches

Everything works thx to that small change everywhere it needs it.
The gate kept on appearing in the top middle of level 4 map, AND the gate also infinitely looped through going to level 3 mid and gliding up, so I need a stop this script after it glides, but stopping the script keeps the gate in that place at end of glide, so I created separate flags (starts) for each level, (<3), (=3) and (>3), with (wait 0.1 sec) b4 “forever”.

https://scratch.mit.edu/projects/239494206/
MichaelPCgamer
New to Scratch
19 posts

Maze game glitches

Dunno if people are still following this but here's up to level 5. https://scratch.mit.edu/projects/239688229/

I'm having trouble with the code for the level 5 gate. When hitting the bat, my character goes to start like it should. Touching the key makes the gate open (but it infinitely goes back and forth), and touching the bat after the key makes the gate stay perfectly. My only prob is the gate not staying open.

In the future, there may be a shooting mechanic to shoot non-moving enemies, as well as ability to shift gates from hallway to hallway using 1 or more keys which control it. I can provide animation to explain that last part.
DD-8861
Scratcher
100+ posts

Maze game glitches

You have the script like this
forever
go to x: (202) y: (-50)
if <(gate 5) = [1]> then
glide (1) secs to x: (122) y: (-50)
end
end
that is why it keeps going back and forth. Instead you could just do this
forever
if <(gate 5) = [3]> then
go to x: (202) y: (-50)
end
if <(gate 5) = [1]> then
glide (1) secs to x: (122) y: (-50)
end
end
MichaelPCgamer
New to Scratch
19 posts

Maze game glitches

https://scratch.mit.edu/projects/240428362/

So I've fixed some stuff, added a bit to level 6, and I had an issue in level 5 where after opening the gate I wanted the goal to tell me “finished level 5” but it didnt work so it took me 2 hours to find the perfect code to make that work.
Just in case this thread is being followed still I'm posting my continuation of the project here in case. I might change threads and add this question in other forums.

Powered by DjangoBB