• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

SOLVED Controller Input Using Object Variables Issue

Can anyone tell me why this isn't working properly?

I have made a Player Controller Input object o_input, o_inputP2, o_inputP3 & o_inputP4 with a menu Switch statement so each player can actually choose what slot their controller will be in.

I have different modes the menus work in, but this is the 2 Player Mode menu, where when player 1, chooses Slot 0 the o_input.Controller_P1 = 0 only IF the other o_input objects are NOT equal to it. But, when I choose this option and press the button, the controller slots are not assigned like they should. This works on the 1 player mode menu, but not on the other multiplayer modes.

This code is really straight forward. With it basically saying: if Slot 0 is not assigned to ANY o_inputP2, o_inputP3 or o_inputP4, assign o_input to slot 0. But if ANY of the o_inputP2, o_inputP3 or o_inputP4 is assigned to Slot 0, then show a message saying that the slot is full.

I've tried this with global variables like: global.Controller_P1 etc. but it still does the same thing.

Each controller o_input object starts with the controller slot = noone. So each player can choose the slot.

Code:
// Create event

Controller_P1 = noone;

//User Event

action_one_ = gamepad_button_check(Controller_P1, gp_face1)
Here is some code from the Switch statement:

GML:
if o_input.action_one_pressed_ {
    switch (index_) {

case player_1_input_slot_select_2_player_mode.controller_slot_0:
            
            // Sets P1 Controller Input to "0" Meaning P1 uses the first Controller slot.
            
            audio_play_sound(Start_SFX, 10, false);
            
            if o_inputP2.Controller_P2 and o_inputP3.Controller_P3 and o_inputP4.Controller_P4 != 0 {
                o_input.Controller_P1 = 0;
            } else if o_inputP2.Controller_P2 or o_inputP3.Controller_P3 or o_inputP4.Controller_P4 == 0 {
                show_message("Slot is full. Choose a Different Slot");
            }
        
        break;
    }
}
My question is, why isn't o_input.Controller_P1 equaling 0, even though o_inputP2.Controller_P2 and o_inputP3.Controller_P3 and o_inputP4.Controller_P4 are NOT equal to 0?
 
Apparently instead of saying: if o_inputP2.Controller_P2 and o_inputP3.Controller_P3 and o_inputP4.Controller_P4 != 0

I need to actually do it like this: if o_inputP2.Controller_P2 != 0 and o_inputP3.Controller_P3 != 0 and o_inputP4.Controller_P4 != 0

Put the != at the end of each o_input check. I thought by saying and would group them together and check if they ALL when equal to 0.
 

Nidoking

Member
The and (&&) operator groups booleans. Each check is a boolean. The input instances are not booleans. You won't get the results you want if you use boolean operators with things that are not booleans.
 
Top