RPTools.net

Discussion and Support

Skip to content

It is currently Thu Jun 22, 2017 5:17 pm 






Reply to topic  [ 9 posts ] 

Previous topic | Next topic 

  Print view

Author Message
 Offline
Dragon
 
Joined: Tue Apr 20, 2010 7:22 pm
Posts: 566
 Post subject: Same code, very different results
PostPosted: Wed Apr 19, 2017 2:38 pm 
This is in 1.4.0.5

I have this piece of code in 3 different macros.

Code:
[broadcast("1")]
[h, token(getInitiativeToken()), code: {
[h : tokenInit = getInitiative()]
}]
[broadcast(tokenInit)]


In two of them, I get the expected result in the chat window "1", then, "The token is not in the initiative list." Which I expect, because there are no tokens on the initiative board. This is what I expect and wanted to get back.

However, in the 3rd macro, I instead get this...

1
Error executing initiative function: there is no impersonated token.

So I'm pretty sure that the error is in that "code" section...but since I've copied it straight to each of the 3 macros, I'm quite confused about the inconsistent behavior.

All 3 macros are called from buttons on the Global panel, with only "Auto Execute" set on them. All 3 macros are on the same library token and again, only "Auto Execute" is checked off on the macros themselves.

Any ideas?


Top
 Profile  
 
 Offline
Dragon
 
Joined: Tue Apr 20, 2010 7:22 pm
Posts: 566
 Post subject: Re: Same code, very different results
PostPosted: Wed Apr 19, 2017 2:40 pm 
Note that if I add the token to the initiative board, then it works fine and broadcasts the token's initiative value. But since these macros can be called when there are no tokens on the init board, it has to work in those situations as well.

Works fine for 2 of them, but not the 3rd.


Top
 Profile  
 
User avatar  Offline
Deity
 
Joined: Fri Mar 20, 2009 4:40 am
Posts: 9250
Location: Netherlands
 Post subject: Re: Same code, very different results
PostPosted: Wed Apr 19, 2017 3:49 pm 
Did to check "apply to selected token"?

_________________
GETTING STARTED WITH MAPTOOLS - TUTORIALS, DOCS, VIDEOS, TOOLS, ETC

My stuff
Excel Tools: Table and Light editors
MT Tools: Bag of Tricks: Tools for Maptool, Dungeon Builder I, Dungeon Builder II,onMouseOverEvent and
DPI.
Frameworks: Dark Heresy, Rogue Trader, Deathwatch, Black Crusade, Only War, SET Card Game, RoboRally
Wiki: Debugging Tutorial, Speed Up Your Macros, Working With Two CODE Levels, Shortcut Keys, Avoiding Stack Overflow, READ THIS


Top
 Profile  
 
 Offline
Dragon
 
Joined: Tue Apr 20, 2010 7:22 pm
Posts: 566
 Post subject: Re: Same code, very different results
PostPosted: Wed Apr 19, 2017 6:43 pm 
Nope, none of them. Later in the macros, it does a "getSelected" to figure out which tokens to apply the results to.

I'm going to see if I can work this a different way.


Top
 Profile  
 
 Offline
Dragon
 
Joined: Tue Apr 20, 2010 7:22 pm
Posts: 566
 Post subject: Re: Same code, very different results
PostPosted: Wed Apr 19, 2017 7:10 pm 
I threw together a seperate macro that all three of these macros use instead.

Code:
[h : initValue = -100]
[h : initId = getInitiativeToken()]
[h, if(initId != ""), code : {
   [h : switchToken(initId)]
   [h :  initValue = getInitiative()]
}]

[h : macro.return = initValue]


This seems to do the trick, if there's someone who has the initiative, it uses their initiative value, if there's no one on the init board, then it returns -100.

That fixes my issue.


Top
 Profile  
 
User avatar  Offline
Deity
 
