scripting?

Thoughts, Help, Feature Requests, Bug Reports, Developing code for...

Moderators: dorpond, trevor, Azhrei

Forum rules
PLEASE don't post images of your entire desktop, attach entire campaign files when only a single file is needed, or generally act in some other anti-social behavior. :)
User avatar
ltwally
Cave Troll
Posts: 88
Joined: Tue Nov 14, 2006 12:16 pm
Location: Phoenix, AZ, USA
Contact:

scripting?

Post by ltwally »

OK. I've tried going through the search engine on this site, and came back with non-helpful results.


As of 1.3b39, what is the state of scripting in MapTool? (Our group has decided not to update until 1.3 hits gold.)

Can I set a variable and have it used in my macros? If so, how?

Can I do conditional logic? If so, how?

If this stuff exists, we really need a reference guide & tutorials out in the open somewhere that everyone can easily see.

If this stuff isn't yet available... Hop to it! Updating a dozen or more macros every time my character levels is teh suck.

Thanks!

-ltwally

Esaquam
Cave Troll
Posts: 32
Joined: Thu Jul 24, 2008 11:55 pm

Re: scripting?

Post by Esaquam »

ltwally wrote:...
As of 1.3b39, what is the state of scripting in MapTool? (Our group has decided not to update until 1.3 hits gold.)


You probably want http://forums.rptools.net/viewtopic.php?t=5177 to start.

User avatar
Orchard
Great Wyrm
Posts: 1852
Joined: Fri May 09, 2008 10:45 am
Location: Doylestown PA
Contact:

Post by Orchard »

But the simple answer is:

There is some conditional logic: (if statements & min/max). If statements can be nested and currently have a number of limitations.

Variables are currently severely limited in scope to the same macro--that is you cannot set a variable and have it available across multiple macros unless it is a token property (or a token state). Equasam's link is the best resource currently for that.

If statements can be nested and work like this:

Code: Select all

[if(condition, result_if_true, result_if_false)]


but it's best to have that set a variable if you plan to do anything with it, like such:

Code: Select all

[hitroll=1d20][hit=if(hitroll>EnemyAC, "Hit", "Miss")]


That will print the result of the d20 roll and either Hit or Miss. It will ALSO prompt you for the value of EnemyAC presuming this is not a token macro and the EnemyAC is not a token property that you have set. At some point in the future it looks like we will be able to target other tokens and have that work, but it hasn't happened yet. Until that happens, my personal solution as a DM is to include EnemyAC as a property on the tokens and set it right after the player tells me who they are attacking. It's a bit clunky, but whatever.

For more detail, see the link.
0+0=1, for very unstable CPUs.

User avatar
ltwally
Cave Troll
Posts: 88
Joined: Tue Nov 14, 2006 12:16 pm
Location: Phoenix, AZ, USA
Contact:

Post by ltwally »

For the scripting to really be of value to me, I need to somehow be able to assign "static" variables to a token.

Using D&D for an example, I would like to be able to have a variable for BaseAttack, so that when I click on the macro button it just does everything correctly.

Having it pop up and ask me for all the variables every time sort of defeats the purpose - that being to simplify my life.


That being said, I am happy to see the conditional logic, and can at the least use that for things like Critical Hits.

User avatar
Orchard
Great Wyrm
Posts: 1852
Joined: Fri May 09, 2008 10:45 am
Location: Doylestown PA
Contact:

Post by Orchard »

ltwally wrote:For the scripting to really be of value to me, I need to somehow be able to assign "static" variables to a token.

Using D&D for an example, I would like to be able to have a variable for BaseAttack, so that when I click on the macro button it just does everything correctly.

Having it pop up and ask me for all the variables every time sort of defeats the purpose - that being to simplify my life.


That being said, I am happy to see the conditional logic, and can at the least use that for things like Critical Hits.


Static variables can be assigned to tokens--they are simply called properties.

This process is a bit different from what you might expect if you are a long-time programmer, but if you are coming at this from a character-design philosophy, think of it this way:

The variables are simply all properties of the character/token. They are things about that token that don't change (much), and so reside there. But most tokens will have MOST things in common within a single campaign. So you go into the menu EDIT>CAMPAIGN PROPERTIES and the first tab (open by default) will be token properties. There you can select the 'basic' list of properties on the left (or define a new list for differeing campaigns, gametypes, etc), define all the properties (static variables) that you need, hit update (don't forget this) and then hit ok. You can even export these and send them to a friend for sharing (useful if you have a player who is setting up their own token's macros.

Once there you can setup things like a roll to add the base attack bonus to an attack roll, using a token property as the variable. You might define the property BAB (base attack bonus) [note: I play d&d 3.5/3.0, so this colors my responses--I am also using maptool b40 as a reference], and then do this:

Code: Select all

[hRoll=1d20] {Hit=if(hRoll+BAB>EnemyAC,1,0)}
{if(Hit==1,"You Strike your enemy!", "Your swing fails to connect!")}

Note that the use of the {} vs. the [] in the second line means that the logic of the if statement won't be displayed, just the actual text of the result.

Here is some sample output:

Code: Select all

« hRoll=1d20 = hRoll = 6 = 6 » 1 You Strike your enemy!


Of course, this doesn't tell you much about the monster's AC (but the DM should know that), and it doesn't give the damage (and you could add that in).

To create a token macro, which is different from a global or campaign macro, first make sure you have created the properties you need, then edit the tokens properties to set the values (otherwise you will get null data errors OR a box asking for the value of the variable). Do this by double clicking (left mouse button, thanks!) on the token, or right click on the token and choose edit. Then choose the properties tab and set all the relevant values.

Once this is done, you can (with the token selected), go to the 'Selected' panel of macros, right click and 'Add New Macro'. Type or copy/paste the text of the macro and give it a name, then hit OK.

This will give you a button to fire the macro, but only while the token is selected.

You can SET existing properties, but not create new ones (unless there is something I don't know) from within macros by assignment:

Code: Select all

[HP=HP+1d8]  


(Maybe for a healing potion or something, I don't know...)

There is also more complicated stuff that can be done, but that should get you started.
0+0=1, for very unstable CPUs.

User avatar
Naryt
Dragon
Posts: 517
Joined: Fri Oct 26, 2007 8:55 am
Location: Near a tree, in a cave, under a rock.

Post by Naryt »

ltwally wrote:For the scripting to really be of value to me, I need to somehow be able to assign "static" variables to a token.

Using D&D for an example, I would like to be able to have a variable for BaseAttack, so that when I click on the macro button it just does everything correctly.

Having it pop up and ask me for all the variables every time sort of defeats the purpose - that being to simplify my life.


That being said, I am happy to see the conditional logic, and can at the least use that for things like Critical Hits.


Token properties are what you want. Edit->Campaign Properties and then modify the token properties to include what you want. To assign values to the individual tokens, edit them and modify their values appropriately.

Look for the Token Properties tutorial on the videos page: http://www.rptoolstutorials.net/maptool.htm
A wandering lost soul

User avatar
Orchard
Great Wyrm
Posts: 1852
Joined: Fri May 09, 2008 10:45 am
Location: Doylestown PA
Contact:

Post by Orchard »

Naryt wrote:
ltwally wrote:For the scripting to really be of value to me, I need to somehow be able to assign "static" variables to a token.

Using D&D for an example, I would like to be able to have a variable for BaseAttack, so that when I click on the macro button it just does everything correctly.

Having it pop up and ask me for all the variables every time sort of defeats the purpose - that being to simplify my life.


That being said, I am happy to see the conditional logic, and can at the least use that for things like Critical Hits.


Token properties are what you want. Edit->Campaign Properties and then modify the token properties to include what you want. To assign values to the individual tokens, edit them and modify their values appropriately.

Look for the Token Properties tutorial on the videos page: http://www.rptoolstutorials.net/maptool.htm


I type so slow, you didn't see my post.

But it was a long post...
0+0=1, for very unstable CPUs.

User avatar
Naryt
Dragon
Posts: 517
Joined: Fri Oct 26, 2007 8:55 am
Location: Near a tree, in a cave, under a rock.

Post by Naryt »

Orchard wrote:
Naryt wrote:
ltwally wrote:For the scripting to really be of value to me, I need to somehow be able to assign "static" variables to a token.

Using D&D for an example, I would like to be able to have a variable for BaseAttack, so that when I click on the macro button it just does everything correctly.

Having it pop up and ask me for all the variables every time sort of defeats the purpose - that being to simplify my life.


That being said, I am happy to see the conditional logic, and can at the least use that for things like Critical Hits.


Token properties are what you want. Edit->Campaign Properties and then modify the token properties to include what you want. To assign values to the individual tokens, edit them and modify their values appropriately.

Look for the Token Properties tutorial on the videos page: http://www.rptoolstutorials.net/maptool.htm


I type so slow, you didn't see my post.

But it was a long post...


Yeah, just saw it....good details.
A wandering lost soul

User avatar
ltwally
Cave Troll
Posts: 88
Joined: Tue Nov 14, 2006 12:16 pm
Location: Phoenix, AZ, USA
Contact:

Post by ltwally »

Ok... I'm hard at work with this stuff. Thanks guys!

Follow-up question: Is there a way to get a dice-roll from within the results of an IF statement.

example:

Code: Select all


{if(attackRoll!=1 && attackRoll!=20,[2d4+1+ITEM+INT],"")}


User avatar
Naryt
Dragon
Posts: 517
Joined: Fri Oct 26, 2007 8:55 am
Location: Near a tree, in a cave, under a rock.

Post by Naryt »

ltwally wrote:Ok... I'm hard at work with this stuff. Thanks guys!

Follow-up question: Is there a way to get a dice-roll from within the results of an IF statement.

example:

Code: Select all


{if(attackRoll!=1 && attackRoll!=20,[2d4+1+ITEM+INT],"")}




{if(attackRoll!=1 && attackRoll!=20,2d4+1+ITEM+INT,"")}

Just leave out the brackets around your roll and you are already there.
A wandering lost soul

User avatar
Orchard
Great Wyrm
Posts: 1852
Joined: Fri May 09, 2008 10:45 am
Location: Doylestown PA
Contact:

Post by Orchard »

Yeah, I thought about putting that in there, but then decided not to.

NOTE: you can't do an assignment operator within the if statement, but you can nest them.

SO

Code: Select all

[foo=if(bar>19, 1d4, if(baz>20, 2d8, 2d6))]


is valid, but

Code: Select all

[foo=if(bar>19, baz=1d4, 2d8)]


will fail horribly. I've nested four or even five layers deep without any problems, so don't worry too much about that.

EDIT: All of the above is untested code--there may be aggregious errors.
0+0=1, for very unstable CPUs.

bobthedog
Cave Troll
Posts: 85
Joined: Sun Aug 03, 2008 7:17 pm

Post by bobthedog »

ltwally wrote:Ok... I'm hard at work with this stuff. Thanks guys!

Follow-up question: Is there a way to get a dice-roll from within the results of an IF statement.

example:

Code: Select all


{if(attackRoll!=1 && attackRoll!=20,[2d4+1+ITEM+INT],"")}



One thing you CAN'T have inside if statements is variable assignment, like this:

{if(1 > 0, A = B, A = C)}

Instead, what you have to use is:

{A = if(1 > 0, B, C)}

User avatar
Mrugnak
Dragon
Posts: 745
Joined: Mon Jul 21, 2008 7:38 pm

Post by Mrugnak »

Another useful tip:

If you're trying to do the equivalent of

If (Condition)
A = B
Else
C = D
Endif

you CAN do it, but it takes a structure like this:

[A = if(Condition, B, A)]
[C = if(Condition, C, D)]

So basically, what this does is check if Condition is true. If so, it changes the value of A to B, If NOT true, it changes the value of A to... A. Which it was at the beginning of this statement, so nothing changes.
THEN, it checks if Condition is true. if so, it changes the value of C to C, ie doesn't change anything. If it's FALSE, it changes it to D.

Logically slightly confusing to follow, but sound.

(I don't think we have NOT as an operator yet. We have NOT EQUAL but that's not the same thing.)

User avatar
ltwally
Cave Troll
Posts: 88
Joined: Tue Nov 14, 2006 12:16 pm
Location: Phoenix, AZ, USA
Contact:

Post by ltwally »

Man, I wish the conditional logic was a bit... better.

I can code around it, but I know that at some point down the road Trevor will fix it, and I'll end up coding around it.

Still, I'm grateful for what's available. It's pretty nice to be able to set an attack power at level one and only ever have to update the token variables that it uses.


You guys have been really great with your examples and help. Thanks again!

User avatar
ltwally
Cave Troll
Posts: 88
Joined: Tue Nov 14, 2006 12:16 pm
Location: Phoenix, AZ, USA
Contact:

Post by ltwally »

Current Quest: is there a round() function? (So that when I do a LEVEL/2, I can chop off the .5 at the end of odd levels.)

Nevermind - I found it. ;)

Post Reply

Return to “MapTool”