in my project there is a room called ( competition room ) in which users can join it to do some competitions
when one user join alone he first has to wait in ( waiting screen for another users to start the room with them)
the maximum number of users that can join to the same room is 4
when one user join the room alone, he has to wait for at least another one to join with him and when there is another one join him, there is a counter (timer) that starts from 15 to 0 ( to wait if there will be another users to join them or not, as I said before the maximum number is 4) I have made it by using (set interval and clear interval )
So if one user join the room alone, he waits for another one.
when another one join him in the same room, The counter starts from 15 to 0
if 3rd and 4th users join them before the end of the counter, they will take the same counter ( there is no counter created if there is already one) so if 3rd user for example join them when there is only 7 seconds he will start with them from 7 not 15
I hope it's clear
All of that works correctly but there is only on problem which occurs rarely but it occurs
when one user join the room alone, and then another 2 users join to him ( at the same millisecond ) there are 2 timers start because the the 2nd user and 3rd user join the room at the same millisceond
I have noticed that by using
Code: Select all
trace(params.countDown)
The problem is when it become 0 in the both timers there is only one timer become destroyed by clear interval and the other one continue as -1, -2 ,-3, -4 .... and the users don't start the competitions even if them exit from the room and join again because the second timer which not destroyed still works unless I restart the server
My interpretation of the problem: that when the both players joined the first player at the same millisecond, the server deals with them as both are the 2nd player , so two counters are created
when this problem occur I have to restart the server to work again
How can I solve it? the problem is not from my code as I said it occurs only when 2 users join the same room at the same milliseconds which is very rarely I know but it occurs ( if there is difference 1 millisecond or more between the joining of 2nd and 3rd the problem doesn't occur )
I tried to repeat (clear interval) twice but it still destroy only one timer
So I need to make someone delay only for a 1 millisecond if he join at the millisecond with another one