Joined: Tue Nov 10, 2009 6:11 pm
Posts: 7729
Location: Bay Area
 Post subject: Re: Same code, very different results
PostPosted: Thu Apr 20, 2017 12:44 am 
There's an important difference in the two macros. One macro uses two roll options side by side, ie token(tokenName), code: {} and the other separates them. MapTool may or may not go left to right when processing, but logically it could run the right side first with no access to the left, thus not having an impersonated token. Doing it the second way is the correct way to do this.

_________________
Downloads:


Top
 Profile  
 
User avatar  Offline
Deity
 
Joined: Fri Mar 20, 2009 4:40 am
Posts: 9250
Location: Netherlands
 Post subject: Re: Same code, very different results
PostPosted: Thu Apr 20, 2017 2:26 am 
@AM: I've never encountered an issue using any roll option in combination with the 'code' roll option. The 'left' side is ALWAYS evaluated before the 'code' part. Its another things when using e.g. the if() and count() roll options simultaneously.

The issue reported in this ine:
[h, token(getInitiativeToken()), code: {
is the simple fact that if there is no token in initiative you do:
[h, token(""), code: {
and that can generate an error. Using this code in different locations might result in the suppression of the error to the output (and the code not halting) while in other places it *does* throw an error and halts in that spot.

last code looks good, this is how I would do it:
Code:
[hinitId getInitiativeToken()]
[
h, if(initId != ""), code: {
    [
token(initId):initValue getInitiative()]
};{
    [
initValue = -100]
}]

[
macro.return = initValue

_________________
GETTING STARTED WITH MAPTOOLS - TUTORIALS, DOCS, VIDEOS, TOOLS, ETC

My stuff
Excel Tools: Table and Light editors
MT Tools: Bag of Tricks: Tools for Maptool, Dungeon Builder I, Dungeon Builder II,onMouseOverEvent and
DPI.
Frameworks: Dark Heresy, Rogue Trader, Deathwatch, Black Crusade, Only War, SET Card Game, RoboRally
Wiki: Debugging Tutorial, Speed Up Your Macros, Working With Two CODE Levels, Shortcut Keys, Avoiding Stack Overflow, READ THIS


Top
 Profile  
 
User avatar  Offline
Deity
 
Joined: Tue Nov 10, 2009 6:11 pm
Posts: 7729
Location: Bay Area
 Post subject: Re: Same code, very different results
PostPosted: Thu Apr 20, 2017 3:27 am 
MOTE ran in to this problem with that format where they had to force left to right evaluation.

_________________
Downloads:


Top
 Profile  
 
User avatar  Offline
Deity
 
Joined: Fri Mar 20, 2009 4:40 am
Posts: 9250
Location: Netherlands
 Post subject: Re: Same code, very different results
PostPosted: Thu Apr 20, 2017 8:13 am 
interesting, I didn't know that and have never encountered the issue.

_________________
GETTING STARTED WITH MAPTOOLS - TUTORIALS, DOCS, VIDEOS, TOOLS, ETC

My stuff
Excel Tools: Table and Light editors
MT Tools: Bag of Tricks: Tools for Maptool, Dungeon Builder I, Dungeon Builder II,onMouseOverEvent and
DPI.
Frameworks: Dark Heresy, Rogue Trader, Deathwatch, Black Crusade, Only War, SET Card Game, RoboRally
Wiki: Debugging Tutorial, Speed Up Your Macros, Working With Two CODE Levels, Shortcut Keys, Avoiding Stack Overflow, READ THIS


Top
 Profile  
 
Display posts from previous:  Sort by  
Reply to topic  [ 9 posts ] 

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:

Who is online

In total there is 1 user online :: 0 registered, 0 hidden and 1 guest (based on users active over the past 5 minutes)
Most users ever online was 243 on Sun Nov 04, 2012 6:14 am

Users browsing this forum: No registered users and 1 guest





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

Style based on Andreas08 by Andreas Viklund

Style by Elizabeth Shulman