How do you make Ordered Lists?

I’m working on a kind of ‘appified’ game where you can select from a list of exercises on the menu scene, and in the display scene you workout to them in the order they were selected. There is also a duration timer at the bottom of the menu screen where you choose the duration of each exercise (i.e. 15 sec, 30 sec, 60 sec). It should be possible to mix the ordering & durations as well (e.g. 15 sec pushups, 30 sec pullups, 45 sec pushups). My target is to have this on mobile (and also desktop) without requiring storage on a server. Saving the exercise sequence and titling it is also nice but not necessary.

Is the storage action sufficient, or is there some kind of global array or hash extension that I can push variables into? I was looking into the firebase actions, but preferably it’d just be on the device storage as it seems like overkill to have a database for it. What’s the easiest/best way to do this, or is it not possible?


GDevelop doesn’t really support arrays / lists, what most people do is create a structure where the keys are integers.
For ordering and sorting data I ended up writing java script blocks to do that work for me and put them into a private extension. That makes it fairly easy to call your custom action that reads all the data from one global structure and sorts it and puts it into another global structure.

Thanks for sharing the standard practice. Do you think custom Javascript would be necessary for my purposes, or would conditions/actions be enough? (I don’t really know JS).

I’ve set the Global Structure like so:

Workout Set
— ExerciseDuration → (e.g. 30)
— Numsets → (e.g. 2) [i.e. 60 seconds of Pushups]
— SetOrder → (e.g. 1) [i.e. 1st exercise in set]

The only thing is, SetOrder doesn’t give room for the 1st exercise being Pushups and also the 3rd, 4th, or 5th, etc. also being Pushups.

I was imagining with something like an array I’d just push each exercise into the array [Pushups[30], Situps[45], Pushups[30]]. Can I simulate this kind functionality with this kind of structure using actions/conditions, or is JS needed?

I believe what you are doing is possible using just structures, you’ll just need multiple structures, and multiple loops to be able to build an ordered set. There are no actions to sort or filter a structure like there are in JavaScript.

Here’s an idea:
Have a structure called “Routine” where the keys are just a number, and you keep track of the current number.
When the user selects an exercise then set the current number in Routine to store the name and duration:
Routine[0].name = pushups
Routine[0].duration = 60
Then increment the current number from 0 to 1 and repeat until then click done

To play back that routine you can use the “Loop on each child of a structure” that was recently added (or use a traditional loop with an index variable) and use the name to access the additional information in the “WorkoutSet” structure in combination with the duration the user selected.

It’s going to be complicated, but doable.
If you want the user to be able to modify the routine, you will need to create a temporary structure and brush up on computer science design patterns for sorting lists using loops… do they even teach that stuff anymore? Anyways, that’s why I’d just use javascript… but I totally understand that’s not a possibility for most of GDevelop’s audience.

1 Like

I am working on it, I am almost done. See the progress here:


It looks like the “For each child variable (of a structure)” loop is only for scene variables.
I’m going to try with the standard while loop. I don’t fully see how I’d bridge the “WorkoutSet” and “Routine” structures together but I’ll just bang my head against the keyboard with trial-and-error until it’s good enough.

I’m familiar with some of the terminology, but don’t have a background in CS. Would be nice to see some tutorials on JS with GDevelop.

I scoured the forum before posting here and saw one of your previous posts on this. Looking forward to it. I was working on a maze generation algorithm before this project but set it aside largely for this reason (no arrays). Most maze algorithms require organizing blocks into sets with lots of pushing and popping. I don’t think structures can do that.
So considering it’s two projects now where I’ve needed this, I think it’ll be very useful.