Trying to Program Max Points to Proceed to Next Level

Discussion in 'Programming' started by Abdur Olajuwon, Oct 9, 2019.

  1. Abdur Olajuwon

    Abdur Olajuwon Member

    Joined:
    Sep 18, 2016
    Posts:
    162
    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.

    Code:
    if global.points >= 20
    {
    room_goto(rm_level2);
    }
    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.

    Code:
    global.points = 0
     
  2. JeffJ

    JeffJ Member

    Joined:
    Jun 20, 2016
    Posts:
    339
    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.
     
    Bentley, Yal, Simon Gust and 2 others like this.
  3. Abdur Olajuwon

    Abdur Olajuwon Member

    Joined:
    Sep 18, 2016
    Posts:
    162
    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 :)
     
  4. Yal

    Yal GMC Memer GMC Elder

    Joined:
    Jun 20, 2016
    Posts:
    3,743
    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
    room_goto(rm_level2);

    you could use
    room_goto_next();

    (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)
     
    JeffJ and ParodyKnaveBob like this.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice