GMLscripts.com

Discuss and collaborate on GML scripts
Invert

You are not logged in.

#1 Re: GML Code Help » IF statement always returns true » 2013-10-06 11:00:02

Thanks for the response. It worked flawlessly after that quick change. I knew I was overlooking something simple; I've taken the differences of key event functions into account when coding, but it slipped my mind when I had to go back to using the D&D events. Makes sense now:)

#2 GML Code Help » IF statement always returns true » 2013-10-05 12:23:01

ReeferMadness
Replies: 2

Hey folks,

I couldn't find anything relevant to my issue with a quick search, so I'll have to go ahead to ask. I'm fairly new to GM so I'm still learning the do's and dont's. I think I may have found a don't.

I'm currently creating a small game for a school project and ran in to an issue with the IF statement (tl;dr action starts here) I created a simple script that moves the player to the next room, when the current room is the start screen; all is well there. This if statement also checks for the last room, in which case it will end the game when the enter key is pressed. I've attempted to modify this statement, for testing purposes, to allow me to skip the other rooms with two enter key presses, using a variable to check if the enter key was pressed.

The problem is that even though the value of the variable is initialized as 0 (or false, I've tried Boolean too) it still fires off as though it was true.

Expandif (room != rm_end) {

    if (room == rm_start || enter_pressed == true) {
        
        room_goto_next();
        enter_pressed = false; // Resetting variable
    
    } else {
    
        enter_pressed = true;
    
    }
    
} else {

    game_end(); 
    
}

The enter_pressed is a global variable defined and initialized in a Game Start event, this code was placed in a Enter key event. I feel like I may be overlooking something simple here, but I could use a fresh pair of eyes with a bit more experience telling me where I may have butchered this. Sorry for the lengthy description, I appreciate any help offered.

Board footer

Powered by FluxBB