RPTools.net

Discussion and Support

Skip to content

It is currently Wed Nov 22, 2017 1:33 pm 




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. :)



Reply to topic  [ 3 posts ] 

Previous topic | Next topic 

  Print view

Author Message
 Offline
Kobold
 
Joined: Sun Sep 03, 2017 5:36 pm
Posts: 2
 Post subject: I need help evaluating only part of a string!
PostPosted: Sun Sep 03, 2017 7:02 pm 
Alright, first of all, I'll explain what you need to know about the Framework i've been building for D&D 5e.

Each Token with the Token Type "PC" or "NPC" has these properties:
Code:
Dexterity:8
DEX:{floor(Dexterity / 2) - 5}
PB (Proficiency Bonus):2
Weapon0:wpnName=dagger; attackMod={DEX+PB}; critTarget=20; fumbRange=1; effect=;

To edit these properties, I made a library that has a macro called editValues, to modify most of the values a character would have in its sheet. The part that modifies the Weapon0 property is basically as follows:
Code:
[H: input(

"tab1 | Weapons || TAB",
    "Weapon0|
      wpnName="+getStrProp(Weapon0,"wpnName")+";
      attackMod="+getStrProp(Weapon0,"attackMod")+";
      critTarget="+getStrProp(Weapon0,"critTarget")+";
      FumbRange="+getStrProp(Weapon0,"fumbRange")+";
      effect="+getStrProp(Weapon0,"effect")+"
    ||PROPS|SPAN=TRUE SETVARS=UNSUFFIXED"
)]

This is so that every time the Input window is opened, the previous values are kept and are not always replaced by 0 every time the macro is run to its end.

Now, the problem:

The effect variable inside the Weapon0 property is supposed to be flexible, to allow outputs like these:
Quote:
deal (1d8+DEX) piercing damage
Quote:
deal (2d6) piercing damage, or (1d6) if swarm has half HP or lower.

Leaving any attack rolls aside, my objective is to get these strings to roll the dice within them, but allow them to be editable easily. I tried changing the parentheses with [brackets], and although this initially works (the damage has a different result each time, which means the rolling works correctly), once you try to open the Input window again, the previous values in the variable are kept (as intended) but replaced by their already evaluated version (as not intended). Using {curly braces} has the same problem, but the output isn't as messy.

Image
Editing the value for the first time.
Image
Editing the value a second time.

The final display is straightforward:
Code:
[h: wpnName = getStrProp(Weapon0, "wpnName")]
[h: attackMod = getStrProp(Weapon0, "attackMod")]
[h: critTarget = getStrProp(Weapon0, "critTarget")]
[h: fumbRange = getStrProp(Weapon0, "fumbRange")]
[h: effect = getStrProp(Weapon0, "effect")]

[h: attackRoll1 = 1d20]
[h: attackRoll2 = 1d20]

<b>Attack</b>: [wpnName] (+[attackMod])<br>
<b>Effect</b>: [effect]

<!-- Check if attack roll is 1 or 20, do some colorful stuff on either result, output is basically: -->
...
[attackroll1 + attackMod] || [attackroll2 + attackMod]


I've struggled with this issue for almost a week, and I've come to the conclusion that my macro scripting skills aren't up to the task. So I'm hoping someone else can shed some light on this, I'd be very grateful.


Top
 Profile  
 
User avatar  Offline
Deity
 
Joined: Fri Mar 20, 2009 4:40 am
Posts: 9419
Location: Netherlands
 Post subject: Re: I need help evaluating only part of a string!
PostPosted: Mon Sep 04, 2017 3:06 am 
I think you encountered a bug in strProp. I've informed the devs concerning this. A workaround in the mean time is this:

Code:
[h:varsFromStrProp(Weapon0)]
[
h:effect = decode(effect)]
[
H:abort(input(
    "tab1 | Weapons || TAB", 
        
"Weapon0|
          wpnName="
+wpnName+";
          attackMod="
+attackMod+";
          fumbRange="
+fumbRange+";
          critTarget="
+critTarget+";
          wpnName="
+wpnName+";
        ||PROPS|SPAN=TRUE SETVARS=UNSUFFIXED"
,
        "effect|"+effect+"|give effect use brackets"
         
))]
[
h:varsFromStrProp(Weapon0)]
[
h:Weapon0 = setStrProp(Weapon0,"effect", encode(effect))]
[
h: attackRoll1 = 1d20]
[
h: attackRoll2 = 1d20]

<
b>Attack</b>: [wpnName] (+[attackMod])<br>
<
b>Effect</b>: [effect] 


