[Question] Checking what activated function

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!
Post Reply
User avatar
Blichew
Posts: 157
Joined: Thu Sep 27, 2012 12:39 am

[Question] Checking what activated function

Post by Blichew »

Hi there,

1. I have a few levers, let's call them lr_1 to lr_6
2. Each lever has onToggle hook to function called checkLever
3. Inside this function - how can I check which lever actually activated the function ?

Is that even possible ? I couldn't find any info in reference...

thanks in advance,
Blichew
GoldenShadowGS
Posts: 168
Joined: Thu Oct 30, 2014 1:56 am

Re: [Question] Checking what activated function

Post by GoldenShadowGS »

Here is how I would do this:

I would have each lever connect to two functions. One of them is your main function and another one is unique to each lever that just sets a boolean variable. Then you can find out if the boolean is true or false in your main function.
User avatar
Prozail
Posts: 158
Joined: Mon Oct 27, 2014 3:36 pm

Re: [Question] Checking what activated function

Post by Prozail »

Code: Select all

function checkLever(sender)
     print(sender.go.id)   -- this should print the name of the pulled lever. 
end
MrChoke
Posts: 324
Joined: Sat Oct 25, 2014 7:20 pm

Re: [Question] Checking what activated function

Post by MrChoke »

I believe the 1st parameter passed to an onToggle function is the object that triggered it.

So if you had something like:

Code: Select all

onToggle = function(obj) 
     print(obj.go.id)
end
I think you would see your leve's id printed. "onToggle" may pass a 2nd argument as well. The state of the lever, true or false.
User avatar
Blichew
Posts: 157
Joined: Thu Sep 27, 2012 12:39 am

Re: [Question] Checking what activated function

Post by Blichew »

That was fast, thank you :)

I've already started doing a workaround with separate function for each lever which sets a boolean var...
User avatar
Komag
Posts: 3658
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: [Question] Checking what activated function

Post by Komag »

much better to do it proper and read the parameter than to set up a bunch of unnecessary functions
Finished Dungeons - complete mods to play
Post Reply