# Simple Object timing script help

#### XD005

##### Member
Hello everyone, its been a while since I have made a serious game in GMS.
Anyway, I am currently working on a music game and I just need help with this timing script.

Instead of millisecond values, I am using tick values.A tick is just a unit derived from the BPM.
One tick is equal to BPM / 192. I have an equation I am using to create an object at a certain speed when it is appropriate.

This is the script I was using for millisecond values in an earlier build.
Code:
``````//Process the node creation
x1 = receptor_x + receptor_width/2 //the position the note is created
x2 = receptor_x + receptor_width_padding + receptor_width_center // the position of the target (say, 320)
sp = global.gem_speed; // speed of the note (say, 1)
t1 = global.NoteTimes[index] //the time that the note is created (global.note_times[global.current_note] in this case)
t2 = 0 //the time the note reaches to the target
t3 = 1000/room_speed; //This is the unit, converts the pixels to ticks
t2=((x2-x1)/sp*t3)/1000;``````
And then it would use the millisecond value of the song currently and compare that with the results of that but I want to use tick values instead. To get the current time in ticks, you can use this script.
//Get the current tick value
global.tick=((60/global.BPM)/global.tick_resolution)
global.tick=(global.song_position-global.offset) / global.tick;

Disregard the offset, that is for songs that don't start at 0 seconds. I would be so grateful for assistance in this matter.

#### Joe Ellis

##### Member
What do you need help with?

#### XD005

##### Member
What do you need help with?
I'm just trying to figure out what to put for t3 as it wouldnt be 1000/room_speed as we aren't using milliseconds, but ticks instead.
In essence, how do I convert the pixels to ticks in regards to the movement speed and fps. How long will it take for the object to reach a certain point in ticks instead of milliseconds?

#### Joe Ellis

##### Member
Ah I get what you mean now. Well think about game frames, there're only 60 per second, (1 / 60 = 0.01666) .
So if an object moves at 0.01666 per frame, it would take exactly one second to move 1 pixel.
So then you can divide the bpm by 60, then 60 again (3600) to get how many beats there are per frame.
Then if you wanted the object to move n pixels per beat, you would do:
move_speed = (bpm / 3600) * pixels_per_beat

ps. I worked this out right now while I was trying to answer the question, I hope it's right lol, but I can't promise anything. Also I don't know if it helps with what you're doing, but it might be a point in the right direction

#### XD005

##### Member
Ah I get what you mean now. Well think about game frames, there're only 60 per second, (1 / 60 = 0.01666) .
So if an object moves at 0.01666 per frame, it would take exactly one second to move 1 pixel.
So then you can divide the bpm by 60, then 60 again (3600) to get how many beats there are per frame.
Then if you wanted the object to move n pixels per beat, you would do:
move_speed = (bpm / 3600) * pixels_per_beat

ps. I worked this out right now while I was trying to answer the question, I hope it's right lol, but I can't promise anything. Also I don't know if it helps with what you're doing, but it might be a point in the right direction
Thank you so much. The notes don't move so I think my code somewhere is wrong. But this what I came up with...

This is what sets up the movement speed of the gems and BPM and tick resolution
Code:
``````global.BPM = 120;
global.tick_resolution = 192;
global.gem_speed = ((global.BPM / 60)/global.tick_resolution) / room_speed``````
//And this is the code that creates the notes
Code:
``````            //Process the node creation
x1 = receptor_x + receptor_width/2 //the position the note is created
x2 = receptor_x + receptor_width_padding + receptor_width_center // the position of the target (say, 320)
sp = global.gem_speed; // speed of the note (say, 1)
t1 = global.NoteTimes[index] //the time that the note is created (global.note_times[global.current_note] in this case)
t2 = 0 //the time the note reaches to the target
t3 = ((global.BPM/60)/room_speed)/global.tick_resolution; //This is the unit, converts the pixels to ticks

