Timer not working
#1

Hi, I've just removed foreach because I decided to use GetPlayerPoolSize loops and now "Check" doesn't get called.
That:
Код:
public OnGameModeInit()
{
	SetTimer("Check", 1000, true);
}

forward Check();
public Check()
{
	print("Check called.");
}
It doesn't print anything. It literally stopped working after I removed foreach. What would be causing this problem? I tried using SetTimerEx with that although it's not needed, but it didn't work as well. All other timers are working. I know there's nothing wrong with the code, but does anyone know what would be causing that?
Reply
#2

I had the same issue in a script where the first timer never ran. I had to call an invalid timer, so the next timer (that being the first call of a timer despite the invalid timer) actually executed.

I don't know the source of this issue, but it definitely has something to do with some code in the script as it does works in a blank script.

I thought I was going crazy at one point, it was very frustrating xD
Reply
#3

Thanks man, it works now.
Instead of creating a new thread I'll just ask another question here:
what's the difference between two variables in a GetPlayerPoolSize loop (e.g i and j) instead of just one (e.g i)?
This is what wiki says: Note that we assign the return value to a new variable (j) to avoid calling the function with each iteration.
My English is not too good so I don't understand that.
Reply
#4

for(new i = 0, j = GetPlayerPoolSize(); i <= j; i ++) is what you should use. It stores the value retrieved by the function and stores it in a variable. The second part (after the first semicolon) is called every iteration (1, 2, 3, 4, etc.), so if you put the function in that part, it will execute the function and run the instructions of that function over and over (every iteration), which may slow down the loop.
Reply
#5

Quote:
Originally Posted by SickAttack
Посмотреть сообщение
for(new i = 0, j = GetPlayerPoolSize(); i <= j; i ++) is what you should use. It stores the value retrieved by the function and stores it in a variable. The second part (after the first semicolon) is called every iteration (1, 2, 3, 4, etc.), so if you put the function in that part, it will execute the function and run the instructions of that function over and over (every iteration), which may slow down the loop.
Alright, thank you.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)