31Nf4ChZ4H73N
Member
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
script stateActive
oBattle
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
script stateActive
oUnit
GML:
//STEP event
script_execute(state);
GML:
function stateActive(){
if(keyboard_check_released(vk_lcontrol))
{
state = stateDone;
}
}
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;
}
}
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);
GML:
function stateActive(){
if(keyPressed)
{
state = stateDone;
}
}