Is it possible to use and change Properties in a Macro without using their Property Name in the Macro?

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
ShadowofAion
Kobold
Posts: 4
Joined: Tue Aug 11, 2020 12:25 am

Is it possible to use and change Properties in a Macro without using their Property Name in the Macro?

Post by ShadowofAion »

To start off, I'm a novice at Maptools and making macros for it, I'm working on a lot of macros I need/want to make the 1st session of my custom game run smoothly.

Basically, I'm trying to make a versatile Macro where I can manually input the Property name and manually input a numeric value to increase or lower that Property's value.

I tried a more complicated Macro but it failed then I tried a more simplistic one, that failed as well. From what I gather when I put something like [h:CurrentLimbST=ManualLimbInput] it is taking my Input as just that without trying to see if it is a property or if any value is associated with it.

Code: Select all

[h:status = input(
"LimbSTChange|0|Number of Limb Stabilty",
"TargetLimb|LArm1,LArm2,LArm3,LArm4,LArm5,RArm1,RArm2,RArm3,RArm4,RArm5,LLeg1,LLeg2,LLeg3,LLeg4,LLeg5,RLeg1,RLeg2,RLeg3,RLeg4,RLeg5,LWing1,LWing2,LWing3,LWing4,LWing5,RWing1,RWing2,RWing3,RWing4,RWing5,Tail1,Tail2,Tail3,Tail4,Tail5|Which Limb is being affected?|LIST|SELECT=0 VALUE=STRING",
"lostOrgained|Lost, Gained|Is Limb ST being lost or gained?|RADIO|SELECT=0")]
[h:abort(status)]

[if(lostOrgained == 0),CODE:
{
    [h:LimbSTLoss = TargetLimb - LimbSTChange]
    [h:CurrentLimbST = max(LimbSTLoss, 0)]
    [h:TargetLimb = CurrentLimbST]
    [r:token.name] [r:TargetLimb] loses [r:LimbSTChange] ST.
};
{
    [h:diff = MaxST - ST]
    [h:ST = min(ST+LimbSTChange, MaxST)]
    [r:token.name] gains [r:min(diff,LimbSTChange)] ST. 
}]
I haven't messed with the 2nd part of the code associated with recovery as I wanted to just make sure the Damage portion works first(which it obviously doesn't).

Is there a specific macro option or way to write this which will both bring the Property name and it's Property value so I can use it in the/a Macro? I am quite tired and mentally drained at this point so I wouldn't be surprised if it is something simple that I am not thinking of.

Thank you, in advance.

User avatar
aliasmask
RPTools Team
Posts: 9029
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Is it possible to use and change Properties in a Macro without using their Property Name in the Macro?

Post by aliasmask »

If given a property name as a string you can get the value a couple of ways.

Code: Select all

[H: value = getProperty(propName)]

OR

[H: value = eval(propName)]

ShadowofAion
Kobold
Posts: 4
Joined: Tue Aug 11, 2020 12:25 am

Re: Is it possible to use and change Properties in a Macro without using their Property Name in the Macro?

Post by ShadowofAion »

aliasmask wrote:
Tue Aug 11, 2020 3:41 am
If given a property name as a string you can get the value a couple of ways.

Code: Select all

[H: value = getProperty(propName)]

OR

[H: value = eval(propName)]
Thank you so much for introducing me to the eval macro command, at first I had no idea what eval was really doing or how it would be useful but after thinking about it a bit more I had an epiphany and with the use of both eval and setProperty(1st time using both) I came up with this more simplistic macro(which can technically be used for any Property change).

Code: Select all

[h:LimbAffected = TargetLimb]
[h:CurrentLimbST = getProperty(LimbAffected)]
[h:STChange=STLost]
[r:token.name]'s [r:LimbAffected] has it's ST reduced by [r:STChange].
[h: FinalResult = max((eval(LimbAffected)) - STChange, 0)]
[r: if(FinalResult==0, "<b>It has been Crippled/Severed!</b>", "")]
[h: setProperty(LimbAffected, FinalResult)]
This works perfectly, though I may combine some of the methods used in this macro with my previous more complex macro so that it is restricted to only altering predetermined Limb Properties and has both Damage & Heal aspects in one macro.

