SA-MP Forums Archive
Timer not alternating between TRUE/FALSE [REP++] - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Timer not alternating between TRUE/FALSE [REP++] (/showthread.php?tid=314773)



Timer not alternating between TRUE/FALSE [REP++] - Hoborific - 31.01.2012

pawn Код:
new Clock;


forward HUDTimer();
public HUDTimer()
{
    if(Clock == 1)
        {
        Clock = 0;
        for(new i=0; i>=MAX_PLAYERS,i++;)
            {
            if(IsPlayerConnected(i) )
                {
                if(IsSpawned[i] == 1)
                    {
                   
                    TextDrawShowForPlayer(i,HUDClockBlink);
                   
                    }
                }
            }
           
       
        }
    else
        {
        TextDrawHideForAll(HUDClockBlink);
        Clock = 1;
        }

}



Re: Timer not alternating between TRUE/FALSE [REP++] - Hoborific - 31.01.2012

pawn Код:
SetTimer("HUDTimer",1500,1);
OnGameModeInit


Because I can login, see the textdraw ( called onplayerspawn to show ), Watch it disappear and then never come back, I believe the timer works fine, or is just continuously looping the else.


Re: Timer not alternating between TRUE/FALSE [REP++] - Babul - 31.01.2012

i guess the missing return 1; was th most important addition
pawn Код:
forward HUDTimer();
public HUDTimer()
{
    Clock=1-Clock;
    switch(Clock)
    {
        case 0:
        {
            for(new i=0; i>=MAX_PLAYERS,i++;)
            {
                if(IsPlayerConnected(i))
                {
                    if(IsSpawned[i] == 1)
                    {
                        TextDrawShowForPlayer(i,HUDClockBlink);
                    }
                }
            }
        }
        case 1:
        {
            TextDrawHideForAll(HUDClockBlink);
        }
    }
    return 1;
}



Re: Timer not alternating between TRUE/FALSE [REP++] - Hoborific - 31.01.2012

Why use a switch for a boolean when the IF statement should work, and I humoured your return 1; theory with feeble optimistic hope, nothing changed or began working.

please clarify this too

pawn Код:
Clock=1-Clock;



Re: Timer not alternating between TRUE/FALSE [REP++] - Hoborific - 31.01.2012

I did change it to

pawn Код:
<=
but yeah I still can't see where I went wrong, could you give a foreach example?


Re: Timer not alternating between TRUE/FALSE [REP++] - CaHbKo - 31.01.2012

pawn Код:
for(new i; i !=/*or <= if you like*/ MAX_PLAYERS; i++)



Re: Timer not alternating between TRUE/FALSE [REP++] - Hoborific - 31.01.2012

What would be most efficient, foreach, while or for?


Re: Timer not alternating between TRUE/FALSE [REP++] - MP2 - 31.01.2012

foreach.