[SOLVED] Dynamic Timelines

Samuel Venable

Time Killer
This is the first time I recall the need to dynamically create a timeline in GameMaker: Studio.

The problem is I want to create at random moments a new instance (with 55 * room_speed as the max), but instead of creating them all at different moments, they are all created at moment (step) zero simultaneously.

Code:
// Create Event

tl=timeline_add();

for (i=0; i<=50; i+=1) {

    random_x[i]=random_range(256,room_width-256);
    random_time[i]=round(random(55 * room_speed));
    timeline_moment_add_script(tl,random_time[i],
    instance_create(random_x[i],0,obj_Ball));

}

// Global Mouse Left Pressed

for (i=0; i<=50; i+=1) {
   
    // this demonstrates the 50 different values are indeed random and not all zeros.
    show_message(random_time[i])

}
Can someone please explain what I am doing wrong here?
Also, are dynamic timelines still officially supported?
I received no error stating use of obsolete functions.

Thanks
 

Mick

Member
The instance_create code needs to be in a script and you set the script index (name) in the timeline_moment_add_script function.
 

TheouAegis

Member
Broken on most platforms. Works on HTML5.
An alternative workaround is to use a data structure such as a map or grid that stores the time indexes and the scripts to run. Then use a counter that increases each step. Find any and all times that counter is indexed in the data structure and execute the code(s) assigned to that point.
 

Samuel Venable

Time Killer
@WitchMaster I actually tried that before posting this thread and with the same result.

@TheouAegis do you know if anyone has reported this to the tracker? If not, I'll gladly post a ticket. I've never used data structures before, but I'll check it out. Thanks for the recommendation!
 
S

sir_meowzalot

Guest
@TheouAegis I created this account to thank you for your map idea. It works perfectly for me. Thank you!
 
Top