how to get current timestamp in match_loop
? (consistent and relative to receive_time_ms
)
i’m lack of ideas. could someone help me with this please?
Hello @skullptr, you can keep track of time by using the current match tick and knowing the match tick rate to calculate elapsed seconds, you can then use this to calculate current time if needed.
hi @sesposito !
yes, this is what comes to mind first, but messages in match_loop
has milliseconds precision:
time.Now().UTC().UnixNano() / int64(time.Millisecond)
how you can precisely calculate the position for example, if you don’t know the very first timestamp for match_loop
? Timestamp for next tick you can calculate easily then obviously, if you know the very first.
You can store a timestamp with the match creation time upon match creation.
An example of how to pass params to the match can be seen here.
Hope this helps.
yes, you can get the timestamp at match_create
, but just wondered is there a way to get very accurate ms timestamp right before match_loop
, because it could simplify the scripting.
Anyways, thanks for the help @sesposito . I “workarounded” it in a way which close to what you mentioned:
- For current (input.x,input.y) and
receive_time_ms
from player I add (1 /tick_rate
) * speed to (x, y); - In next
match_loop
if there is a new input from player, then we invalidate adding (1 /tick_rate
) * speed and overwrite (x, y) with (input.x, input.y).
Sorry for curved explanation, but idea is more or less there