This is creating an infinite loop, Why?
#1

I realized after looking at samp wikipedia that my server was restarting and this was causing it, I checked by removing it and I can confirm, this is an infinite loop, but my knowledge does not understand it as far as to how it is. Can anyone explain how it is and how to fix it?

pawn Код:
public UpdateTime()
{
    new mins,hour,secs;
    new time = gettime(hour,mins,secs);
    SetWorldTime(hour+4);

    format(timestr,32,"%02d:%02d",hour, mins);
    TextDrawSetString(txtTimeDisp,timestr);
   

    new x= time;
    while(x != MAX_PLAYERS)
    {
        if(IsPlayerConnected(x) && GetPlayerState(x) != PLAYER_STATE_NONE)
        {
            SetPlayerTime(x,hour,mins);
         }
        if(mins == 0)
        {
            doPayDay(x);
        }
         x++;
    }
}
Reply
#2

How can you even do such a thing?
gettime returns 3 values which you compare to one value (MAX_PLAYERS)
This is like doing:
new pos;
pos = GetPlayerPos(playerid,x,y,z);
new i = pos;
while(pos != 0)

Pos has 3 values which you cannot compare to one.
It will never be equal to MAX_PLAYERS therefore the infinite loop.
Reply
#3

Ahh, I think that was unintended...thanks.
Reply
#4

Quote:
Originally Posted by [XST]O_x
Посмотреть сообщение
How can you even do such a thing?
gettime returns 3 values which you compare to one value (MAX_PLAYERS)
This is like doing:
new pos;
pos = GetPlayerPos(playerid,x,y,z);
new i = pos;
while(pos != 0)

Pos has 3 values which you cannot compare to one.
It will never be equal to MAX_PLAYERS therefore the infinite loop.
No it does not return three values, it returns a single unix timestamp value which is way bigger than the max ammount of players samp will ever get, aswell modificates the three parameters you input on the function outside it, but its an integer function, and GetPlayerPos doesnt return a value, so in your example you store the value of void function on an integer, which makes no sense.
Reply
#5

Quote:
Originally Posted by kirk
Посмотреть сообщение
No it does not return three values, it returns a single unix timestamp value which is way bigger than the max ammount of players samp will ever get, aswell modificates the three parameters you input on the function outside it, but its an integer function, and GetPlayerPos doesnt return a value, so in your example you store the value of void function on an integer, which makes no sense.
Aha.
Thanks for making me feel better about not using gettime.
Reply
#6

Quote:
Originally Posted by [XST]O_x
Посмотреть сообщение
Aha.
Thanks for making me feel better about not using gettime.
No, i didnt meant you shouldnt use it, but ofcourse as you alredy told him as a player index it can not be used, he was looping over inexistent players even if it was a loop of the players playing at the same time in the whole SA:MP mod.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)