0

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.

1 Answers1

1

Is it possible to make presets of the queue you want to call?

For example, your queue is defined before, and in case you want to use that queue, then you can call it to fill in the current queue. Then it would still work while deleting it, as the queue has been defined somewhere else before.

Otherwise, I don't think I understand the problem, perhaps I would've made boss states of the full boss script and vary between them through switch statements (though I think you already do something similair with state==cfbossstates.steam), but I think that lingers more towards 'rewriting the whole code'.

Steven
  • 1,996
  • 3
  • 22
  • 33
  • Thanks for you input but I managed to get help from elsewhere to solve this problem. Will try to close this item. – user15950867 Aug 09 '22 at 17:33
  • That's alright, glad to hear you've solved it. Questions itself don't really get "Closed", unless it was an unclear/bad question. But if you got a solution, I do recommend placing your solution as an answer yourself, and if it's accepted (by yourself), people will know the answer got a solution. – Steven Aug 10 '22 at 06:48