RPTools.net

Discussion and Support

Skip to content

It is currently Mon Dec 18, 2017 11:54 am 






Reply to topic  [ 11 posts ] 

Previous topic | Next topic 

  Print view

Author Message
 Offline
Kobold
 
Joined: Sun May 21, 2017 11:06 am
Posts: 7
 Post subject: Help with Macro getProperty and setProperty
PostPosted: Wed Sep 20, 2017 8:51 pm 
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:
[r: if(CorbitWins,"PC controlled" SpellDuration "round","PC not controlled")]

or
Code:
[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:
<!-- 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:
<!-- 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]


Top
 Profile  
 
User avatar  Offline
Demigod
 
Joined: Sun Feb 25, 2007 11:53 am
Posts: 3782
Location: MD
 Post subject: Re: Help with Macro getProperty and setProperty
PostPosted: Thu Sep 21, 2017 1:30 am 
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:
[r: if(CorbitWins,"PC controlled" SpellDuration "round","PC not controlled")]

or
Code:
[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:
[r: if (CorbitWins == 1, "Do this", "Otherwise do this")]


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.

_________________
Maptool is the Millennium Falcon of VTT's -- "She may not look like much, but she's got it where it counts."


Top
 Profile  
 
User avatar  Offline
Deity
 
Joined: Fri Mar 20, 2009 4:40 am
Posts: 9427
Location: Netherlands
 Post subject: Re: Help with Macro getProperty and setProperty
PostPosted: Thu Sep 21, 2017 2:53 am 
Quote:
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:
<!-- 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:
<!-- 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.

_________________
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
Kobold
 
Joined: Sun May 21, 2017 11:06 am
Posts: 7
 Post subject: Re: Help with Macro getProperty and setProperty
PostPosted: Thu Sep 21, 2017 5:51 pm 
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:
<!-- 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]


Top
 Profile  
 
User avatar  Offline
Deity
 
Joined: Fri Mar 20, 2009 4:40 am
Posts: 9427
Location: Netherlands
 Post subject: Re: Help with Macro getProperty and setProperty
PostPosted: Fri Sep 22, 2017 5:36 am 
good attempt!

Code:
<!-- 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] 

_________________
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
Kobold
 
Joined: Sun May 21, 2017 11:06 am
Posts: 7
 Post subject: Re: Help with Macro getProperty and setProperty
PostPosted: Fri Sep 22, 2017 1:46 pm 
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:
[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


Top
 Profile  
 
User avatar  Offline
Deity
 
Joined: Fri Mar 20, 2009 4:40 am
Posts: 9427
Location: Netherlands
 Post subject: Re: Help with Macro getProperty and setProperty
PostPosted: Fri Sep 22, 2017 7:41 pm 
the latter

_________________
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
Demigod
 
Joined: Sun Feb 25, 2007 11:53 am
Posts: 3782
Location: MD
 Post subject: Re: Help with Macro getProperty and setProperty
PostPosted: Sat Sep 23, 2017 6:47 pm 
blocked_writer wrote:
Code:
[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."


Top
 Profile  
 
 Offline
Kobold
 
Joined: Sun May 21, 2017 11:06 am
Posts: 7
 Post subject: Re: Help with Macro getProperty and setProperty
PostPosted: Mon Sep 25, 2017 10:04 am 
Got it. Thanks.

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

Code:
<!-- 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&#39;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&#39;s MP is now: [r: corbitMP]


Last edited by blocked_writer on Mon Sep 25, 2017 11:18 am, edited 1 time in total.

Top
 Profile  
 
User avatar  Offline
Deity
 
Joined: Fri Mar 20, 2009 4:40 am
Posts: 9427
Location: Netherlands
 Post subject: Re: Help with Macro getProperty and setProperty
PostPosted: Mon Sep 25, 2017 10:15 am 
Looks good. One min and one max at both macros is redundant given the nature of the macro. But that's all

_________________
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
Kobold
 
Joined: Sun May 21, 2017 11:06 am
Posts: 7
 Post subject: Re: Help with Macro getProperty and setProperty
PostPosted: Mon Sep 25, 2017 11:20 am 
Thanks. I figured the max lines were overkill, but it works and I have the game in an hour!

- Richard


Top
 Profile  
 
Display posts from previous:  Sort by  
Reply to topic  [ 11 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 are 2 users online :: 0 registered, 0 hidden and 2 guests (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 2 guests





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

Style based on Andreas08 by Andreas Viklund

Style by Elizabeth Shulman