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

Get instance IDs of objects/use creation code in sequences?

TomOmNom

Member
So essentially I'm making a fighting game and I thought it would be a great idea to visualize the hitboxes, hurtboxes, and animations through sequences to make them much easier to work with. I have an animation set up with hurtbox instances and hitbox instances, but I can't find a way to assign these instances to the player if there are multiple players in game without making an individual object for each hitbox and hurtbox. I also want to add a further layer of customization with knockback, damage, and angles, and this would get unbelievably tedious if I had to make a new object with relative variables for each one.

TL;DR: Can I add custom code to object instances in sequences, similar to the Creation Code in the room editor? Otherwise what would be the best solution?
 
I'm not sure If I understand what you're looking for but here is the solution I think you want.

Have the object that needs the hitbox create the hitbox object and then store its ID in a variable of the object it just created.

Like this psudocode
GML:
inst = instance_create(hitbox)

inst.masterObject = id
and then in the hitbox

GML:
x = masterObject.x
y = masterObject.y
is this what you were looking for?
 

TailBit

Member
okay, that was a lot of reading .. but the objects you create in the sequence editor isn't "real" .. they are just a structure version of them that is put on the layer to be drawn .. buuuuuut .. you can get their ID

So .. I made the layer "Sequence1" and drew Object2 and Object3 there .. but Object3 just for a short amount

GML:
// first the normal part .. create it and start playing
seq = layer_sequence_create("Instances",0,0,Sequence1);
layer_sequence_play(seq);

// The structure have a lot of things you could check, and its active tracks isn't available to check upon creation ..
// so instead I took and checked the structure of the Sequence1
struct = layer_sequence_get_sequence(seq);

var t = struct.tracks;

// one of the tracks should have the name Object3, find it and store its index position in a variable
for(var i = 0;i< array_length(t);i++){
    if t[i].name == object_get_name(Object3) {
        obj_pos = i;
        break;
    }
}
in the draw/step event I can then get the instance of the sequence and actually try find the instance
GML:
var s = layer_sequence_get_instance(seq);
var ins = s.activeTracks[obj_pos]; // using the position from earlier

if (ins.instanceID > 0){ // if it is currently visible
    draw_line(mouse_x,mouse_y,ins.posx-s.sequence.xorigin, ins.posy-s.sequence.yorigin) 
}
You can change ins.posx and some other stuff with this

.. but .. you might want to get more familiar with the sequence structs so you can work your way around them yourself .. build some functions to list the variable_struct_ stuff.. that helped me a lot with this digging.

show_debug_message(ins) above the draw line should display all of its values, there are also the struct information links at the bottom of the sequence page of the manual that list a lot of it.

I'm gonna cool down my head now xD

EDIT: I found out that some was using "with" to call the instances in the sequence so I kept digging for a better way .. you have to create normal instances and overwrite the struct instances in the sequence .. that way you will have an instance id from the object that you can use just like @PhallicSpleen did above, here .. video:
 
Last edited:
Top