Help with Macro getProperty and setProperty

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
blocked_writer
Kobold
Posts: 7
Joined: Sun May 21, 2017 12:06 pm

Help with Macro getProperty and setProperty

Post by blocked_writer »

I need some help with these two macros.

These are my first attempts at creating macros in MapTool. I made them for a 7th edition Call of Cthulhu adventure.

They refer to an NPC token, corbitt, which has a custom MP (magic point) property of 18. But both macros report the MP property as being 1 higher than it displayed in the token's Properties panel.

The quick fix is to set the NPC's MP score down by one, but I'd like to know what's going wrong.

Any ideas?

Second question: is it possible to reference a variable or a dice roll inside a string using the "if" command (like below)? Every time I tried I got errors.

Code: Select all

[r: if(CorbitWins,"PC controlled" SpellDuration "round","PC not controlled")]
or

Code: Select all

[r: if(CorbitWins,"PC controlled" [1d6+1] "rounds","PC not controlled")]
Thanks.

- Richard

Recharge Magic Points
This should increase the MP property of the NPC token corbitt by 1 each time it's run, up to a maximum of 18. But it treats the max value for MP as 19.

Code: Select all

<!-- Corbitt's MP -->
[h: selectTokens("corbitt")]
[h: CorbitMP = getProperty("MP", "corbitt")]
[h: CorbitMP = max(18)]
[h: setProperty("MP", CorbitMP+1, "corbitt")]
["Corbitt's current MP:"] [CorbitMP]
Corbitt casts a spell
This macro should do the following:
1. Reduce Corbitt's current MP by 1.
2. Ask for the PC's Power ability score (the range is 1-100).
3. Calculate opposed Power rolls for the PC and the NPC.
4. Display the result of the check.
5. Display the NPC's new MP score.

However, CorbitMP always returns a value that is one higher than the token's actual MP score.

Code: Select all

<!-- Corbitt's MP -->
[h: selectTokens("corbitt")]
[h: CorbitMP = getProperty("MP", "corbitt")]
[h: setProperty("MP", CorbitMP-1, "corbitt")]

<!-- PC's Power check -->
[h: PCpow = PCPower]
[h: PCroll = d100]
[h: PCresult = PCpow - PCroll]

<!-- Corbitt's Power check -->
[h: Corpow = 90]
[h: Corroll = d100]
[h: Corresult = Corpow - Corroll]
[h: SpellDuration = (1d6+1) "rounds"]

<!-- Result calculated -->
[h: CorbitWins = if(PCresult<Corresult,1,0)]
[h: CorbitMiss = if(PCresult>Corresult,1,0)]
[r: if(CorbitWins,"PC controlled","PC not controlled")]
[r: if(CorbitWins,SpellDuration,"")]
[r: if(CorbitWins,"rounds","")]
["Corbitt's current MP:"] [CorbitMP]

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

Re: Help with Macro getProperty and setProperty

Post by Full Bleed »

Don't have a lot of time, but I'll give you a couple tips so you can try sorting out your code a bit.
blocked_writer wrote:Second question: is it possible to reference a variable or a dice roll inside a string using the "if" command (like below)? Every time I tried I got errors.

Code: Select all

[r: if(CorbitWins,"PC controlled" SpellDuration "round","PC not controlled")]
or

Code: Select all

[r: if(CorbitWins,"PC controlled" [1d6+1] "rounds","PC not controlled")]
You're using the Wiki: if() incorrectly.

First, you need a condition. "CorbitWins" isn't a condition. Here is a condition:

Code: Select all

[r: if (CorbitWins == 1, "Do this", "Otherwise do this")]
[h: CorbitMP = getProperty("MP", "corbitt")]
[h: CorbitMP = max(18)]
You're using Wiki: max() incorrectly.

By using it that way CorbitMP will *always* equal 18.
Maptool is the Millennium Falcon of VTT's -- "She may not look like much, but she's got it where it counts."

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: Help with Macro getProperty and setProperty

Post by wolph42 »

Quote:
[h: CorbitMP = getProperty("MP", "corbitt")]
[h: CorbitMP = max(18)]

You're using Wiki: max() incorrectly.

By using it that way CorbitMP will *always* equal 18.
...but that's not the cause of the issue you mention

Code: Select all

<!-- Corbitts MP -->
[h: selectTokens("corbitt")]
[h: CorbitMP = getProperty("MP", "corbitt")]
<!-- so far so good  -->

<!-- this goes wrong an many levels. Max returns as FB says the MAXIMUM number of ALL 
the numbers between (), so lets say you would so max(50,18) then what number will be
 returned?? -->
[h: CorbitMP = max(18)]

<!-- so you have just set cmp to 18 and now your storing it to the property +1; 18+1=19.
 So whatever you do, the value 19 will be stored. -->
[h: setProperty("MP", CorbitMP+1, "corbitt")]
["Corbitt's current MP:"] [CorbitMP]
 

Code: Select all

<!-- let say MP is 6. So CorbitMP = 6 -->
[h: CorbitMP = getProperty("MP", "corbitt")]

<!-- so here you store the value -1, hence the value stored is 5. CorbitMP remains 6 -->
[h: setProperty("MP", CorbitMP-1, "corbitt")]

