• Hey! Guest! The 37th GMC Jam will take place between May 28th, 12:00 UTC and June 1st, 12:00 UTC. Why not join in! Click here to find out more!

Trying to Program Max Points to Proceed to Next Level

I been trying to figure this out for a while. What I want to do is when the player has a set number of "collectibles", he will proceed to the next level.

What I have right now won't work and I wondering what I am doing wrong. The player will continue to collect and wont stop.

if global.points >= 20
This is in the creation code in the room

And this is what I have for as far as the score system in the create event.

global.points = 0


Think about this logically. Try saying out loud to yourself where and when the check for points happens. Try to think it over for a minute or two before opening the spoiler tag.

Creation code only happens once - on creation. So, unless you start with 20 or more points, this check will never validate.
What you need to do instead, is continually do the check. One way is to put your code in a step event (such as the player's).
A more efficient way would be to do it every time a new collectible is collected.
So, whenever you add a point, follow it up with what you have in your creation code now.
LOL, I figured it out. All I had to do was to put it in the step even of the player. I will need to organized it more, but I got what I wanted. Thank you :)


šŸ§ *penguin noises*
GMC Elder
The most efficient way would be to add the code in the collision event with the collectibles (since that's the only place where the number of collectibles change). Won't really make a difference for such a small code snippet, but it's always good to keep things like this in the back of your head - once you write a 1000-line AI pathfinding script that you want to run for hundreds of characters at once, it's important to know where to take little shortcuts or the game will make any PC running it catch fire.

One thing you might wanna consider changing right away is not hardcoding the level name to go to, though.
Instead of

you could use

(room_goto_next() will crash if you use it in the last room of the game, so don't forget to do something to deal with this before publishing the game... a nice "congratulations" screen, a check to starting the game over from the first room if you beat the last, or just a check that refuses to move to the next room if you're already at the last)