Page 1 of 1

Am i able to..

Posted: Sun Nov 15, 2009 3:00 am
by droppen
i want to run 2 instances of a script inside one lua file kind of like javascript does. Is this possible?

Code: Select all

 
function main()
	printf("\n\nInitializing..");

	function test()
	    while( not keyPressed(key.VK_F5) ) do

	        print("test1");
		rest(50);
	    end
 	end
	registerTimer("test", secondsToTimer(2), test);

	-- Main loop
	while( not keyPressed(key.VK_F5) ) do

	        print("test2");
		rest(50);
	end

end

main();
I would like to have to output look like this:

Code: Select all

Initializing..
test1
test2
test1
test2
test1
test2
test1
test2
test1
test2
BTW, I haven't been able to see any documentation of starMacro or registerTimer functions

Edit: maybe this belongs to the help & support section

Re: Am i able to..

Posted: Sun Nov 15, 2009 6:45 am
by Administrator
You should look at using coroutines to run two "threads" at the same time.

startMacro() and registerTimer() will be listed under library functions in the manual.