x="" - Why do I need this?

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
tcharleschapman
Kobold
Posts: 16
Joined: Wed Jul 24, 2013 11:50 am

x="" - Why do I need this?

Post by tcharleschapman »

I just got a macro to work but I'm not sure why what I did made it work.

Here is the original:
Original Code

Code: Select all

[h: Number=Times]
[h:x=roll(number, 6)]

[g: "I roll " +number +"d6's! The total is <font color=red><b>" +x +"</b><font color=black>!"]
Here is the working version:
Original Code

Code: Select all

[h: Number=Times]
[h: x=""]
[h:x=roll(number, 6)]

[g: "I roll " +number +"d6's! The total is <font color=red><b>" +x +"</b><font color=black>!"]
Why does adding

Code: Select all

[h: x=""]
suddenly make this work? Why couldn't I just save X as the roll result in the first place?

User avatar
aliasmask
RPTools Team
Posts: 9031
Joined: Tue Nov 10, 2009 6:11 pm
Location: California

Re: x="" - Why do I need this?

Post by aliasmask »

It doesn't work because you don't have "Use tooltips for inline rolls" checked in preferences.

I would also write the same code as this:

Code: Select all

[H: abort(input("number|1|Number of d6's|TEXT"))]
[H: result = roll(number,6)]
[R,G: strformat("I roll %{number}d6's! The total is <span style='color:red;font-weight:bold'>%{result}</span>!")] 
First line I recommend using an input to get values from the user. First it's more descriptive and it also allows you to stop without an error message. Leaving an unexpressed variable is just an MT thing and is a bad habit to start in programming.

Second line. Using x is fine but it's recommended to use variable names that are more descriptive. It's a good habit to get in to especially when your coding becomes more complex and longer.

Third line. Use R with G to suppress the tooltip. In this case showing how the output is concatenated isn't really helpful. Also, Wiki: strformat() is much more friendly and easier to see what's in your output than trying to concatenate with +'s. I used <span style> instead of font in this case because MT ignores the <font> tag for color sometimes and style is more reliable.

Post Reply

Return to “Macros”