Help with autoselecting the token on next initiative

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
Mookie1171
Kobold
Posts: 2
Joined: Wed Nov 11, 2015 2:27 pm

Help with autoselecting the token on next initiative

Post by Mookie1171 »

I'm trying to autoselect the next token as it comes up on initiative. I use the nextInitiative() function to change initiative, then use the getInitiativeToken(), to get the ID number of the token that currently has initiative, then the selectTokens() function to select the current token. I think the issue might be with getting the selectTokens() function to use the ID number from the getInitiativeToken() function. Is there a better way to do this?

Code: Select all

[h:nextInitiative()] <br>
[getInitiativeToken()] <br>
{
CurrentInitiativeID = [getInitiativeToken()] <br>
[selectTokens("CurrentInitiativeID", 1)] <br>
}
[x]
I get this error.

  Error in body of roll.       Statement options (if any):       Statement Body : CurrentInitiativeID= [getInitiativeToken()] [selectTokens("CurrentInitiativeID", 1)]


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

Re: Help with autoselecting the token on next initiative

Post by Full Bleed »

Mookie1171 wrote:I think the issue might be with getting the selectTokens() function to use the ID number from the getInitiativeToken() function.
The issue is that your syntax is wrong in a number of places. You need to spend more time looking at working code and reading up on macro writing to get the basics down (check out Wolph's link above).

But, lets take a look at your code, line by line:

Code: Select all

[h:nextInitiative()] <br>
No reason for the carriage return there.

Code: Select all

[getInitiativeToken()] <br>
You're running this function (which finds the ID of the token that has initiative) and then assigning it to nothing.

You're also not hiding the output and using a carriage return for no reason again.

Code: Select all

{
No reason for this bracket.

Code: Select all

CurrentInitiativeID = [getInitiativeToken()] <br>
Here you are running the same function as above to get the ID of the token with initiative. You're on the right track this time trying to assign it to a variable. But you are doing it wrong. The variable needs to be in the brackets with the function.

It would look like this if done properly:
Proper Code wrote: [h: currentInitiativeID = getInitiativeToken()]
But, as you will see at the end of this post, you don't need to do that at all.

Code: Select all

[selectTokens("CurrentInitiativeID", 1)] <br>
You're using the Wiki: selectTokens() function wrong.

First, "CurrentInitiativeID" should be a variable. You're putting it in quotes like it's a string. You need to understand the difference between the two. The function expects an id there.
Second, by using a "1" in the "add" parameter, you're going to be adding the selected token to the previously selected token (i.e. your list of selected tokens will grow). That's not what you want to do.

Code: Select all

}
Another bracket that should not be there.

So, as you can see, you have a lot of syntax errors. It's good that you're getting your feet wet, but you're in for a world of hurt if you don't work on the basics. ;)


However, this is what you said you wanted to do:

Code: Select all

[h: nextInitiative()]
[h: selectTokens(getInitiativeToken())]
Note that I've nested the Wiki: getInitiativeToken() function into the Wiki: selectTokens() function. You don't have to assign the ID to a variable unless you're going to use it for something else.
Maptool is the Millennium Falcon of VTT's -- "She may not look like much, but she's got it where it counts."

Mookie1171
Kobold
Posts: 2
Joined: Wed Nov 11, 2015 2:27 pm

Re: Help with autoselecting the token on next initiative

Post by Mookie1171 »

Thanks. That's very helpful. It looks like I was on the wrong track and had some syntax messed up, so I might not have ever figured that out. With all that I got wrong, I'm surprised that I even managed to find the right functions.

I have read the Introduction to Macro Writing article, but not everything in it made sense, so I may need to go over it again.

The breakdown of the code line by line was really enlightening. I think I understand syntax and nesting functions a little better now.

Thanks again!

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

Re: Help with autoselecting the token on next initiative

Post by Full Bleed »

Mookie1171 wrote:Thanks. That's very helpful. It looks like I was on the wrong track and had some syntax messed up, so I might not have ever figured that out. With all that I got wrong, I'm surprised that I even managed to find the right functions.

I have read the Introduction to Macro Writing article, but not everything in it made sense, so I may need to go over it again.

The breakdown of the code line by line was really enlightening. I think I understand syntax and nesting functions a little better now.

Thanks again!
You're welcome. Learning MT macro coding requires a lot of trial and error... the best guides come from scavenging from examples on the wiki and the forums... then building on that.

Have fun. I'd suggest that you don't try to do too much with macros right away. Get some basics down and then let your macro usage grow organically as your understanding increases.
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”