Calling a timer inside a timer.
#1

Hey, So basically I wanna make an infinite timer without making the repeat to true, So inside the timer's code... I'd like to check if a certain condition is true.. and not SetTimerEx the same function again inside it.

However, That crashed the server.
Is there any way or any fix that allows me to that, Thanks in advance.

And if you don't get me, here is example:
PHP код:
new bool:certainCondition false;
public 
OnPlayerConnect(playerid)
{
    
SetTimerEx("FUNC"10000"d"playerid);
{
forward FUNC(playerid);
public 
FUNC(playerid)
{
    if(!
certainCondition) return SetTimerEx("FUNC"10000"d"playerid); //This cause crash.
    
else {
        
//code here
    
}

Reply
#2

Make two publics with same content, example:
PHP код:
public OnPlayerConnect(playerid)
{
        
SetTimerEx("FUNC"10000"d"playerid);
        return 
1;
}


forward FUNC(playerid);
public 
FUNC(playerid)
{
       if(!
certainCondition) return SetTimerEx("FUNC_2"10000"d"playerid); //timer for FNC_2
       
else {
          
//code here
       
}
       return 
1;


forward FUNC_2(playerid);
public 
FUNC_2(playerid)
{
       if(!
certainCondition) return SetTimerEx("FUNC"10000"d"playerid); //timer for FNC
       
else {
          
//code here
       
}
       return 
1;

Reply
#3

Quote:
Originally Posted by BroZeus
Посмотреть сообщение
Make two publics with same content, example:
PHP код:
public OnPlayerConnect(playerid)
{
        
SetTimerEx("FUNC"10000"d"playerid);
        return 
1;
}
forward FUNC(playerid);
public 
FUNC(playerid)
{
       if(!
certainCondition) return SetTimerEx("FUNC_2"10000"d"playerid); //timer for FNC_2
       
else {
          
//code here
       
}
       return 
1;

forward FUNC_2(playerid);
public 
FUNC_2(playerid)
{
       if(!
certainCondition) return SetTimerEx("FUNC"10000"d"playerid); //timer for FNC
       
else {
          
//code here
       
}
       return 
1;

That can be called upto 10 times.
That won't be a good way...
Reply
#4

What are you trying to do? It'd be easier if we know so we can help you. The code you gave gives me the direction but I don't understand why not setting the timer to be repetitive.
Reply
#5

I am creating a command that shows messages in a queue after a certain timer. (A textdraw)
So instead of creating an enum which will contain the queue details.

I will create a command that will trigger a timer with the info and than the timer will check if there is no any textdraws shown, And if not, It will show the textdraw and than return one without calling itself and if there is one shown, It will call itself again and keep doing these untill the screen is free for its turn.
Reply
#6

You can do something like this:
pawn Код:
#define DELAY 5 //The delay between each textdraw

new Text: myTextdraws[7];
new textCounter[MAX_PLAYERS] = 0;
new timer[MAX_PLAYERS];

forward FUNC(playerid);

public OnPlayerConnect(playerid)
{
    textCounter[playerid] = 0;
    timer[playerid] = SetTimerEx("FUNC", DELAY*1000, 0, "d", playerid);
    return 1;
}

public FUNC(playerid)
{
    TextDrawShowForPlayer(playerid, myTextdraws[textCounter[playerid]]);
    textCounter[playerid]++;
    if(textCounter[playerid] == 7) KillTimer(timer[playerid]);
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)