(...)

<!-- and here you show the result, which is 6. So as you never changed its value it will
 thus not be one lower. -->
["Corbitt's current MP:"] [CorbitMP] 
by the way, if is a bit confusing as there are TWO completely different ifs. You have Wiki: if() and [if:]. The difference is 'function' and 'roll option'. Click on the link in my sig 'read this' to get a better idea concerning this.

blocked_writer
Kobold
Posts: 7
Joined: Sun May 21, 2017 12:06 pm

Re: Help with Macro getProperty and setProperty

Post by blocked_writer »

Thanks for the advice. I've spent most of the evening trying to get these things to work. I've either made great progress or none at all.

I decided to create a library token for the NPC, so there was a central MP stat for the macros to access. And the "Increase MP" macro seems to be working properly, in that it increases the MP score by 1, up to a max of 18. (Added below.)

The other script, to show the results of an opposed skill check, is either nearly working or completely broken now. :cry:

I'll try and get that fixed tomorrow.

- Richard

Code: Select all

<!-- Increase Corbitt's MP -->

<!-- Retrieve lib:corbitt's MP -->
[h: selectTokens("lib:corbitt")]
[h: CorbitMP = getLibProperty("MP", "lib:corbitt")]

<!-- Check Corbitt's current MP between 0-18 -->
[h: GiveCorbitMP = if(CorbitMP > 0 && CorbitMP < 18, "true", "false")]

[h,if(GiveCorbitMP == "true"),CODE:
{
[CorbitMP = CorbitMP +1]
[setLibProperty("MP", CorbitMP, "lib:corbitt")]
}
]
Corbitt's MP rating now [r: CorbitMP] 

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: Help with Macro getProperty and setProperty

Post by wolph42 »

good attempt!

Code: Select all

<!-- Increase Corbitts MP -->

<!-- Retrieve lib:corbitts MP -->
[h: CorbitMP = getLibProperty("MP", "lib:corbitt")]
<!-- increase upto 18 -->
[h:CorbitMP = min(18,CorbitMP +1)]
<!-- store it back -->
[h:setLibProperty("MP", CorbitMP, "lib:corbitt")]

<!-- as good practice, do NOT use single quotes in the macros 
UNLESS they 'open and close'. Stuff can really break else -->
Corbitts MP rating now [r: CorbitMP] 

blocked_writer
Kobold
Posts: 7
Joined: Sun May 21, 2017 12:06 pm

Re: Help with Macro getProperty and setProperty

Post by blocked_writer »

Thanks for the more elegant version!

That macro ended up being one of four I ended up making, all to do the job I intended one macro to do.

I did consider whether using min would work in this case. But I couldn't work out what it did from the description page.

Code: Select all

[h:CorbitMP = min(18,CorbitMP +1)]
To check my understanding, does that code mean running the macro:
adds 1 to "CorbitMP" up to a maximum of 18? Or
adds 1 to "CorbitMP", but "18" is the highest value that will be returned to setLibProperty?

- Richard


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

Re: Help with Macro getProperty and setProperty

Post by Full Bleed »

blocked_writer wrote:

Code: Select all

[h:CorbitMP = min(18,CorbitMP +1)]
To check my understanding, does that code mean running the macro:
adds 1 to "CorbitMP" up to a maximum of 18? Or
adds 1 to "CorbitMP", but "18" is the highest value that will be returned to setLibProperty?
It means that CorbitMP will equal the lower of the two values inside the min() function. Which in this case is:
1) 18
or
2) CorbitMP + 1
Maptool is the Millennium Falcon of VTT's -- "She may not look like much, but she's got it where it counts."

blocked_writer
Kobold
Posts: 7
Joined: Sun May 21, 2017 12:06 pm

Re: Help with Macro getProperty and setProperty

Post by blocked_writer »

Got it. Thanks.

These are the scripts I ended up with. The max line ensures the MP value doesn't drop below 0.

Code: Select all

<!-- Reduce Corbitt MP by 1 -->
[h: CorbitMP=getLibProperty("MP", "Lib:corbitt")]
[h: CorbitMP=min(18,CorbitMP-1)]
[h: CorbitMP=max(0,CorbitMP)]
[h: setLibProperty("MP", CorbitMP, "Lib:corbitt")]
Corbitt's MP is now: [r: corbitMP]

<!-- Increase Corbitt MP by 1 -->
[h: CorbitMP=getLibProperty("MP", "Lib:corbitt")]
[h: CorbitMP=min(18,CorbitMP+1)]
[h: CorbitMP=max(0,CorbitMP)]
[h: setLibProperty("MP", CorbitMP, "Lib:corbitt")]
Corbitt's MP is now: [r: corbitMP]
Last edited by blocked_writer on Mon Sep 25, 2017 12:18 pm, edited 1 time in total.


blocked_writer
Kobold
Posts: 7
Joined: Sun May 21, 2017 12:06 pm

Re: Help with Macro getProperty and setProperty

Post by blocked_writer »

Thanks. I figured the max lines were overkill, but it works and I have the game in an hour!

- Richard

Post Reply

Return to “Macros”