I'm building a module to add tokens to the initiative panel. I am using code from Toy Robot's toolbar macros as the basis.
Essentially, there is a campaign macro that builds a dialog to take in initiative rolls. It then sends the list of tokens and the corresponding initiative values to a macro on Lib:Initiative which is supposed to parse out the values, add the tokens to the initiative panel, and sort the tokens.
The first macro seems to work just fine. The second macro - the one that is actually adding the tokens to the initiative panel - has a FOREACH loop to go through each of the selected tokens. It seems to start out fine, but it seems to break if there are tokens with a space in the name. It crashes out of the loop and the rest of the macro stops. I'd appreciate another set of eyes running over this.
Here is the code for the dialog set up:
Spoiler
Code: Select all
[h: tableText = ""]
[h: addList = getSelectedNames("%%")]
[h, FOREACH(creature, addList, "","%%" ): tableText= tableText
+ strformat("<tr><td align=right>%s</td><td><input type=text size=5 name='%s' value='%s'></td></tr>",
creature,
creature,
"1d20+"+getProperty("Initiative", creature)
)]
[DIALOG("Add to Initiative", "input=1; height=300; width=250; temporary=1"):{
<html>
<body>
<form method=get action='[r: macroLinkText("Roll Initiative@Lib:Initiative", "None", encode(addList)+"," )]'>
<center>
<table>
<tr><td colspan=2><center><b>Enter initiative scores or dice notation.</b></center></td></tr>
[r: tableText]
</table>
<br>
<input type=submit value=Add>
</center>
</form>
</body>
</html>
}]
Spoiler
Code: Select all
[h: tokenNamesList = decode( listGet(macro.args, 0) )]
[h: initArgs = listGet(macro.args, 1)]
[h, foreach(Token, tokenNamesList,"","%%"), CODE:
{
[h: switchToken(Token)]
[h: InitMod = getProperty("Initiative")*0.01]
[h: UncannyDodge = getProperty("UncannyDodge")]
[h: InitRoll = ( eval( string( getStrProp(initArgs, Token) ) ) )]
[h, if(UncannyDodge != 1): setState("FlatFooted",1)]
[h: addToInitiative()]
[h: setInitiative(InitRoll+InitMod)]
[h: deselectTokens()]
}]
[h: "/** The macro breaks somewhere around here. The rest of the macro is halted"]
[h: setInitiativeRound(1)]
[h: sortInitiative()]
[h: setCurrentInitiative(0)]
[h: activeCreature = getInitiativeToken()]
[h: setState("Active",1,activeCreature)]
[h: setState("FlatFooted",0,activeCreature)]
[h: goto(activeCreature)]