Again, thank you so much aliasmask.

ShadowofAion
Kobold
Posts: 4
Joined: Tue Aug 11, 2020 12:25 am

Re: Is it possible to use and change Properties in a Macro without using their Property Name in the Macro?

Post by ShadowofAion »

Alright, so for some reason while trying to merge the two macros together for it won't work, which I can't seem to figure out what is causing it.

Code: Select all

[h:status = input(
"LimbSTChange|0|Number of Limb Stabilty",
"TargetLimb|LArm1,LArm2,LArm3,LArm4,LArm5,RArm1,RArm2,RArm3,RArm4,RArm5,LLeg1,LLeg2,LLeg3,LLeg4,LLeg5,RLeg1,RLeg2,RLeg3,RLeg4,RLeg5,LWing1,LWing2,LWing3,LWing4,LWing5,RWing1,RWing2,RWing3,RWing4,RWing5,Tail1,Tail2,Tail3,Tail4,Tail5|Which Limb is being affected?|LIST|SELECT=0 VALUE=STRING",
"lostOrGained|Lost, Gained|Is Limb ST being lost or gained?|RADIO|SELECT=0")]
[h:abort(status)]

[if(lostOrGained == 0),CODE:
{
	[r:token.name]'s [r:TargetLimb] has it's ST reduced by [r:LimbSTChange].
	[h: FinalResult = max((eval(TargetLimb)) - LimbSTChange, 0)]
	[r: if(FinalResult == 0, "<b>It has been Crippled/Severed!</b>", "")]
	[h: setProperty(TargetLimb, FinalResult)]
};
{
	[r:token.name]'s [r:TargetLimb] recovered [r:LimbSTChange] ST.
	[h: FinalResult = min((eval(TargetLimb)) + LimbSTChange, MaxLimbST)]
	[r: if(FinalResult == MaxLimbST, "<b>It has completely recovered!</b>", "")]
	[h: setProperty(TargetLimb, FinalResult)]
}]
When I remove the 2nd Healing/recovery portion of the "if" macro the 1st damage/reduction macro works fine, but with the recovery portion present the whole thing no longer works. I can only assume that for some reason the "if" function is having trouble identifying the 2 separate "if" variables??

though I can't figure out why as I'm just using a modified version of this macro that works and everything seems to be in the correct format.

Code: Select all

[h:status = input(
"hpChange|0|Number of Hit Points",
"dmgOrHealing|Damage,Healing|Is the character taking damage or being healed?|RADIO|SELECT=0")]
[h:abort(status)]
 
[if(dmgOrHealing == 0),CODE:
{
    [h:HP = HP - hpChange]
    [h:bar.Health = HP / MaxHP]
    [r:token.name] loses [r:hpChange] hit points.
};
{
    [h:diff = MaxHP - HP]
    [h:HP = min(HP+hpChange, MaxHP)]
    [h:bar.Health = HP / MaxHP]
    [r:token.name] is healed and gains  [r:min(diff,hpChange)] hit points. 
}]

Glendwyr
Kobold
Posts: 16
Joined: Mon Apr 11, 2016 4:11 am

Re: Is it possible to use and change Properties in a Macro without using their Property Name in the Macro?

Post by Glendwyr »

It's the unbalanced apostrophe.

You have a line

Code: Select all

[r:token.name]'s [r:TargetLimb] recovered [r:LimbSTChange] ST.
The parser sees the apostrophe and thinks you're starting a quote. It never finds an apostrophe to close the quote -- but you do have one on the damage-taking part of the macro. It's basically the same as having an open quotation mark but not a closing one.

Try this instead:

Code: Select all

