Campaign macro vs Token macro (impersonate token error)

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
paddirn
Kobold
Posts: 18
Joined: Wed Dec 30, 2009 10:37 pm

Campaign macro vs Token macro (impersonate token error)

Post by paddirn »

Basically what this code is supposed to do is read whether a state is active or not on the selected token. If it is, it removes the state and copies a token on the current map and removes that state from selected token. If the macro is run again with that specific token in the same cell, it removes the token and adds that state back to the selected token (to show that the selected token is "carrying" the item)

I've got a set of macros set up that work fine on the Token level, but I can't seem to get it to work on the Campaign macro level and I'm not sure if it's just because it uses a Lib: token and that's just a known limitation of Lib: tokens.

This is the Token/Campaign level macro:

Code: Select all

[h: defineFunction("CAT_Pickup", "CAT_Pickup@Lib:SpaceHulk")]
[h: switchToken(getSelected())]
[h:isCAT=state.CAT]

[if(Side=="SpaceMarines" && isCAT == 0), code:
{
[h:setState("CAT", 1)]
[h: CAT_Pickup()]
<b>[r:getSelectedNames()] picked up the CAT</b>
};{}]

[if(Side=="SpaceMarines" && isCAT == 1), code:
{
	[h:setState("CAT", 0)]
	<b>[r:getSelectedNames()] droppped the CAT</b>
	[h: UNITS_CELLS = 0]
	[h: marine = currentToken()]
	[h: x = getTokenX(UNITS_CELLS, marine)]
	[h: y = getTokenY(UNITS_CELLS, marine)]
	[h: updates = json.set("", "x", x, "y", y, "useDistance", UNITS_CELLS)]
	[h: copyToken("CAT", 1, "Tokens", updates)]
	[h: setState("CAT", 0)]

	[h:switchToken("CAT")]
	[h: sendToBack()]
};{}]
and this is the Lib:SpaceHulk token macro:

Code: Select all

	[h: switchToken(getSelected())]
	[h: areaOffsets = '[ {x:0, y:0}]']
	[h: area = json.set("{}", "offsets", areaOffsets)]
	[h: cond = json.set("{}", "area", area, "npc", 1, "unsetState", "['Dead']")]
	[h: ids = getTokens("json", cond)]

	[r,foreach(id, ids, "<br>"),CODE:
	{
   	  [h:switchToken(id)]

  	  [if(Side == "CAT"), code:
		{
    		[h:removeToken("CAT")]
		};{}]
	}]

I've tried inserting [h: switchToken(getSelected())] in a number of places to make sure the selected token is the impersonated token to get it to work, but it doesn't seem to matter. This code works fine on the Token macro level, but does not work on the Campaign macro level. Can anybody see what I'm missing in this that is generating the "Error executing "getTokens": there is no impersonated token" error?


User avatar
Full Bleed
Demigod
Posts: 4736
Joined: Sun Feb 25, 2007 11:53 am
Location: FL

Re: Campaign macro vs Token macro (impersonate token error)

Post by Full Bleed »

CoveredInFish wrote:Wiki: getTokens() wants you to specify the token parameter in the area-object.
This bit me today... and it was a pain in the butt to figure out. It made it seem like I could not use getTokens() without an impersonated token... and it did not jive with how all the other functions in the macro were working. Usually if you "switchToken()" in the macro you can be reasonably certain that the rest of the functions will call from/on that token. But not here... yuck.
Maptool is the Millennium Falcon of VTT's -- "She may not look like much, but she's got it where it counts."

Post Reply

Return to “Macros”