t2=((x2-x1)/sp*t3)/1000;

if (global.tick>=global.NoteTimes[index] - t2) { //Note time value is in ticks BPM/tick resolution

//Create the object and assign the instance variables
index_id = instance_create_layer(x1,receptor_y + receptor_width_center,"Gameplay_Foreground",obj_node);
with (index_id) {value=note_value; node_time=tick_millisecond;} //Pass the number value to the node
index+=1; //Increment the index variables

}``````
I'll keep looking at the code and see if I can figure it out though.

#### XD005

##### Member
Sorry to bump this topic but I don't understand your formula. If we are using BPM 120, and game is running at 60 FPS, tick resolution is 192... How are you getting 3600?

So to get Beats Per Second...
global.BPM / 60 = 2 BPS

To get beats per frame...
BPF = BPS/room_speed =

BPF / global.tick_resolution = ‭1.736111111111111e-4‬

This is how many ticks there are in a frame? Now how does this relate to room speed and the rest of the formula? Note times are also in ticks...

#### Joe Ellis

##### Member
It's just cus you divide by 60 to get beats per second, then divide by 60 again (room speed) to get beats per frame, so to shorten it, you divide it by (60 * 60). If the room speed isn't 60, you can just change it to 60 * room_speed instead. Then beats per frame will be: global.bpm / (60 * room_speed)

Then beats per frame can be used as a ratio that can be multiplied with the movement speed per beat, to reduce\convert it into the amount of pixels it needs to move per frame, in order to move at the chosen amount of pixels per beat.
Sorry if that still doesn't explain, I'm trying to think of a better way of explaining it..

I don't really understand the tick resolution though, how are you calculating it to be 192 at 120 bpm? I don't know what the formula is that gives this number

It might be simpler to not use ticks, but I'm not sure until I understand why they're used

Last edited:

#### XD005

##### Member
It's just cus you divide by 60 to get beats per second, then divide by 60 again (room speed) to get beats per frame, so to shorten it, you divide it by (60 * 60). If the room speed isn't 60, you can just change it to 60 * room_speed instead. Then beats per frame will be: global.bpm / (60 * room_speed)

Then beats per frame can be used as a ratio that can be multiplied with the movement speed per beat, to reduce\convert it into the amount of pixels it needs to move per frame, in order to move at the chosen amount of pixels per beat.
Sorry if that still doesn't explain, I'm trying to think of a better way of explaining it..

I don't really understand the tick resolution though, how are you calculating it to be 192 at 120 bpm? I don't know what the formula is that gives this number

It might be simpler to not use ticks, but I'm not sure until I understand why they're used
Yes the tick value is just the BPM divided by 192. Its just the unit of time that that the syncing engine I use works with.
I could convert them when it is loaded into memory and stored in the array. But gotcha, I think I understand.
So this would make movement speed be as follows...
global.gem_speed = ((global.BPM / (60 / room_speed))/global.tick_resolution) * 2

And we'll use 2 as a scrolling factor.
And so then t3 = 60/room_speed; should be what we change in the 1st formula. I'm sorry if I'm repeating myself or not being clear.
Math isn't my specialty. lol

Edit: Basically we use ticks because BPS is too big of a measurement, it needs to be something smaller.

Last edited:

#### Joe Ellis

##### Member
I think I'd given you a different formula to the one you need, I've read the code more and realized you want to work out how many ticks it will take for the object to reach it's target based on it's move speed?

For that the formula should be:
ticks_till_reach_target = pixels_from_target / pixels_per_tick

To get pixels_per_tick, you divide pixels_per_frame(move_speed) by ticks_per_frame.
To get ticks_per_frame you need to know how many ticks there are per second, then divide this by the amount of frames per second (the room speed)

So as one line it would be:

ticks_till_reach_target = (x2 - x1) / (move_speed / (ticks_per_second / room_speed))

I don't know if that's answered every problem you have, if there's anything else just ask