break; or another way
#1

I'm doing a timer of 20 seconds, which will be repeated until seconds gets 1, and wont happen anymore since 0.
pawn Код:
new time = 20;
public counter()
{
    new string[3];
    time--;
    format(string,sizeof(string),"%d",time);
    GameTextForAll(string,1000,5);
    if(time == 0)
    {
        time = 20;
        break; // Says it's out of the context. This is the error.
    }
    else
    {
        SetTimer("counter",1000,false); // Will repeat until time be higher than 0
    }
    return 1;
}

I'm almost 100 % sure I'm not using break correctly, but I've used "continue" and "break" on other cases. Is there other way to kill this timer when the time variable gets 0?
Reply
#2

break; and continue; are supposed to be used in a loop statement. They are not used in this case, funnily enough it looks like your code should be working anyway? So why bother even adding break? You're calling the timer everytime it's not 0 already, so it's not going to keep getting called when it hits 0, but you're not using SetTimer when it's 0.
Reply
#3

Break would breaks the timer when time variable be 0. But I've found a better way for that:
pawn Код:
public counter()
{
    new string[3];
    time--;
    format(string,sizeof(string),"%d",time);
    GameTextForAll(string,1000,5);
    if(time > 0)
    {
        SetTimer("counter",1000,false);
    }
    else
    {
        SetTimer("voting",2000,false);
    }
    return 1;
}
thx at all.
Reply
#4

Quote:
Originally Posted by blackwave
Посмотреть сообщение
Break would breaks the timer when time variable be 0. But I've found a better way for that:
pawn Код:
public counter()
{
    new string[3];
    time--;
    format(string,sizeof(string),"%d",time);
    GameTextForAll(string,1000,5);
    if(time > 0)
    {
        SetTimer("counter",1000,false);
    }
    else
    {
        SetTimer("voting",2000,false);
    }
    return 1;
}
thx at all.
But you're not understanding actually, the timer isn't active when you are using break, so why would it break the timer? And like I said, this is not how break is used, it's used in loops. If you want to kill a timer that is actually active, you need to use a function like KillTimer, but again this isn't needed, since your timer isn't actually active when it hits 0.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)