delayedCall with parameter

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
User avatar
Jouki
Posts: 127
Joined: Fri Oct 24, 2014 12:57 pm

delayedCall with parameter

Post 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"
NutJob
Posts: 426
Joined: Sun Oct 19, 2014 6:35 pm

Re: delayedCall with parameter

Post 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.
User avatar
JKos
Posts: 464
Joined: Wed Sep 12, 2012 10:03 pm
Location: Finland
Contact:

Re: delayedCall with parameter

Post 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
- LoG Framework 2http://sites.google.com/site/jkoslog2 Define hooks in runtime by entity.name or entity.id + multiple hooks support.
- cloneObject viewtopic.php?f=22&t=8450
User avatar
Jouki
Posts: 127
Joined: Fri Oct 24, 2014 12:57 pm

Re: delayedCall with parameter

Post 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
Last edited by Jouki on Fri Nov 07, 2014 1:44 am, edited 1 time in total.
minmay
Posts: 2780
Joined: Mon Sep 23, 2013 2:24 am

Re: delayedCall with parameter

Post by minmay »

In case this needs mentioning, remember to only pass serializable values to JKos' script if you use it.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
NutJob
Posts: 426
Joined: Sun Oct 19, 2014 6:35 pm

Re: delayedCall with parameter

Post 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~
User avatar
Jouki
Posts: 127
Joined: Fri Oct 24, 2014 12:57 pm

Re: delayedCall with parameter

Post by Jouki »

I'd say I'm darp from that. can you show up how the code in practice?
Image
User avatar
petri
Posts: 1917
Joined: Thu Mar 01, 2012 4:58 pm
Location: Finland

Re: delayedCall with parameter

Post by petri »

I've added support for arbitrary number of optional args to delayedCall in 2.1.16.
User avatar
Jouki
Posts: 127
Joined: Fri Oct 24, 2014 12:57 pm

Re: delayedCall with parameter

Post by Jouki »

petri wrote:I've added support for arbitrary number of optional args to delayedCall in 2.1.16.
ImageImageImage
User avatar
Aisuu
Posts: 61
Joined: Fri Oct 31, 2014 2:07 pm

Re: delayedCall with parameter

Post 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...
Post Reply