Jump to content
  • 0

Sleep a source line


Question

Posted (edited)

Is any way I could delay some code? After I execute an instruction I want to execute another one in about 100ms (but leave the rest of the code go on).

 

I guess I could use the add_timer function, but it looks a bit complicated as it needs a timerFunc variable.

Edited by Mikado

7 answers to this question

Recommended Posts

Posted (edited)

sleep will also stop server running.

 

-

 

use add_timer or put your setting into somewhere timer (like sc, skill delay, pc loop...etc)

 

you can find some sample in core about how to use add_timer.

Edited by goddameit
Posted

DONT use "sleep" on the code you'll slow down all other thing. You'll have to understand how we deal with socket to get what I mean but best is to use the add timer wich will call your sub func at appopriate time.

nb : sleep and usleep are different on OS :

#ifdef WIN32
            Sleep(1000);
#else
            sleep(1);
#endif
Posted

So, as I need to use add_timer with a custom function, anybody can tell me how to use it properly? As it uses TimerFunc variables and I don't know how to pass variables through it.

Posted

let assum my_func = your custom finction.

 

1) Add my_func to timer_func_list :

add_timer_func_list(my_func, "my_func_name");

 

2) Ask a timered call :

x = 200; //suppose we wanna call it in 200ms

otherdata = 25<<16 |  10; //suppose we want to send 2 value 25 and 10

my_func->timer_id = add_timer(gettick() + x, my_func, bl->id, otherdata);

 

3)Function treatement : (exemple)

int my_func(int tid, unsigned int tick, int id, intptr_t data) {
 TBL_PC *sd=map_id2sd(id); //this assum bl was BL_PC (os you can have all info about sd)
 if(sd->sc.data[sC_ASSUMPTIO]) foo; //got assumptio do foo.

 if((data&0x00FF) <= 10) foo; //does my second value was 10 and below ? (eg yes (10))

 else if ((data&0xFF00) > 30) foo2; //does my 1st value was above 30 ? (eg no (25))
}

yes 3rd part may be more hard to understand but without utilisy of my_func I can't give better exemple. Hope rest was clear =)

  • Upvote 1

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...