Page 1 of 2

delayedCall with parameter

Posted: Thu Nov 06, 2014 11:03 pm
by Jouki
hello, I'd like send the parameter via delayed call, but idk how

Code: Select all

function theDelay(entity,name,time)
	delayedCall(self.go.id, time, name)
end
I need send the parameter "entity" to the function "name"

Re: delayedCall with parameter

Posted: Thu Nov 06, 2014 11:13 pm
by NutJob
Just pass what you need in a global variable and once your call from delayedCall has used it/completes get rid of that "passed" along variable.

Re: delayedCall with parameter

Posted: Fri Nov 07, 2014 12:24 am
by JKos
Here is a quick implementation of delayCall with arguments, I did this for LoG1 too so it wasn't too hard.

name this script to
delay

Code: Select all

timers = {}

function call(delay,method,args)
	local timer = spawn('timer',party.level,1,1,1,1)
	timers[timer.id] = {method,args}
	timer.timer:addConnector('onActivate',self.go.id,'execute')
	timer.timer:setTimerInterval(delay)
	timer.timer:setDisableSelf(true)
end

function execute(timer)
	local data = timers[timer.go.id]
	data[1](unpack(data[2]))
	cleanup(timer)
end

function cleanup(timer)
	timers[timer.go.id] = nil
	timer.go:destroy()
end
Usage example

Code: Select all

 
local callback = function(arg1,arg2,arg3)
 print(arg1,arg2,arg3)
end
delay.script.call(3,callback,{1,2,3})
arguments must be passed as an array

Re: delayedCall with parameter

Posted: Fri Nov 07, 2014 1:09 am
by Jouki
I should take a rest from modding for few days because It's getting hard for me to understand codes. :|

edit: I'll look at it tomorrow

Re: delayedCall with parameter

Posted: Fri Nov 07, 2014 1:14 am
by minmay
In case this needs mentioning, remember to only pass serializable values to JKos' script if you use it.

Re: delayedCall with parameter

Posted: Fri Nov 07, 2014 1:29 am
by NutJob
That is a lot more functional then the delayedCall we have, JKos. Once again you have caused me to rework what I already have. ~laughs~

Re: delayedCall with parameter

Posted: Fri Nov 07, 2014 10:36 am
by Jouki
I'd say I'm darp from that. can you show up how the code in practice?
Image

Re: delayedCall with parameter

Posted: Fri Nov 07, 2014 10:58 am
by petri
I've added support for arbitrary number of optional args to delayedCall in 2.1.16.

Re: delayedCall with parameter

Posted: Fri Nov 07, 2014 11:10 am
by Jouki
petri wrote:I've added support for arbitrary number of optional args to delayedCall in 2.1.16.
ImageImageImage

Re: delayedCall with parameter

Posted: Fri Nov 07, 2014 11:51 am
by Aisuu
petri wrote:I've added support for arbitrary number of optional args to delayedCall in 2.1.16.
Can anyone explain me what does this mean, please? Iam using dalayedCall in my mod now...