Page 1 of 1

Macro Output Artifacts

Posted: Mon Sep 25, 2017 7:08 pm
by Templar
Hi,

I get some weird artifacts in my output for some of my macros.
We use our own custom system where Primary weapon, Secondary Weapon and Missile Weapon each have there own Init roll.
The Macros work perfectly but:

The first example below always has these 3 '' '' '' at the end of the output.

The second example works perfectly if its the Npcs init but if not it gets one ".
I would rather it produced no output at all.

Example 1
============================================================
[h:x=input(
"Weapon | Primary, Secondary, Missile, All | Pick the weapon for this Init Roll | RADIO | ORIENT=V SELECT=0"
)]
[h: abort(x)]
[if(Weapon == 0), Code:{

[h: PInit = initiative]
[h: Init = "{PInit}"]
<b>Primary Init set to: [r: PInit]</b> }]

[if(Weapon == 1), Code:{
[h: SInit = initiative]
[h: Init = "{SInit}"]
<b>Secondary Init set to: [r: SInit]</b> }]

[if(Weapon == 2), Code:{
[h: MInit = initiative]
[h: Init = "{MInit}"]
<b>Missile Init set to: [r: MInit]</b>}]

[if(Weapon == 3), Code:{
[h: PInit = initiative]
[h: SInit = PInit]
[h: MInit = PInit]
[h: Init = "{PInit}"]
<b>All Init set to: [r: PInit]</b>}]
-----------------------------------------------
Output looks like this:
Colin: Primary Init set to: 1 '' '' ''
=============================================================

Example 2
=============================================================

[h: CurrentToken = nextInitiative()]
[h: jsonInit = getInitiativeList()]
[h: AllTokenArray = json.get(jsonInit, "tokens")]
[h: Token_ID = json.get(json.get(AllTokenArray, CurrentToken), "tokenId")]
[h: CurrentTokenName = getName( Token_ID)]

[h: SelectedTokens = getSelectedNames()]
[h: deselectTokens(SelectedTokens, ",")]
[h: selectTokens(Token_ID, 1)]

[h: TokenInit = getProperty("Init", Token_ID)]
[h: WeaponSpeed = getProperty("PWeaponSpeed", Token_ID)]
[h: DBonus = getProperty("DexBonus", Token_ID)]

[h: WSpeed = TokenInit + WeaponSpeed]
[h: React = 9 - DBonus]
[h: InitRoll = eval("D" + React)]
[h: NewInit = WSpeed + InitRoll]
[h: CurrentCount = getInitiativeRound()]

[If(TokenInit == CurrentCount), CODE:{
[h: setProperty("PInit", NewInit, Token_ID)]
<b>Current Count: </b>[r: CurrentCount]<br>
<hr/>
<b>[r: CurrentTokenName]: Init = [r: TokenInit] GO-GO-GO</b><br>
<b>Recovery: </b>[r: WSpeed]<br>
<b>Reaction: </b>[r: React]<br>
<b>Init Roll: </b>[r: InitRoll]<br>
<b>New Initiative: </b>[r: NewInit]<br>
<hr/>
}]
-----------------------------------------------
Output looks like this:

Colin: ''
=============================================================

Re: Macro Output Artifacts

Posted: Mon Sep 25, 2017 7:26 pm
by jackolas
Your IF statement are not complete, they require an else. most simple is to add ;{} to the end of them
example 1

Code: Select all

[h:x=input(
"Weapon | Primary, Secondary, Missile, All | Pick the weapon for this Init Roll | RADIO | ORIENT=V SELECT=0"
)]
[h: abort(x)]
[if(Weapon == 0), Code:{

[h: PInit = initiative]
[h: Init = "{PInit}"]
<b>Primary Init set to: [r: PInit]</b> };{}]

[if(Weapon == 1), Code:{
[h: SInit = initiative]
[h: Init = "{SInit}"]
<b>Secondary Init set to: [r: SInit]</b> };{}]

[if(Weapon == 2), Code:{
[h: MInit = initiative]
[h: Init = "{MInit}"]
<b>Missile Init set to: [r: MInit]</b>};{}]

[if(Weapon == 3), Code:{
[h: PInit = initiative]
[h: SInit = PInit]
[h: MInit = PInit]
[h: Init = "{PInit}"]
<b>All Init set to: [r: PInit]</b>};{}]
Example 2

Code: Select all

[h: CurrentToken = nextInitiative()]
[h: jsonInit = getInitiativeList()]
[h: AllTokenArray = json.get(jsonInit, "tokens")]
[h: Token_ID = json.get(json.get(AllTokenArray, CurrentToken), "tokenId")]
[h: CurrentTokenName = getName( Token_ID)]

[h: SelectedTokens = getSelectedNames()]
[h: deselectTokens(SelectedTokens, ",")]
[h: selectTokens(Token_ID, 1)]

[h: TokenInit = getProperty("Init", Token_ID)]
[h: WeaponSpeed = getProperty("PWeaponSpeed", Token_ID)]
[h: DBonus = getProperty("DexBonus", Token_ID)]

[h: WSpeed = TokenInit + WeaponSpeed]
[h: React = 9 - DBonus]
[h: InitRoll = eval("D" + React)]
[h: NewInit = WSpeed + InitRoll]
[h: CurrentCount = getInitiativeRound()]

[If(TokenInit == CurrentCount), CODE:{
[h: setProperty("PInit", NewInit, Token_ID)]
<b>Current Count: </b>[r: CurrentCount]<br>
<hr/>
<b>[r: CurrentTokenName]: Init = [r: TokenInit] GO-GO-GO</b><br>
<b>Recovery: </b>[r: WSpeed]<br>
<b>Reaction: </b>[r: React]<br>
<b>Init Roll: </b>[r: InitRoll]<br>
<b>New Initiative: </b>[r: NewInit]<br>
<hr/>
};{}]

btw, there is a Macro help section under the Maptools Subforum: http://forums.rptools.net/viewforum.php?f=20

Re: Macro Output Artifacts

Posted: Mon Sep 25, 2017 8:39 pm
by Templar
Perfect. I appreciate it.