• 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!

GML Disable player INPUT

A

ArtCode

Guest
Hello!
I'm trying to create a game where the player can take control of numerous objects. So I must disable the main PLAYER inputs to control an another object. Which is the clever way to achieve this?
Thanks in advance :)
 

matharoo

manualman
GameMaker Dev.
You can create a variable that stores the instance id of the instance that is in control. Then in every object, before taking an input or acting on it, you can check if that instance is the one in control:

Code:
//input
if (instance_in_control == id){
    //move
}
 

NicoFIDI

Member
I usually make a parent obj_input
then use childs like:
obj_inputWASD
obj_inputArrows
obj_inputGamePad

then on "begin step" of every child I update the values as needed,
then the player just calls
obj_input.xAxis
obj_input.yAxis
obj_input.tryToJump
obj_input.tryToAtack

if you do this, then you can put into the father a value like:
available

then if you do:
if (!available) exit;
you will end the event for that input:

you can also make other inputs, if you want to change the baheviour, like:
obj_inputPauseMenu
and make xAxis,yAxis to cero
and tryToJump,tryToAtack to false
while you get the input to move arround the menu with values like:
moveUp
moveDown
select
goBack

and maybe i missunderstood your problem.
soooo.... welp :)
Hope it helps
 

NightFrost

Member
Hello!
I'm trying to create a game where the player can take control of numerous objects. So I must disable the main PLAYER inputs to control an another object. Which is the clever way to achieve this?
Thanks in advance :)
The solutions are pretty much variations of "if something either is true or is not true, don't do this" code. You didn't mention if there's only specific circumstances when control should be deferred to another object, but assuming as long as an instance of the other controllable object exists, controls should move it instead if player:
Code:
// Player step event
if(!instance_exists(obj_other_controllable_thing)){
    // Code that changes player position and does collision checks.
}
The other object contains identical position & collision code so you can move it same way as the main player object. Now, as long as it exists controls will move it, and once it is destroyed control returns to main player.
 
I would set up a main control object that stores the id of the instance you want to control:

obj_control_master
Create:
Code:
control_inst = initial_instance_you_control;
Step:
Code:
var left_dir = keyboard_check(ord('A'));
//Etc for all the controls

with (control_inst) {
   //Control input here
}
Then just pass the id of the instance you want to control to the control_inst variable in obj_control_master whenever you want to switch an instance. This way you don't have to set variables for each controllable object or muck around with parenting and stuff. Literally any object you want will be automatically controllable by simply passing its id to the master controller.
 
Top