in order to use 'effect' you first need to decode it:
Code:
[r:decode(getStrProp(Weapon0,"effect"))] 

and in order to evaluate it you use Wiki: evalMacro():
Code:
[r:evalMacro(decode(getStrProp(Weapon0,"effect")))] 


tested in 1.4.0.5

_________________
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 Sep 03, 2017 5:36 pm
Posts: 2
 Post subject: Re: I need help evaluating only part of a string!
PostPosted: Mon Sep 11, 2017 12:03 am 
Sorry for the late answer, but life got in the way. Fortunately, your solution works perfectly! Thank you a lot.
I've also modified it so that it can use up to four weapons, in case anyone wants to see.

Properties:
Code:
Dexterity:8
DEX
:{floor(Dexterity / 2) - 5}
PB (Proficiency Bonus):2
Weapon0
:wpnName=longbow (150/600) ; attackMod=; critTarget=20 ; fumbRange=; effect=deal+%5B1d8%2BDEX%5D+piercing+damage. 
Weapon1
:wpnName=rapier ; attackMod=; critTarget=20 ; fumbRange=; effect=deal+%5B1d8%2BDEX%5D+piercing+damage. 


Inside the editValues library macro:
Code:
"tab1 | Weapons || TAB", 
        
"Weapon0|
         wpnName="
+getStrProp(Weapon0,"wpnName")+";
         attackMod="
+getStrProp(Weapon0,"attackMod")+";
         critTarget="
+getStrProp(Weapon0,"critTarget")+";
         fumbRange="
+getStrProp(Weapon0,"fumbRange")+";
        ||PROPS|SPAN=TRUE SETVARS=UNSUFFIXED"
,

        "effect0|"+effect0+"|Effect for Weapon 0",

        "Weapon1|
         wpnName="
+getStrProp(Weapon1,"wpnName")+";
         attackMod="
+getStrProp(Weapon1,"attackMod")+";
         critTarget="
+getStrProp(Weapon1,"critTarget")+";
         fumbRange="
+getStrProp(Weapon1,"fumbRange")+";
        ||PROPS|SPAN=TRUE SETVARS=UNSUFFIXED"
,

        "effect1|"+effect1+"|Effect for Weapon 1", 


Inside the weaponAttack library macro
Code:
[h:status = input("
       weaponID|
       "
+getStrProp(Weapon0, "wpnName")+", "+getStrProp(Weapon1, "wpnName")+"|
       Choose weapon to attack with|
       LIST|
       SELECT=0 VALUE=NUMBER
"
)]

[if(
weaponID == 0), CODE:
            {
                [h: wpnName = getStrProp(Weapon0, "wpnName")]
                [h: attackMod = getStrProp(Weapon0, "attackMod")]
                [h: critTarget = getStrProp(Weapon0, "critTarget")]
                [h: fumbRange = getStrProp(Weapon0, "fumbRange")]
                [h: effect = decode(getStrProp(Weapon0,"effect"))] 
            
};
            {
                [h: wpnName = getStrProp(Weapon1, "wpnName")]
                [h: attackMod = getStrProp(Weapon1, "attackMod")]
                [h: critTarget = getStrProp(Weapon1, "critTarget")]
                [h: fumbRange = getStrProp(Weapon1, "fumbRange")]
                [h: effect = decode(getStrProp(Weapon1,"effect"))] 
             
};]


[
h: attackRoll1 = 1d20]
[
h: attackRoll2 = 1d20]

<
b>Attack</b>: [wpnName] (+[attackMod])<br>
<
b>Effect</b>: [r:evalMacro(effect)]
<
center><font size="4">[if(attackroll1 == 20),CODE:
    {
        <font color="green">[attackroll1 + attackMod]</font>
    };
    {
        [if(attackroll1 == 1), CODE:
            {
                <font color="maroon">[attackroll1 + attackMod]</font>
            };
            {
                <font color="black">[attackroll1 + attackMod]</font>
            };]
    };] || [if(attackroll2 == 20),CODE:
    {
        <font color="green">[attackroll2 + attackMod]</font>
    };
    {
        [if(attackroll2 == 1), CODE:
            {
                <font color="maroon">[attackroll2 + attackMod]</font>
            };
            {
                <font color="black">[attackroll2 + attackMod]</font>
            };]
    };] </font></center>
 


Top
 Profile  
 
Display posts from previous:  Sort by  
Reply to topic  [ 3 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 4 users online :: 1 registered, 0 hidden and 3 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: Bing [Bot] and 3 guests





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

Style based on Andreas08 by Andreas Viklund

Style by Elizabeth Shulman