onCampaignLoad

From RPTools Wiki
Revision as of 15:23, 31 March 2018 by Phergus (talk | contribs) (Added warning about the use of certain functions within onCampaignLoad plus example code for making deferred function calls.)
Jump to navigation Jump to search

onCampaignLoad Macro

• Introduced in version 1.3b51

A special macro that can be created on library tokens to have macro code automatically execute when a campaign is loaded. A campaign is considered to have been loaded if it is opened via the File menu, or upon connecting to a server running that campaign. All output from onCampaignLoad() is discarded, when it is executed automatically. This special macro is ideally suited for loading your defined functions via defineFunction().

When onCampaignLoad() is executed automatically, it is considered a Trusted Macro. If you wish to use trusted functions within onCampaignLoad() and execute it manually (e.g. while developing macros), you will have to make sure that it follows all of the rules of Trusted Macros.

How to Create an onCampaignLoad Macro

You can create an onCampaignLoad() macro on any library token; simply create a macro that is specifically named onCampaignLoad.

Limitations

  • Do not make changes within the onCampaignLoad() macro to the library token it resides upon. This is not supported by MapTool. A duplicate lib token can/will appear and this will/can break stuff.
  • Some macro functions may not work as expected if run in onCampaignLoad without deferring their execution by using the defer option of execLink().

Example of Deferred Function Calls

Inside onCampaignLoad() macro place code like this:

[h: link = macroLinkText("deferredCalls@"+getMacroLocation())]
[h: execLink(link,1)]

And in the deferredCalls() macro place the functions to be deferred.

[h: goto("2")]
[h: setZoom(2)]