PDA

View Full Version : Referencing tokeninstance objects



Wintermute
April 25th, 2018, 18:09
I was wondering if someone could point me in the right direction. I'm not new to programming, but I am new to lua.

I wanting to use two functions from tokeninstance, onActivation and setActive. I'm not sure how to reference the functions. Trying something like:

if setActive() == true then
Debug.console('setActive called')
end

This gives me a console error "Attempt to call global 'setActive' (a nil value)". Do I have to call it like tokeninstance.setActive()? Did I miss defining it as a global?

Thanks for any help.

Trenloe
April 25th, 2018, 18:53
These are two different types of functions - one is an event handler (onActivation) and one is a package function that you call.

See here for details of event handlers: https://www.fantasygrounds.com/wiki/index.php/Developer_Guide_-_Rulesets_-_Scripting#Using_Events

setActive() needs to be called with the token instance object - e.g. myTokenInstance.setActive(true);

Trenloe
April 25th, 2018, 18:56
I'd recommend you do a "find in files" (use a text editor that supports this) in the CoreRPG ruleset (extract CoreRPG.pak into a temporary location - not the FG "rulesets" directory).

Search for .setactive to find some examples of how to use this function.

Wintermute
April 25th, 2018, 19:21
I had searched the core ruleset for onActivation but not for setActive. A quick search did indeed answer most of my questions. Thanks Trenloe for pointing out the right direction. :)