What is wrong with my macro?

Doc requests, organization, and submissions

Moderators: dorpond, trevor, Azhrei

Post Reply
Lotus
Kobold
Posts: 1
Joined: Sun Aug 16, 2020 6:43 am

What is wrong with my macro?

Post by Lotus »

So I've been working on a Spell Save macro for a whole bunch of selected tokens, as to make the process much faster, and since I couldn't find one already on here.

tl;dr at end

Here Is my complete code that I've written.

Code: Select all

<!-- Request preliminary Info-->
[h: Save_Type = input(
"saveType|Strength, Dexterity, Constitution, Intelligence, Wisdom, Charisma,|Save Type|LIST|VALUE=STRING",
"saveDC|0|Spell DC",
"advantage||Advantage?|CHECK",
"damage||Will it Damage?|CHECK",
"effects||Are there Aditional Effects?|CHECK"
)]
[h:abort(Save_Type)]

<!-- Begin displaying info given (only some parts)-->
DC [r:saveDC] [r:saveType] |

<!-- Damage inputs -->
[h:Damage_Input = 0]
[if(damage==1),CODE:{
	[h:Damage_Input = input(
		"dmg|0|Input Rolled Damage",
		"vunerable||Vulnerable to Damage Type?|CHECK",
		"half||Half on Fail?|CHECK"
		)]
	[h:abort(Damage_Input)]

	
}]


<!--Damage Calculation per selected -->

[h:Damage = 0]
[h: ids = getSelected()]
[save = saveType + "ST"]
[FOREACH(id,ids), CODE:{
	[saveroll=d20+getProperty(save,id)]
	[if(saveroll>=saveDC),CODE:
	{
		<!--Passes-->
		[if(half==1),CODE:
			{
				[h:Damage = floor(dmg/2)]
			};
			{
				[h:Damage = 0]
			}
		]
		[if(vunerable==1),CODE:
			{
				[h:Damage = Damage*2]
			};
			{
			}
		]
	};
	{
		<!-- Fails-->
		[h:Damage = dmg]
		[if(vunerable==1),CODE:
		{
			[h:Damage = Damage*2]
		};
		{
		}
		]
	}
	]
}]

<!--DEBUG: Display damage -->
[Damage]


For the most part it all works, in-fact the Damage Calculation per selected works perfectly, without the addition of the foreach (and of course modifying it slightly to work without it).

However once I add the foreach it suddenly stops working. Can someone please help?

As a side note it shouldn't be any ] or } that are missing, since I've counted, multiple... multiple.... times.

TL;DR
Code no work when I add FOREACH function. Help please.

User avatar
wolph42
Deity
Posts: 9805
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: What is wrong with my macro?

Post by wolph42 »

the use of CODE blocks in MT is limited to 2 nestings, so: code:{bla code:{}} no deeper. Either rewrite your code or use a 'dirty' trick I discovered a while back: placing two single quotes: ' before every }, so ''} this will break the parser and allowing more code levels. You can also read the article I wrote about it in the wiki, see corresponding link in my sig.

Post Reply

Return to “Documentation Requests/Discussion”