Using multiple "playing offset of the sound on channel" in an OR statement?

Hello! I’ve been following this response from this thread to optimize my rhythm game’s coding: Making a rhythm game

I did the following based on what they said to spawn the notes at the right time:

(Some additional context: The first three variables are just there so I can eventually add more songs and difficulties to the main scene. The “is4K” variable is to define whether or not the player is using the default number of keys of the game, and is currently unused anywhere else in the project as 4 key mode is currently a very early WIP)

However, when I do a preview, the notes only spawn once, at the first offset specifically, and then stop spawning altogether despite the song still going forward. I guess this has something to do with Trigger Once but if it isn’t there notes will spawn like there’s no tomorrow ;_;

How should I do it? Any help would be appreciated ;v;

1 Like

I don’t know how familiar you are with arrays but a flexible option would be to create an array of the values and then use a counter to track which value to test against next.

I made a visual example to test the concept. You drag the arrow past the nodes to trigger the next value.

Try me: Drag the arrow and click the buttons
https://gd.games/keith_13579/scenic-feeling

Source: (click the green [code] button and [download zip] extract and open the JSON file
https://github.com/doug13579/Gdevelop-drag-trigger-notes

This uses the Array Tools extension to convert a string of numbers separated by commas into an array.
It uses 2 arrays, List holds the current values to test against. Songs is an array of songs or presets. Counter is used to decide which index to check against and Value is used for the for each child

This is the key part. It compares the X() to the index in the Counter variable, it then increases the Counter. You need to make sure the Counter isn’t higher than the last array index. Arrays start at 0 so if the array child count is 5 the last child or index is 4. Instead of checking the X(), you would check the offset and any other conditions and actions.

To create the List array, you split the string with the numbers separated by commas using the array named Songs and reset the counter. For my example I used a button object variable name ID to choose which child or index of the array to use.
image

A lot of the events are just for the visuals but I didn’t want to hear a song over and over again and I’m more of a visual person. I hope it demonstrates my concept. I also prefer to teach than to create projects.

All of the events

1 Like

Ooo got it! Thank you so much, it’s really appreciated c:

1 Like

You’re welcome. It was a fun concept. I never know the experience of the person who might read this. So, I always try to explain it as much as possible. I find arrays are also a concept a lot of people find difficult or simply haven’t used yet.

1 Like

I’ve got you, you want to spawn different notes, and you put all the timings in 1 single event, now, for each note you have to do an event:
°If song offset > noteSpawnTime1
-spawn note

°If song offset > noteSpawnTime2
-spawn note

And you go like this till you’ve put all notes

Btw, this is a my idea, if you wanna make more songs, TRUST ME, you aren’t going to code the chart all the way like this, cuz it’s a really hard work, if you have a good experience you can make a simple chart editor that stores all timings in a JSON, and than all you will need to put in the events is to load the chart.JSON.

I hope i helped, good luck!