1. Hello Guest! It's with a heavy heart that we must announce the removal of the Legacy GMC Archive. If you wish to save anything from it, now's the time! Please see this topic for more information.
    Dismiss Notice

GM:S 1.4 Problem that i can't solve

Discussion in 'Programming' started by Mauricio Antunes, Aug 11, 2019.

  1. Mauricio Antunes

    Mauricio Antunes Member

    Joined:
    Oct 8, 2016
    Posts:
    34
    Hi, im trying to make one thing on my game.

    I need that the user click on the button, after the button is pressed it will check if the global variable is higher than another one then will give an error if its true, if its false it will change room.

    I don't know what happen because it always go for the next room and always pass the max number.
    Can you guys help me? I tried a lot of things but in the end i tried the code that i paste here.

    if (global.foodreserve >> global.foodstorageleft)
    {
    audio_play_sound(snd_errormsg,1,0);
    }

    if (global.foodreserve <= global.foodstorageleft)
    {
    global.foodowneddisplay = (global.foodowneddisplay + global.foodreserve);
    room_goto(RM_002_MainGame);
    }
     
  2. curato

    curato Member

    Joined:
    Jun 30, 2016
    Posts:
    424
    should be
    Code:
    if (global.foodreserve > global.foodstorageleft)
    you just have a typo looks like
     
  3. Mauricio Antunes

    Mauricio Antunes Member

    Joined:
    Oct 8, 2016
    Posts:
    34
    I saw that and changed, but it didnt work either =(
     
  4. curato

    curato Member

    Joined:
    Jun 30, 2016
    Posts:
    424
    with that fix it should run one if statement or the other. I would say use show_debug_message prior to the first if statement to confirm the values are what you think they are.
     
    Mauricio Antunes likes this.
  5. RefresherTowel

    RefresherTowel Member

    Joined:
    Jul 13, 2016
    Posts:
    1,219
    Also, use an else statement instead of the second if statement, rather than two ifs. "If" logic is important and if it's an "or" scenario you should always be using else.
     
    Mauricio Antunes likes this.
  6. Joe Ellis

    Joe Ellis Member

    Joined:
    Aug 30, 2016
    Posts:
    994
    Could it be that you're clamping the food reserve to the max? then it will = the max, maybe change it to:

    Code:
    if (global.foodreserve >= global.foodstorageleft)
    {
    audio_play_sound(snd_errormsg,1,0);
    }
    
    if (global.foodreserve < global.foodstorageleft)
    {
    global.foodowneddisplay = (global.foodowneddisplay + global.foodreserve);
    room_goto(RM_002_MainGame);
    }
     
  7. Mauricio Antunes

    Mauricio Antunes Member

    Joined:
    Oct 8, 2016
    Posts:
    34
    Yeah i tried everything you guys said but it's not working too....i will need to check everything again -_-
     

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