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

turned based combat system keyboard_check mouse clicks not updating

Currently I am working an a turned based combat system using state mechanics. I have an object called oUnit and an object oBattle. oBattle has a ds_list which contains the ids of three oUnits to see whos turn it is. oUnit currently just executes its state in the step event. I have three state scripts "stateWait", "stateActive" and "stateDone". Of these three state scripts only stateActive actually runs some code.

oUnit
GML:
//STEP event
script_execute(state);
script stateActive
GML:
function stateActive(){
    if(keyboard_check_released(vk_lcontrol))
    {       
        state = stateDone;
    }
}
oBattle
GML:
if(instance_exists(oUnit))
{
    var unitAmount = instance_number(oUnit);
    var triggerNextRound = true;
    for(var i = 0; i<unitAmount; i++)
    {
        var unit_id = instance_find(oUnit,i);
        if( unit_id.state ==stateActive)
        {
            triggerNextRound = false;
        }
    }
    if(triggerNextRound)
    {
       ds_list_delete(dsl_queue, 0);
       dsl_queue[| 0].state = stateActive;
    }
}
I noticed that the keyboard_check_released does not get updated. which results that two units gets set to stateDone eventhough I only pressed the button once!

My solution to this problem was that I created an oInput object which handles the input and then rather check for the varibles in oInput than using the actual game maker keyboard functions

oInput
GML:
//STEP event
keyPressed = keyboard_check_released(vk_lcontrol);
script stateActive
GML:
function stateActive(){
    if(keyPressed)
    {       
        state = stateDone;
    }
}
 

Nidoking

Member
keyboard_check_released will retain its value throughout the step. If you want it to affect only one unit, you'd need to do something with the value of keyPressed (why it's called keyPressed when it's tracking the release of a key, I have no idea) after you've processed it once.
 
keyboard_check_released will retain its value throughout the step. If you want it to affect only one unit, you'd need to do something with the value of keyPressed (why it's called keyPressed when it's tracking the release of a key, I have no idea) after you've processed it once.
ups my fault. yes the variable should be called keyReleased and it is acutally called from the object oInput. this solves the issue with the key_check function. I edited my earlier post
 
Top