How to change the struct values of a sequence, dynamically at runtime?

gkri

Member
I tried to access the struct of a premade sequence from asset browser. I wanted to change the keyframe of a specific channel of a track. To be more specific I wanted to change the mouth of a character from neutral to smile.

After some looping and show_debug_message in create event, I found the value that refering to image_index of the mouth sprite:

seq_.tracks[2].tracks[4].keyframes[0].channels[0].value

But changing that value only have effect if I change it in create event. If I try to change it into step event, the change is ignored...

GML:
//create event

seq = layer_sequence_create(INSTANCES, xx, yy, seq_character);

seq_ = (layer_sequence_get_sequence(seq));


//If I put the next line of  code in create event the change applies

//but if I put the next line of  code in step event the change is ignored

seq_.tracks[2].tracks[4].keyframes[0].channels[0].value = 14;

// 0 is neutral mouth, 14 is smile

Can you help me and tell me what I am doing wrong?


My goal is eventually to dynamically create idle animations like smile, eyes blinking, for all my characters, without tediously overflowing the asset browsing with numerous sequences with very simple animations...
 
Did you find an answer to your problem?? I'm having a similar problem by trying to edit the colors of sprites inside a sequence

GML:
var seq_struct = sequence_get(seq_astro_selected_in).tracks;
var seq_length = array_length(seq_struct);

var cc = global.game_colors[? color_interface];
var color_red = color_get_red(cc)/255;
var color_green = color_get_green(cc)/255;
var color_blue = color_get_blue(cc)/255;
var color_array = [1, color_red, color_green, color_blue];

for(var s = 0 ; s < seq_length ; s++) {
    var seq = seq_struct[s];
    
    seq.tracks[4].keyframes[0].channels[0].color = color_array;
    seq.tracks[4].keyframes[0].channels[0].colour = color_array;
}
The problem is that it only functions at the start of the game, if I try to change the colors in game it doesnt work
 

gkri

Member
Unfortunately no. I also asked on reddit, I did not get an answer there, too. I did it the tedious way, creating every single sequence I need into asset tree...

@Gizmo199 wrote impressive code for sequences. Hopefully if he knows the way, will let us know the solution here...
 

Gizmo199

Member
Unfortunately no. I also asked on reddit, I did not get an answer there, too. I did it the tedious way, creating every single sequence I need into asset tree...

@Gizmo199 wrote impressive code for sequences. Hopefully if he knows the way, will let us know the solution here...
So what I would suggest (at least the attempt I am going to try and make at it) is to store the struct data in a separate data structure and call what I need from the structure instead. That way I can just alter the data structure instead of trying to alter the internal GM stuff. So maybe if you stored everything inside of a nested list/map/grid you could then have animations "play" by altering the positions, scales, colors, etc found in the data structure and loop through it. Just my thoughts. If I come up with a solution I will definitely post it somewhere!!! :D
 
So what I would suggest (at least the attempt I am going to try and make at it) is to store the struct data in a separate data structure and call what I need from the structure instead. That way I can just alter the data structure instead of trying to alter the internal GM stuff. So maybe if you stored everything inside of a nested list/map/grid you could then have animations "play" by altering the positions, scales, colors, etc found in the data structure and loop through it. Just my thoughts. If I come up with a solution I will definitely post it somewhere!!! :D
That sounds like interesting alternative. Just checked your 3SeqsD project, It's really cool, congratulations.

Other alternative I was considering (I think maybe there is too much too much work in it, but I'm still not sure, is to use objects instead of sprites. In that way you could use object.variable and modify the colors, the problem is that in my case, I will have 42 objects, just for gui purposes.
 

Gizmo199

Member
That sounds like interesting alternative. Just checked your 3SeqsD project, It's really cool, congratulations.

Other alternative I was considering (I think maybe there is too much too much work in it, but I'm still not sure, is to use objects instead of sprites. In that way you could use object.variable and modify the colors, the problem is that in my case, I will have 42 objects, just for gui purposes.
Thanks! :D Yeah you have to use objects in my 3SeqsD engine too. One thing you could do instead is to put the 42 objects in the sequence and replace the objects to get the variable data. Add all of the object data to a list/map and "record" the animation as well (positions, rotations, etc). Once that is done destroy the animation and all of the objects and just have a render object draw everything using the data instead of having the animation OR the objects. The downside is that you would need a "loading" phase when the animation is first created but essentially you could also run the animation, export it to a file when the game first loads up and if that file exists just retrieve the data.

Just some thoughts. Hope it helps!
 
Thanks! :D Yeah you have to use objects in my 3SeqsD engine too. One thing you could do instead is to put the 42 objects in the sequence and replace the objects to get the variable data. Add all of the object data to a list/map and "record" the animation as well (positions, rotations, etc). Once that is done destroy the animation and all of the objects and just have a render object draw everything using the data instead of having the animation OR the objects. The downside is that you would need a "loading" phase when the animation is first created but essentially you could also run the animation, export it to a file when the game first loads up and if that file exists just retrieve the data.

Just some thoughts. Hope it helps!
That sounds like an interesting alternative, I will certainly try to make that out. Thanks!
 
Top