GMS 2.3+ Timeline index out of order

I'm trying to make a tower defense game, and everything seems correct, but the waves go in the order 4-1-2-3 for some reason.

Waves folder:
wave folder.png

Create event:
GML:
image_speed = 0;
global.wave = 0;
running = false;
canclick = true;
Step event:
GML:
if timeline_position > timeline_max_moment(timeline_index) and instance_number(enemyparent) <= 1 {
    running = false;
    canclick = true;
    image_index = 0;
}
Left Pressed event:
Code:
if canclick == true {
    show_debug_message("started wave " + string(global.wave));
    canclick = false;
    running = true;
    global.wave += 1;
    timeline_index = global.wave;
    timeline_position = 0;
    timeline_running = true;
    image_index = 1;
}
 

TsukaYuriko

☄️
Forum Staff
Moderator
Timeline indices are not guaranteed to be sequential. You're assigning timelines via integers that may or may not refer to the timeline you want to refer to. Assign them via the actual timeline IDs.
 

TheouAegis

Member
Make an array and put in the array each of the timeline indexes. Then use global.wave to fetch the desired timeline from the array.
Code:
global.WavesList = [wave1,wave2,wave3,wave4];
Code:
...
timeline_index = global.WavesList[global.wave];
...
 
Top