Delcaring functions.

Posted by Shigs on Mon 11 Aug 2008 12:04 PM — 3 posts, 16,786 views.

#0
Where should function declerations be placed, when making a plugin inorder to make them accessible, by all triggers/aliases/ etc.


In the script space? When is this script initiated, on installation? on running of the client?


Thanks
Shigs.
#1
Put your Lua script in the plugin's script space, yes. It will be accessible to all triggers, aliases, etc in that plugin. If you want scripts to be accessible to multiple plugins or worlds, put them in modules (similar to the included little sample/utility scripts) and use the "require" keyword to load them into your script space.

The script will execute when the plugin is loaded, so when you open the world.
Australia Forum Administrator #2
As part of the plugin installation (loading) the script is processed and thus any global declarations are processed. Then it calls OnPluginInstall, if present. However for that to work the function OnPluginInstall must already exist, so therefore executing all global declarations is the very first thing that happens.

See for yourself by putting a line like this at the bottom of the script part in a plugin:


Note ("Script reloading: ", os.date ("%c"))


When you see that, the plugin is loading its script. Note that you may not see that at world startup because plugins load before the main output window is initialized, and thus the message may disappear. You could try appending it to a notepad instead, which will always work.