onCampaignLoad gotchas?

Discuss macro implementations, ask for macro help (to share your creations, see User Creations, probably either Campaign Frameworks or Drop-in Resources).

Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice

Post Reply
User avatar
Jagged
Great Wyrm
Posts: 1306
Joined: Mon Sep 15, 2008 9:27 am
Location: Bristol, UK

onCampaignLoad gotchas?

Post by Jagged »

My onCampaignLoad seems to have stopped working :(

Are there some gotchas I have missed? Its a trusted macro. Its in a token called "Lib:Components" that is visible to all. If I manually press the button, all works.
onCampaignLoad

Code: Select all

[defineFunction("transformData", "transformData@Lib:Components")]
[defineFunction("getCellData", "getCellData@Lib:Components")]
[defineFunction("getExpressData", "getExpressData@Lib:Components")]
[defineFunction("getShoverData", "getShoverData@Lib:Components")]
[defineFunction("getCrusherData", "getCrusherData@Lib:Components")]
[defineFunction("getPitData", "getPitData@Lib:Components")]
[defineFunction("getCheckpointData", "getCheckpointData@Lib:Components")]
[defineFunction("getBoardCellData", "getBoardCellData@Lib:Components")]
[defineFunction("getStartX", "getStartX@Lib:Components")]
[defineFunction("getStartY", "getStartY@Lib:Components")]
[defineFunction("getFirstFlag", "getFirstFlag@Lib:Components")]
[defineFunction("getLastFlag", "getLastFlag@Lib:Components")]
[defineFunction("isBotToBePositioned", "isBotToBePositioned@Lib:Components")]
[defineFunction("getActiveBoard", "getActiveBoard@Lib:Components")]
[defineFunction("conveyorMove", "conveyorMove@Lib:Components")]
[defineFunction("gearMove", "gearMove@Lib:Components")]
[defineFunction("movetokens", "movetokens@Lib:Components")]
[defineFunction("moveBotSquare", "moveBotSquare@Lib:Components")]
[defineFunction("backUpBotSquare", "backUpBotSquare@Lib:Components")]
[defineFunction("registerMove", "registerMove@Lib:Components")]
[defineFunction("collisionCheck", "collisionCheck@Lib:Components")]
[defineFunction("clearMove", "clearMove@Lib:Components")]
[defineFunction("conveyorCollision", "conveyorCollision@Lib:Components")]
[defineFunction("checkForBot", "checkForBot@Lib:Components")]
[defineFunction("convertFacing", "convertFacing@Lib:Components")]
[defineFunction("checkForPit", "checkForPit@Lib:Components")]
[defineFunction("checkBotWall", "checkBotWall@Lib:Components")]
[defineFunction("checkForWall", "checkForWall@Lib:Components")]
[defineFunction("getCardMove", "getCardMove@Lib:Components")]
[defineFunction("getCardHTML", "getCardHTML@Lib:Components")]
[defineFunction("getCardSelectHTML", "getCardSelectHTML@Lib:Components")]
[defineFunction("getRegisterHTML", "getRegisterHTML@Lib:Components")]
[defineFunction("getFacingHTML", "getFacingHTML@Lib:Components")]
[defineFunction("getProgrammeHTML", "getProgrammeHTML@Lib:Components")]
[defineFunction("getPowerDownHTML", "getPowerDownHTML@Lib:Components")]
[defineFunction("resurrectTheDead", "resurrectTheDead@Lib:Components")]
[defineFunction("dealCards", "dealCards@Lib:Components")]
[defineFunction("returnCards", "returnCards@Lib:Components")]
[defineFunction("Reset", "Reset@Lib:Components")]
[defineFunction("checkHoloStatus", "checkHoloStatus@Lib:Components")]
[defineFunction("arePCsReady", "arePCsReady@Lib:Components")]
[defineFunction("getRegisterText", "getRegisterText@Lib:Components")]
[defineFunction("GMControls", "GMControls@Lib:Components")]
[defineFunction("processGMControls", "processGMControls@Lib:Components")]
[defineFunction("Reg1", "Reg1@Lib:Components")]
[defineFunction("Reg2", "Reg2@Lib:Components")]
[defineFunction("Reg3", "Reg3@Lib:Components")]
[defineFunction("Reg4", "Reg4@Lib:Components")]
[defineFunction("Reg5", "Reg5@Lib:Components")]
[defineFunction("TurnEnd", "TurnEnd@Lib:Components")]
[defineFunction("Express", "Express@Lib:Components")]
[defineFunction("Conveyors", "Conveyors@Lib:Components")]
[defineFunction("Pushers", "Pushers@Lib:Components")]
[defineFunction("Gears", "Gears@Lib:Components")]
[defineFunction("Crushers", "Crushers@Lib:Components")]
[defineFunction("BoardLasers", "BoardLasers@Lib:Components")]
[defineFunction("Setup", "Setup@Lib:Components")]
[defineFunction("RepairPoints", "RepairPoints@Lib:Components")]
[defineFunction("ArchivePoints", "ArchivePoints@Lib:Components")]
[defineFunction("Checkpoints", "Checkpoints@Lib:Components")]
[defineFunction("deferMacro", "deferMacro@Lib:Components")]
Incidentally, B86 gives a much nicer error message that B90. B90 says, "Error in body of roll..." While B86 says "Undefined function ..."

User avatar
aliasmask
RPTools Team
Posts: 9031
Joined: Tue Nov 10, 2009 6:11 pm
Location: California

Re: onCampaignLoad gotchas?

Post by aliasmask »

Looks fine. I would just make sure the macro name uses the correct casing and is spelled correctly "onCampaignLoad". I've seen people put OnCampaignLoad before and have this problem (i think).

User avatar
Jagged
Great Wyrm
Posts: 1306
Joined: Mon Sep 15, 2008 9:27 am
Location: Bristol, UK

Re: onCampaignLoad gotchas?

Post by Jagged »

For the record, I copied the "onCampaignLoad" in the first post, from the macro button. :(

User avatar
aliasmask
RPTools Team
Posts: 9031
Joined: Tue Nov 10, 2009 6:11 pm
Location: California

Re: onCampaignLoad gotchas?

Post by aliasmask »

Do you have onCampaignLoad twice on lib token or perhaps there is a space after the name. Basically, if it's not running, then it's not seeing the macro for some reason. If it's not on the token layer, I would put it there as well. Using getInfo("client") will show the lib tokens and "user defined functions", but only if lib token is on the token layer.

If there is an error in the macro, perhaps defining a macro that doesn't exist, then it may error as well, but I'm not sure about that one.

This may be an overly complex way of doing it, but I put this on all my lib tokens:

Code: Select all

@@ @onCampaignLoad
@PROPS@ fontColor=yellow ; autoExecute=true ; fontSize=11pt ; sortBy=18 ; color=red ; playerEditable=false ; applyToSelected=false ; group=Init ; tooltip= ; minWidth=94 ; 
[H: '<!-- All functions will be given a UDF name excluding tags and special characters -->']
[H: prefix = "am.xx."]
[H: this = getMacroLocation()]

<!-- Here is a change -->

[H: '<!-- Macro names ending with .html will allow output. "local" also sets newScope to 0. -->']
[H: outputExtensions = json.append("","html","local","out","output","sub","css")]

[H: '<!-- Define functions here with options other than ignoreOutput = 1 and NewScope = 1 -->']

[H: '<!-- List functions names here to exclude from UDF definition -->']
[H: excludeList = json.append("","(new)")]
[H: tableFunctions = json.difference(getMacros("json"),excludeList)]

[H: '<!-- Define UDFs.  Already defined UDFs will not be redefined. -->']
[H, foreach(fn,tableFunctions), code: {
   [H: fName = replace(fn,"<[^>]*?>","")]
   [H: fName = replace(fName,"[^a-zA-Z0-9_.]","")]
   [H: cleanFN = strformat("%{prefix}%{fName}")]
   [H: extension = listGet(cleanFN,listCount(cleanFN,".")-1,".")]
   [H: newScope = 1 - listContains("local,sub",extension)]
   [H: ignoreOutput = 1 - json.contains(outputExtensions,extension)]
   [H: exclude = listContains("x",extension)]
   [H, if(! isFunctionDefined(cleanFN) && ! exclude): defineFunction(cleanFN,strformat("%{fn}@"+this),ignoreOutput,newScope)]
}]

!!
This suppresses all output, so you would need your own output macro using broadcast. My output macro is overly complicated as well, but you can glean some code from it:

Code: Select all

@@ @output.basic
@PROPS@ fontColor=black ; autoExecute=true ; fontSize=11pt ; sortBy=21 ; color=white ; playerEditable=false ; applyToSelected=false ; group=Chat ; tooltip= ; minWidth=94 ; 
[H: "<!-- output.basic(chatText[,targets[,tokenInfo]]) -->"]
[H: args = macro.args]
[H: chatText = json.get(args,0)]
[H, if(! json.isEmpty(chatText)), code: {
   [H: playerName = replace(getPlayerName(),'"',""")]
   [H, if(json.length(args) >= 3): tokenInfo = json.get(args,2);tokenInfo = "{}"]
   [H, if(json.type(tokenInfo) == "UNKNOWN" && ! json.isEmpty(tokenInfo)), code: {
      [H, token(tokenInfo), if(lower(tokenInfo) == "token"): id = currentToken();id = findToken(tokenInfo)]
      [H, if(! json.isEmpty(id)): tokenInfo = am.play.getTokenInfo(id)]
   };{}]
   [H, if(json.length(args) >= 2): targets = am.play.updateTargets(json.get(args,1),tokenInfo);targets = "[]"]
   [H, if(json.isEmpty(tokenInfo)), code: {
      [H: output = strformat('
         <table cellpadding="0">
            <tr>
               <td style="margin-right: 5px;font-weight:700;" valign="top">%{playerName}:</td>
               <td valign="top"><span>%{chatText}</span></td>
            </tr>
         </table>')]
   };{
      [H: am.play.jsonToVars(tokenInfo)]
      [H: output = strformat('
         <table cellpadding="0">
            <tr>
               <td width="40" style="padding-right: 5px" valign="top"><img src="%{tokenImage}-40" alt="%{playerName}" /></td>
               <td style="margin-right: 5px;font-weight:700;" valign="top">%{tokenName}:</td>
               <td valign="top"><span>%{chatText}</span></td>
            </tr>
         </table>')]
   }]
   [H, if(! json.isEmpty(targets)): am.play.output(output,targets)]
};{}]

!!
@@ @output
@PROPS@ fontColor=black ; autoExecute=true ; fontSize=11pt ; sortBy=21 ; color=white ; playerEditable=false ; applyToSelected=false ; group=Chat ; tooltip= ; minWidth=94 ; 
[H: output = arg(0)]
[H, if(argCount() >= 2),code: {
   [H, if(argCount() >= 3): tokenInfo = arg(2); tokenInfo = "{}"]
   [H: targets = am.play.updateTargets(arg(1),tokenInfo)]
   [H, if(! json.isEmpty(targets)): broadcast(output,targets,"json")]
};{
   [H: broadcast(output)]
}]

!!


User avatar
Jagged
Great Wyrm
Posts: 1306
Joined: Mon Sep 15, 2008 9:27 am
Location: Bristol, UK

Re: onCampaignLoad gotchas?

Post by Jagged »

wolph42 wrote:Oncampaignload won't run for:
Owned tokens
Aha! At some point the Lib token had acquired "All Players" for ownership. I probably accidentally clicked that instead of "Visible to Players" ;)

Cheers all.

Post Reply

Return to “Macros”