[H: abort(input("LimbSTChange|0|Number of Limb Stabilty",
"TargetLimb|LArm1,LArm2,LArm3,LArm4,LArm5,RArm1,RArm2,RArm3,RArm4,RArm5,LLeg1,LLeg2,LLeg3,LLeg4,LLeg5,RLeg1,RLeg2,RLeg3,RLeg4,RLeg5,LWing1,LWing2,LWing3,LWing4,LWing5,RWing1,RWing2,RWing3,RWing4,RWing5,Tail1,Tail2,Tail3,Tail4,Tail5|Which Limb is being affected?|LIST|SELECT=0 VALUE=STRING",
"lostOrGained|Lost, Gained|Is Limb ST being lost or gained?|RADIO|SELECT=0"))]

[R, If(lostOrGained==0), Code:
{	[R: strformat("%{token.name}'s %{TargetLimb} has its ST reduced by %{LimbSTChange}.")]
	[H: FinalResult = max(eval(TargetLimb) - LimbSTChange,0)]
	[R, If(FinalResult == 0): "<b>It has been Crippled/Severed!</b>";""]
};
{	[R: strformat("%{token.name}'s %{TargetLimb} recovered %{LimbSTChange} ST.")]
	[H: FinalResult = min(eval(TargetLimb) + LimbSTChange,MaxLimbST)]
	[R, If(FinalResult == MaxLimbST): "<b>It has completely recovered!</b>";""]
}]

[H: setProperty(TargetLimb,FinalResult)]
I'm a big believer in the power of strformat to give you cleaner code to read; it also has the side-benefit of fixing the apostrophe issue in this case since it's enclosed in quotation marks.

ShadowofAion
Kobold
Posts: 4
Joined: Tue Aug 11, 2020 12:25 am

Re: Is it possible to use and change Properties in a Macro without using their Property Name in the Macro?

Post by ShadowofAion »

Glendwyr wrote:
Wed Aug 12, 2020 9:01 pm
It's the unbalanced apostrophe.

You have a line

Code: Select all

[r:token.name]'s [r:TargetLimb] recovered [r:LimbSTChange] ST.
The parser sees the apostrophe and thinks you're starting a quote. It never finds an apostrophe to close the quote -- but you do have one on the damage-taking part of the macro. It's basically the same as having an open quotation mark but not a closing one.

Try this instead:

Code: Select all

[H: abort(input("LimbSTChange|0|Number of Limb Stabilty",
"TargetLimb|LArm1,LArm2,LArm3,LArm4,LArm5,RArm1,RArm2,RArm3,RArm4,RArm5,LLeg1,LLeg2,LLeg3,LLeg4,LLeg5,RLeg1,RLeg2,RLeg3,RLeg4,RLeg5,LWing1,LWing2,LWing3,LWing4,LWing5,RWing1,RWing2,RWing3,RWing4,RWing5,Tail1,Tail2,Tail3,Tail4,Tail5|Which Limb is being affected?|LIST|SELECT=0 VALUE=STRING",
"lostOrGained|Lost, Gained|Is Limb ST being lost or gained?|RADIO|SELECT=0"))]

[R, If(lostOrGained==0), Code:
{	[R: strformat("%{token.name}'s %{TargetLimb} has its ST reduced by %{LimbSTChange}.")]
	[H: FinalResult = max(eval(TargetLimb) - LimbSTChange,0)]
	[R, If(FinalResult == 0): "<b>It has been Crippled/Severed!</b>";""]
};
{	[R: strformat("%{token.name}'s %{TargetLimb} recovered %{LimbSTChange} ST.")]
	[H: FinalResult = min(eval(TargetLimb) + LimbSTChange,MaxLimbST)]
	[R, If(FinalResult == MaxLimbST): "<b>It has completely recovered!</b>";""]
}]

[H: setProperty(TargetLimb,FinalResult)]
I'm a big believer in the power of strformat to give you cleaner code to read; it also has the side-benefit of fixing the apostrophe issue in this case since it's enclosed in quotation marks.
Yea, that works perfectly now. I currently don't know anything about strformat and how to use it so I will have to look into it more so I can add it to my repertoire of macro functions.

Thank you so much Glendwyr for both taking the time to look through my macro code and going through the trouble of creating a new macro that works with the key functions of it. :)

Post Reply

Return to “Macros”