[SOLVED] Triggering multiple timelines simultaneously. Is this possible?

I'm working on a project where I have 8 separate timelines. Each one is generated dynamically with its moments or timestamps indicated by timestamps in an array. Each timelines triggers a different version of the script.

Timeline 1 - Script 1
Timeline 2 - Script 2 etc.

Each of those scripts is pretty much identical except that they trigger different objects moving in different locations. Due to the number of different timestamps in each array (hundreds) it's much cleaner to keep them all separated.

If I run each timeline individually then everything works perfectly. But if I try and trigger all 8 at the same time then only the first one triggered actually works.

Is it possible to run multiple timelines simultaneously and if so how do I go about doing this?

I've tried creating a different game object for each one and triggering them simultaneously but only the first one activates.

The code I've tried is the following but for all 8 of my timelines in a step event.
Code:
timeline_index = global.tml_dynamic1;
timeline_running = true;
timeline_position =  0;

timeline_index = global.tml_dynamic2;
timeline_running = true;
timeline_position =  0;

timeline_index = global.tml_dynamic3;
timeline_running = true;
timeline_position =  0;
 

TheouAegis

Member
You'd have to have different game objects all created at the start of the game/room. The way timelines are handled in GM is:

unknown_variable += timeline_speed;
if floor(unknown_variable) != timeline_position
{ execute_timeline_moment(); timeline_position++; }

Since you cannot access that unknown variable, there's no way to "reset" the counter multiple times within the same step.
Alternatively, since they're calling scripts, don't use a timeline and instead just call the scripts directly.
 

FrostyCat

Member
Or you can spawn worker instances to run the timelines for you. This is a pattern that gets neglected a lot in mainstream GM coding ideology (which seems to place too much weight in keeping everything in one place).

Create an invisible object called obj_worker with the following events:

Create
Code:
subject = noone;
Step:
Code:
if (!instance_exists(subject)) instance_destroy();
Then you can do the following to run timelines in parallel:
Code:
with (instance_create(0, 0, obj_worker)) {
  subject = other.id;
  timeline_index = global.tml_dynamic1;
  timeline_running = true;
  timeline_position =  0;
}
The only catch is that you now need to wrap everything in your timelines in with (subject) { ... }.
 
Last edited:
You'd have to have different game objects all created at the start of the game/room. The way timelines are handled in GM is:

unknown_variable += timeline_speed;
if floor(unknown_variable) != timeline_position
{ execute_timeline_moment(); timeline_position++; }

Since you cannot access that unknown variable, there's no way to "reset" the counter multiple times within the same step.
Alternatively, since they're calling scripts, don't use a timeline and instead just call the scripts directly.
I'm using timelines because I specifically need to to trigger instance_create() at specific time intervals.
 
Or you can spawn worker instances to run the timelines for you. This is a pattern that gets neglected a lot in mainstream GM coding ideology (which seems to place too much weight in keeping everything in one place).
This was what I thought I'd already done but a toggle switch that changes from on to off after the first timeline triggered is what stopped the other timelines from triggering.

So yeah, simply creating a series of multiple hidden objects that listened out for a button press seemed to work a treat. Here's what I used in the end that works without needing to use a create event. I simply created a global variable for each timeline in my initialisation script called global.timeline1_playing which can be set to NO or YES. Initially it's set to NO but once activated is set to YES. This is simple to stop multiple further timelines being created by additional button presses.

Thanks Frosty.

Code:
if (gamepad_button_check_pressed(0,gp_face1))
{ 
    if (global.timeline1_playing == "NO")
    {
        timeline_index = global.tml_dynamic1;
        timeline_running = true;
        timeline_position =  0;
        global.timeline1_playing = "YES";
    }
}
 
Top