The premise of my problem is I have a boss that goes into different states, for example state.forcefield.
When he is in a state, a queue of functions runs which carry out some actions like a change the state of the player, destroy and create instances etc. There is a time delay which I can change after each function until the queue ends and then the state changes or something similar. After each function in the queue has run, it gets deleted so the next function can run.
This is the problem I have: I want the functions to not be deleted as the boss will move into the same state later in the game at which point I want the same functions to run as before. But because I am using a queue system, they have all been deleted so I have to create a new state and queue for the same events.
I think using list would be the best solution, but all the solutions I have seen still delete each function in the list which I don't want to happen. My code is this:
Create:
dt=delta_time/1000000
time=0*dt;
queue1=[function() {
obj_pl_um_states.state=states.nopoo;
audio_play_sound(sou_steam, 0, 0);
sprite_index = spr_coff_boss_steam;
image_index = 0;
path_start(path12, 1, path_action_stop, true);
return 240;//This is crucial as it allows me to set a delay for the next function to start
},
function() {//Destroy the speech
with(obj_forcefield) instance_destroy();
audio_play_sound(sou_shatter,1,0)
obj_en_coff_boss_states.state=cfbossstates.spin
}]//There a lot more functions than two but I've just used two for an example
And in my step event:
if(state==cfbossstates.steam){//When in this state perform the functions in queue1
if ( time > 0 ) {
time -= 1;
} else {
while( array_length( queue1 ) > 0 ) {
var _next = queue1[ 0 ];
array_delete( queue1, 0, 1 );//Deletes the items in the queue which I want to avoid
var _result = _next();
if ( _result != undefined ) {
time = _result;
break;
}
}
}
}
}
If anyone can suggest a solution which does not involve rewriting everything that would be great. My coding skills are amateur so things like structs and constructors with lots of different functions at this point is not really what I'm after....although if that is the only way I guess it is the only way.