Strange Output Behaviour

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
Templar
Cave Troll
Posts: 65
Joined: Wed Sep 20, 2017 9:24 pm

Strange Output Behaviour

Post by Templar »

Hi All,

I am trying to get an understanding some strange code behaviour.
In the example below I have removed a large amount of code for ease of explanation.

I have a macro called "TokenActions" that calls a macro called "DisplayMessage" for each token in its list.

I wanted to add a condition to only do this if the token was not dead.
Since in the original code, the foreach was imbedded within in an if statement, and the text output from the "DisplayMessage" macro was also imbedded in 2 conditional levels, I decided that the best way was to insert a macro ("IfNotDead") which does the check.
Unfortunately this does not work??

For 3 tokens, I should get 6 lines of output. But I only get 3 (from calling the "DisplayMessage" directly).

If I remove the if statement from "IsNotDead" and just leave "[macro("PDam@Lib:Miror"):id]", then I get all 6 lines of output.

Any ideas?

===TokenActions===========================================================================

Code: Select all

[h: cond = "{layer:["TOKEN"]}"]
[h: newlist=getTokenNames()]
[h: tokenList = ""]
[h, foreach(name, newlist, ""), code:{
	                                  [h: id = findToken(name)]               
                                      [if(getProperty("ObjectType", Id) == "PC-NPC"), CODE:{[h: tokenList = listAppend(tokenList, name)]};{}]
                                      }]
[foreach(name, tokenList, ""), code:{
	                                 [h: id = findToken(name)]
                                     [macro("IfNotDead@Lib:Miror"):id]
                                     [macro("DisplayMessage@Lib:Miror"):id]
                                      }]
===IfNotDead=====================================================================================

Code: Select all

[h: id = macro.args]

[h: IsDead = 0]
[h, if(IsDead == 0),code:{ [macro("DisplayMessage@Lib:Miror"):id]};{}]
===DisplayMessage===============================================================================

Code: Select all

<b>THIS IS A TEST<b><br>
===Chat Output===================================================================================
Templar: THIS IS A TEST
THIS IS A TEST
THIS IS A TEST
Templar

User avatar
bubblobill
Giant
Posts: 167
Joined: Sun Jan 24, 2010 3:07 pm

Re: Strange Output Behaviour

Post by bubblobill »

I think you are doing things the hard way, most of your sorting can be achieved in getTokens().

Code: Select all

[h: conditions=json.set('', 
    'unsetStates', 'Dead',
    'layer', json.append('', 'token'),
    'propertyType', 'PC-NPC')]
[h: foundTokens=getTokens('json', conditions)]

[foreach(tokenId, foundTokens, ""): getName(tokenId)+' is not dead.']
Or a variation

Code: Select all

[h: conditions=json.set('', 
    'layer', json.append('', 'token'),
    'propertyType', 'PC-NPC')]
[h: foundTokens=getTokens('json', conditions)]

[foreach(tokenId, foundTokens, ""), code: {
   [r: getName(tokenId)]
   [r, if(getState("Dead", tokenId): ' is sadly deceased.'; 'is alive and kicking it baby.']
}]
etc.
Bubblobill on the forum.
@Reverend on the MapTool Discord Server

Responsible for less atrocities than most... I do accept responsibility for these though: SmartDoors, Simple d20 Framework - barebones, Drop-in: All 3.5 SRD Monsters, Drop in: Simple Character Editor, Battletech Framework

Templar
Cave Troll
Posts: 65
Joined: Wed Sep 20, 2017 9:24 pm

Re: Strange Output Behaviour

Post by Templar »

OK,

That's interesting.
I will definitely play around with that, and may use it in the end.

But I would still like to know why, what I did, does not work.
I know the "IsNotDead" macro processes the "Display Message" macro, (which in the original code it does a great deal more).
But it just doesn't give any output to chat???
Templar

User avatar
bubblobill
Giant
Posts: 167
Joined: Sun Jan 24, 2010 3:07 pm

Re: Strange Output Behaviour

Post by bubblobill »

This line in ifNotDead.

Code: Select all

[h, if(IsDead == 0),code:{ [macro("DisplayMessage@Lib:Miror"):id]};{}]
The results of your macro call to DisplayMessage are hidden.
Bubblobill on the forum.
@Reverend on the MapTool Discord Server

Responsible for less atrocities than most... I do accept responsibility for these though: SmartDoors, Simple d20 Framework - barebones, Drop-in: All 3.5 SRD Monsters, Drop in: Simple Character Editor, Battletech Framework

Post Reply

Return to “Macros”