Page 2 of 2

Re: delayedCall with parameter

Posted: Fri Nov 07, 2014 12:31 pm
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!

Re: delayedCall with parameter

Posted: Fri Nov 07, 2014 12:56 pm
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

Re: delayedCall with parameter

Posted: Fri Nov 07, 2014 1:08 pm
by Aisuu
Cool, super thx :D

Re: delayedCall with parameter

Posted: Fri Nov 07, 2014 4:26 pm
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.

Re: delayedCall with parameter

Posted: Fri Nov 07, 2014 4:28 pm
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. :)

Re: delayedCall with parameter

Posted: Fri Nov 07, 2014 4:47 pm
by JKos
Thanks a lot Petri, I guess it supports entities as agrs too? Not a big deal if not, but would be nice.

Re: delayedCall with parameter

Posted: Fri Nov 07, 2014 4:48 pm
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).

Re: delayedCall with parameter

Posted: Fri Nov 07, 2014 6:37 pm
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

Re: delayedCall with parameter

Posted: Fri Nov 07, 2014 10:21 pm
by Jouki
and can we know the syntax? please :P

Re: delayedCall with parameter

Posted: Fri Nov 07, 2014 11:19 pm
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).