What I Need:I'm making a game where I've got a team of players on the pitch and they all fall asleep at different intervals, but I'm having trouble setting up the timer for this to work (read: what I've got ain't doing what I think it should).
So I'm trying to set up a system where each instance of oPlayer has a different countdown attached to it, which then tick down and reset, e.g. instance1 starts with 12seconds, instance2 starts with 10 seconds etc.
5 different timers onto 5 instancesWhat I've Got:For the oPlayer Object I've got an alarm which runs the script below 5 times, once for each player (the script is basically a state machine, ticking down from the initial value in the "awake" state, then switching to the "asleep" state and ticking down again. This keeps occuring, with the timing getting faster till it switches between being awake for 3 seconds and asleep for 3 seconds)
//SCRIPT NAME: sNarco
//argument0 = cdownasleep
//argument1 = cdownawake
//argument2 = cdslp_tracker
//argument3 = cdawk_tracker
//argument4 = alarm[n]
//argument5 = awake
//while the state machine is awake
if argument5=1
{
//countdown to being asleep
argument0-=1;
//when timer finishes, falls asleep
if argument0=0
{
argument5=0;
//the time that it resets to gets bigger up to 3 (starting from 1)
if argument3<2
{
argument1=ceil(random_range(argument3,argument3+1));
}
else
{
argument1=3;
}
argument3=argument1;
}
}
else
{
//countdown to being awake
argument1-=1;
//when timer finishes, awaken
if argument1=0
{
//the time that it resets to gets smaller down to 3 (starting from the random initial value)
if argument2>5
{
argument0=floor(random_range(argument2-2,argument2));
}
else
{
argument0=3
}
argument2=argument0;
argument5=1;
}
}
//reset the alarm
argument4=room_speed
So I've set up an array for arguments 0,1,2,3,5 (cslp[0...4], cawk[0...4], cslp_t[0...4], cawk_t[0...4], awake[0...4]) and argument 4 is for each alarm, so the code for alarm[0] looks like this:
for (i=0; i<instance_number(oPlayer01); i+=1)
script_excecute(sNarco,cslp[i],cawk[i],cslp_t[i],cawk_t[i],alarm[0],awake[i]);
The arrays in the create event for the oPlayer object look like this:
//initialise arrays
for (n=instance_number(oPlayer01);n>-1;n-=1)
{
//argument0
//initial value for the timer to countdown from
cslp[n]=floor(random_range(7,12));
//argument1
//these values get reset in the alarm itself before being used, so this just initialises the array
cawk[n]=1;
//argument2
//tracker for the sleep countdown
cslp_t[n]=cslp[n];
//argument3
//tracker for the awake countdown
cawk_t[n]=1;
//argument5
//set all the machines to awake
awake[n]=1;
n-=1;
}
//set up alarm (argument4)
alarm[0]=room_speed;
Then in the draw event for the oPlayer Object ive got a loop that
SHOULD draw the timer for each alarm separately on each player:
//draw alarms
for (i=0; i<instance_number(oPlayer01); i+=1)
{
if awake[i]=1
{
//if it's awake then draw that time in blue (should be a number between 3-12 incl.)
draw_set_color(c_blue)
draw_text(instance_find(oPlayer01,i).x,instance_find(oPlayer01,i).y-45,cslp[i]);
}
else
{
//if it's asleep then draw that time in green (should be a number between
draw_set_color(c_green);
draw_text(instance_find(oPlayer01,i).x,instance_find(oPlayer01,i).y-45,cawk[i]);
}
}
but instead it just seems to draw them all on each player, overlaying them ontop of each other while not ticking down at all:
Now I don't know whats wrong, if it's the way I'm calling the arguments, if its the arrays, if its the way I'm drawing the text, or do I need separate alarms? I don't think I'm calling the right variables to draw? Do I need to put a "" return <expression> "" into the script? I know the state machine part works, I had it as the code for a single alarm and it ticked down just fine.
I don't even know if this is the best way of doing this, setting up different alarms that all count down separately, if it's not then please enlighten me.
Any help would be much appreciated, I've attached the .gmz for this
here (google drive link). Thanks in advance!