I’m trying to make more accurate system for my rhythm game.
It should print out how accurate is hit when player hits the note.
I want system that can catch to miliseconds, what things should I use to make it?
Should I use tick() to check accuracy?
Yes tick() will work for this kind of system, tick() returns a number, which is how much time has passed in seconds since some predefined point in time.
You’ll want to keep track of when the beat goes off, and when the beat was responded to.
You can do math.abs(Response-Beat)
to get the exact time difference between the two
--math.abs() returns the absolute value of whatever you put in (so making the number positive no matter what)
--Response would be the tick() time when the beat is responded to
--Beat would be the tick() time when the beat goes off
lets say Response was 1, but the beat was on 2. 1 minus 2 equals -1, math.abs() would turn that into 1, thus telling you that there was a second difference.
Here is an example for how to use tick() in this kind of system.
--//The Function
function StartBeat(TimeTil) --TimeTil is a number
local Beat = tick()+TimeTil --Lets say TimeTil = 5, that means this would be 5 seconds in the future from when the function was called.
local Callback = function()
local Response = tick() --Gets the current point in time.
local Diff = math.abs(Response-Beat) --As discussed before, this gets the difference between the two times.
return Diff
end
return Callback --Returning the function above, so that can be called at any point in time.
end
--//Calling the function
local Respond = StartBeat(10) --Defining it in a variable because it returns a function, so Respond = a function.
task.wait(9) --Waiting nine seconds, task.wait() is a more preferable wait()
print(Respond()) --Calling the Respond function
task.wait(3) --Waiting three more seconds, twelve seconds should've now passed.
print(Respond()) --Calling it again, as there's nothing stopping you from calling it multiple times.
and console would look like
1
2
I hope this helps, and if there’s any confusion about this just ask.