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
JohnWordsworth
Posts: 1397
Joined: Fri Sep 14, 2012 4:19 pm
Location: Devon, United Kingdom
Contact:

Re: delayedCall with parameter

Post by JohnWordsworth »

@Aisuu: It means you will be able to do something like this...

Code: Select all

function doHudPrint(text)
  hudPrint(text)
end

function showDialogue()
  delayedCall(self.go.id, 5.0, "doHudPrint", "Hello Lowly Mortal.");
  delayedCall(self.go.id, 10.0, "doHudPrint", "I am going to speak to you using the HudPrint Method.");
  delayedCall(self.go.id, 15.0, "doHudPrint", "And these message will appear on the screen.");
  delayedCall(self.go.id, 20.0, "doHudPrint", "With 5 second gaps between them. All using one callback function.");
end

showDialogue();
Obviously, I've guessed at the syntax, but that's very useful - many thanks Petri!
My Grimrock Projects Page with links to the Grimrock Model Toolkit, GrimFBX, Atlas Toolkit, QuickBar, NoteBook and the Oriental Weapons Pack.
User avatar
Jouki
Posts: 127
Joined: Fri Oct 24, 2014 12:57 pm

Re: delayedCall with parameter

Post by Jouki »

Aisuu wrote:
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...
You call function but without any parameters, but why if you need send the name with that delay? (for example name, or whole entity)

I try write example:

Code: Select all

function WhichOne()
    
    if lever_1.lever:isActivated == true then
        delayedCall(self.go.id, 1, "activateDoor","door_1")
    else
        delayedCall(self.go.id, 1, "activateDoor,"door_2")
    end
end
and function activateDoor:

Code: Select all

function activateDoor(sender)
    if sender == "door_1" then mine_door_spear_1.door:open()
    elseif sender == "door_2" then mine_door_spear_2.door:open()
    end
end
(I hope I didn't forget on something while writing that)
I dont know the syntax how it's gonna be coded but there's example how it could work
User avatar
Aisuu
Posts: 61
Joined: Fri Oct 31, 2014 2:07 pm

Re: delayedCall with parameter

Post by Aisuu »

Cool, super thx :D
NutJob
Posts: 426
Joined: Sun Oct 19, 2014 6:35 pm

Re: delayedCall with parameter

Post by NutJob »

petri wrote:I've added support for arbitrary number of optional args to delayedCall in 2.1.16.
Bump, just because.

AND

Thank you, for still pouring your life energies into the game/community! I may be a nut job but I'm a thankful one.
User avatar
petri
Posts: 1917
Joined: Thu Mar 01, 2012 4:58 pm
Location: Finland

Re: delayedCall with parameter

Post by petri »

NutJob wrote:Thank you, for still pouring your life energies into the game/community! I may be a nut job but I'm a thankful one.
You're welcome! Pouring life energies sounds a little bit too necromantic for being so much fun but I get your point. :)
User avatar
JKos
Posts: 464
Joined: Wed Sep 12, 2012 10:03 pm
Location: Finland
Contact:

Re: delayedCall with parameter

Post by JKos »

Thanks a lot Petri, I guess it supports entities as agrs too? Not a big deal if not, but would be nice.
- 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
petri
Posts: 1917
Joined: Thu Mar 01, 2012 4:58 pm
Location: Finland

Re: delayedCall with parameter

Post by petri »

JKos wrote:Thanks a lot Petri, I guess it supports entities as agrs too? Not a big deal if not, but would be nice.
Only strings, numbers and booleans I'm afraid (these types are really efficient to serialize).
User avatar
Lark
Posts: 178
Joined: Wed Sep 19, 2012 4:23 pm
Location: Springfield, MO USA

Re: delayedCall with parameter

Post by Lark »

petri wrote:I've added support for arbitrary number of optional args to delayedCall in 2.1.16.
My hero! Yes, there are ways around it, but boy does it make the code nicer! It's no big deal not to support entities; this is really great and we all really appreciate you!!!

Sincere Gratitude! -Lark
User avatar
Jouki
Posts: 127
Joined: Fri Oct 24, 2014 12:57 pm

Re: delayedCall with parameter

Post by Jouki »

and can we know the syntax? please :P
NutJob
Posts: 426
Joined: Sun Oct 19, 2014 6:35 pm

Re: delayedCall with parameter

Post by NutJob »

Jouki wrote:and can we know the syntax? please :P
In the patch notes it's mentioned it's an arbitrary number so probably just add them to the end delayedCall(entity, time, function, arg1, arg2, ...) and arg1+ get sent as parameters to the function you're calling. Can't test ATM, just guessing right now.


EDIT: BTW confirmed, syntax

delayedCall(self.go.id, 3.4, "killAnObject", id)

killAnObject received the id as it's first/only parameter.

So, if your function has 5 parameters just keep adding each one (in order!) to the end of delayedCall (of course after delayedCall required parameters).
Post Reply