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

Attempting to modify object variables within a sequence

EdSpaged

Member
Hey all!
Over the past few days, I've been learning about and playing around with the sequence editor within Game Maker Studio 2.3. I've run into a little bit of a roadblock at the moment though. Currently, I am attempting to develop a system that uses sequences in order to create hitboxes for attacks. However, I'm currently at a loss as to how to modify the hitboxes variables for things such as damage and knockback. I've been trying to use "sequence_instance_override_object()" to accomplish this by creating a temporary instance copy of my hitbox object, and modifying the needed values per hitbox, but haven't had much luck in that regard, encountering a lot of strange errors like sequences not playing fully and objects existing when they shouldn't. Does anyone know of a way to modify these values in the game in real time with code? Thanks so much!
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
So, not really sure what to say about this... First, lets ensure you are using the function correctly... The idea behind the "override object" function is that in your sequence you use a placeholder object with no code in it, and then when you create the sequence you call this function and swap it for one that has the code and variables you need. If that is what you are doing then we'll need to have some more concrete information about what is happening... for example, full details of the object you are swapping in and how you are using it.
 

Yal

šŸ§ *penguin noises*
GMC Elder
One thing I noticed in my jam entry (which uses sequences to randomly generate level rooms) is that it takes 1 step for sequence changes to apply (e.g. if you create a sequence, you can't with loop over any instances that's part of the sequences until the next step). I only noticed this behavior for creating them, but I wouldn't be surprised if all changes to sequences will happen between GM steps.
(It would be nice if this was documented somewhere...)

To get around the sequence limitations, I used an approach where the in-sequence objects would be inert "spawner" objects that would create the actual instance using alarms (which would then be separate from the sequence and unbound to it), would that be an option? (It was extra appropriate for my case since I specifically wanted every enemy spawner to create a random enemy, but it would work just fine with an 1:1 relationship too)
 

EdSpaged

Member
So, not really sure what to say about this... First, lets ensure you are using the function correctly... The idea behind the "override object" function is that in your sequence you use a placeholder object with no code in it, and then when you create the sequence you call this function and swap it for one that has the code and variables you need. If that is what you are doing then we'll need to have some more concrete information about what is happening... for example, full details of the object you are swapping in and how you are using it.
I currently have 2 objects, obj_placeholder, and obj_hitbox. At the moment, both objects are essentially dummy placeholder objects with just obj_hitbox having a create event of a owner id variable defaulting to 0.
If I were to do the following:
GML:
function hitboxCreate(seq,owner){
            _seq = seq;
            _seq.playbackMode=seqplay_oneshot;
            _seqLayer="seqLayer"
            sprite_index = spr_StickmanBasicPunch;
            image_index=0
            _myseq = layer_sequence_create(_seqLayer,x,y,_seq)
            _struct = layer_sequence_get_instance(_myseq)
            sequence_instance_override_object(_struct, obj_placeholder, obj_hitbox);
           
}
It works as expected, but the obj_hitbox still has that owner Id default value of 0.
Here is a reference for what the output for this looks like: https://giphy.com/gifs/jIyam5FqxmOU9ij5IF
My current goal is to modify that value on the fly when the function is called in order to avoid making a million different hitboxes. I figured the best way to accomplish this was by creating an instance of obj_hitbox, modify the value, and pass that instance to the sequence_instance_override_object function. It ends up looking like this:
GML:
function hitboxCreate(seq,owner){
       
            _seq = seq;
            _seq.playbackMode=seqplay_oneshot;
            _seqLayer="seqLayer"
            var inst = instance_create_layer(x,y,_seqLayer, obj_hitbox);
            inst.ownerId=100;
            sprite_index = spr_StickmanBasicPunch;
            image_index=0
            _myseq = layer_sequence_create(_seqLayer,x,y,_seq)
            _struct = layer_sequence_get_instance(_myseq)
            sequence_instance_override_object(_struct, obj_placeholder, inst);
}
Upon running this version of the function, this happens: https://giphy.com/gifs/HQPyBABYw6qq1avuYa
As you can see, the instance blinks in and out of existence for some reason, and the sequence has been reduced to a single frame. I am unsure of why this is happening, but as far as I can tell in the manual, I should be able to use instances of objects in the override. Am I misunderstanding how it's supposed to work?
Also through my testing, there seems to be a permanently existing hitbox object in the game (my guess the new instance of the hitbox which disappears), but how to get rid of it I am unsure.

To get around the sequence limitations, I used an approach where the in-sequence objects would be inert "spawner" objects that would create the actual instance using alarms (which would then be separate from the sequence and unbound to it), would that be an option? (It was extra appropriate for my case since I specifically wanted every enemy spawner to create a random enemy, but it would work just fine with an 1:1 relationship too)
I think that this would probably be a good option for me as well, but my only issue is figuring out a way to pass the values to the newly created hitbox beyond creating an instance that the hitbox would need to look for and modify.

Thanks for your replies guys! I hope I was able to explain my issues a bit better. I really appreciate the help!
 
Top