Why isn't this working.

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
xanos_25
Kobold
Posts: 5
Joined: Wed Jan 11, 2017 6:22 pm

Why isn't this working.

Post by xanos_25 »

I've been fighting with map tools macro's off and on for longer then I care to admit, And the same issue keeps cropping up until I throw my hands up. Lets see if someone can give me some answers.

Here's the code

Code: Select all


 [plyr='Bob']<br>
 [chr='Dilbert'] Id
 [id=findToken(chr)] <br>
	
[r,if (id != "" ),code:{
		[switchTokens(id)]
	};{
		[id=copyToken("Default Character",1,"Grasslands")] 
		[switchToken(id)]<br>
		[getName()]<br>
		[setName(chr)]<br>
		[setGMName(plyr)] <br>
		[setPC()]<br>
	}]	

<br>[isTrusted()]<br>
Basically what it's supposed to do is look for a token called "Dilbert" and switch to it, if it fails to find one it creates one and names it "Dilbert" with the GMName "Bob" and turns it into a PC. The last little bit to to verify that it's a trusted macro.

Here's the output
Bob
Dilbert Id
000000005758DC8FB900000000000000
Default Character 46
Dilbert
Bob


1
Everything looks good except the token "Default Character 46" hasn't been modified.

I've tried this with Apply to Selected Tokens check and unchecked and on Several versions of Maptool. I'm certain I'm missing something foolish.

User avatar
aliasmask
RPTools Team
Posts: 9024
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Why isn't this working.

Post by aliasmask »

You can't update a newly created token with the macro that created it. You have to update it with the available option settings.

Code: Select all

[H: playerName = "Bob"]
[H: charName = "Dilbert"]

[H, if(tokenId == ""), code: {
   <!-- copy blank token from other map if token doesn't exist -->
   [H: options = json.set("{}",
      "name",charName,
      "gmName",playerName
   )]
   [H: copyToken("Default Character",1,"Grasslands")]
};{}]
You basically can't have any code after this that modifies the created token.


xanos_25
Kobold
Posts: 5
Joined: Wed Jan 11, 2017 6:22 pm

Re: Why isn't this working.

Post by xanos_25 »

Thank you... I need to potentially do a lot more changes then what copyToken will allow and I couldn't figure a way around. Added on input command to interrupt and will do a more elegant work around later.

Now a can proceed with my nefarious plans. :twisted:
It's better to be a Morloc then an Eloi

Post Reply

Return to “Macros”