Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Topics - reaper

#1
I have created two threads, one each for addition and subtraction. I want them to run simultaneously, what are the possible ways for achieving concurrency?
function onScriptLoad()
{
local coro1 = newthread(add);
local coro2 = newthread(sub);
local addition=coro1.call(0);
local subtraction=coro2.call(50);
local i=1;
do
 {
 print("suspend passed ("+addition+")\n");
 print("suspend passed ("+subtraction+")\n");
 if(coro1.getstatus()=="suspended")
 addition= coro1.wakeup("Addition started "+i);
 if(coro2.getstatus()=="suspended")
 subtraction= coro2.wakeup("Subtraction started "+i);
 ++i;
 }while(coro1.getstatus()=="suspended"||coro2.getstatus()=="suspended");
}
x <- 0;
y <- 50;
function add(x)
{
 while(x<50)
 {
 x=x+5;
 print(x);
 if(x==25)
 local ret = suspend("addition suspended");
 }
}

function sub(y)
{
while(y>0)
 {
 y=y-5;
 print(y);
 if(y==25)
 local ret = suspend("subtraction suspended");
 }
}
#2
Help me to figure out how to generate a number or a vector every few seconds.  For example

1
// 2 sec delay
2
// 2 sec delay
3
// 2 sec delay

or

Vector( x, y, z) from database row 1
// 2 sec delay
Vector( x, y, z) from row 2
// 2 sec delay
Vector( x, y, z) from row 3
// so on


And how to create a delay function where after the time given by user the rest of the lines should execute. For Example

delay(time)
{

}

player.Health = 100;
delay(1000) // it should wait for 1 sec and then execute the next lines
print( Healed );
...

I am just learning from other scripts and snippets so please make sure to give me some example so that i can understand properly.