Page 1 of 1
[Question] Checking what activated function
Posted: Sat Nov 01, 2014 12:57 am
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
Re: [Question] Checking what activated function
Posted: Sat Nov 01, 2014 1:09 am
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.
Re: [Question] Checking what activated function
Posted: Sat Nov 01, 2014 1:12 am
by Prozail
Code: Select all
function checkLever(sender)
print(sender.go.id) -- this should print the name of the pulled lever.
end
Re: [Question] Checking what activated function
Posted: Sat Nov 01, 2014 1:13 am
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.
Re: [Question] Checking what activated function
Posted: Sat Nov 01, 2014 1:23 am
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...
Re: [Question] Checking what activated function
Posted: Sat Nov 01, 2014 3:51 am
by Komag
much better to do it proper and read the parameter than to set up a bunch of unnecessary functions