Reputation: 507
I am building a game wherein two users compete against the clock. Each player has 60 seconds to answer as many questions correctly as possible.
I have two potential approaches to time-keeping:
My question is this: would a client-side countdown be reasonably consistent between both clients?
If implemented client-side, it would be using setInterval()
in JavaScript.
Upvotes: 3
Views: 846
Reputation: 8769
Your real state should be held on the server while clients should try to sync (update thier state) depending on server response state. Basically, if user gets lag, he still loses his time, rather than blocking time. This also prevents client-side cheats by changing values.
So on each tick, your clients should know what is the real time from the server.
Upvotes: 2