#Modifying Token's Attributes with Macro

1 messages · Page 1 of 1 (latest)

spark cradle
#

So I'm trying to make a macro to modify a token's properties based on an input value and properties from a second token.

Where am I going wrong in my code? (the only thing currently missing is the SS value which is from an input and will be added later

    "SS|0|Spell Slot Level | TEXT | WIDTH=4")]
[H: abort(success)]

[h: '<!-- Notes -->']
[h: Clay = if(SS>2,strformat(
    "Clay Armor: All BPS Damage is reduced by 3 (3rd Level Spell Slot)%n"
    ),"")]
[h: Resistance = if(SS>3,strformat(
    "Magic Resistance: Adv on all Saves v. hostile spells/magic effects)%n"
    ),"")]
[h: Resolute = if(SS>4, strformat(
  "Resolute Presence: Allies w/in 10' gain +3 to all Saves (does not stack with Paladin's Aura of Protection)%n"
    ),"")]
    [h:Bonus = if(SS>4, 3, 0)]
[h: Colossi = if(SS>6, strformat(
    "Colossi: Golem ignores difficult terrain, has a reach of 10', deals double damage to objects, and may cast Erupting Earth 3x before a long rest.%n"
    ),"")]
    [h:Reach = if(SS>6, " (10')","")]

    
[h: '<!-- Get Master Properties -->']
[h: Master = getProperty("Owner")]
[h: PCLvl = getProperty("Level", Master)]
[h: PB = getProperty("Proficiency Bonus", Master)]
[h: Langs = getProperty("Languages", Master)]
[h: SABonus = getProperty("Spell Attack Bonus", Master)]

[h: '<!-- Variable Assignment/Math -->']
[h: SSBonus = if(SS>1, SS, 0)]
[h: AC = BaseAC+floor(SSBonus/2)]
[h: STR = STRMod+floor(SSBonus/2)]
[h: CON = CONMod+floor(SSBonus/2)]
[h: Athletics = PB+STR]
[h: StrSave = PB+STR+Bonus]
[h: ConSave = PB+CON+Bonus]
[h: ToHit = SABonus]

[h: '<!-- Update Token Properties -->']
[h: setProperty("HPMax", PCLvl*6 + (SS*3))]
[h: setProperty("HP", PCLvl*6 + (SS*3))]
[h: setProperty("Languages", Langs)]
[h: setProperty("AC", AC)]

[h: '<!-- Multi Attack -->']
[h: MultiMath1 = floor(SS/2)]
[h: Multi = if(MultiMath1 >3, 3, 
    if(MultiMath1 < 1, 1, 
        MultiMath1)
        )]
[h: Multiattack = strFormat("{Multi}x Multi")]
[h: setProperty("Weapon1", Multiattack)]

[h: '<!-- Slam Damage -->']
[h: DMGAvg = 4+STR]
[h: MagicSlam = if(SS>2, "(Magical)","")]
[h: Slam = strFormat("+%{ToHit} To Hit%{Reach}; %{DMGAvg} (1d8+ %{STR})/B %{MagicSlam}")]
[h: setProperty("Weapon2", Slam)]

[h: '<!-- Update Notes -->']
[h: Notes = strFormat("%{Clay} %{Resistance} %{Resolute} %{Colossi}"]
[h: setNotes(Notes)]

[h, if(SS < 4), CODE:{
    [h:setSize(0)]
        }
]
[h, if(SS > 3 && SS < 7), CODE:{
    [h:setSize(2)]
        }
]
[h, if(SS > 6), CODE:{
    [h:setSize(4)]
        }
]```
halcyon stag
#

It looks to me like you're retrieving properties from the current token, doing stuff to them, then putting them back on the current token. To pull the data from the master token, you'll need to add a token reference to the getProperty:

Master = getProperty("Owner", "TokenName")]

(And since the "current token", the default on setProperty, can be a little fuzzy, it isn't a bad idea to include a token reference when you set the properties, too.)

spark cradle
halcyon stag
#

I should pay closer attention. Yeah, that should work (though it still wouldn't hurt to put a token reference in the setProperty statements, and in the first getProperty to pull the Owner property). What is the value of that property? Is it the token name, or the player's name? Because it needs to be the token's name, or ID (ID preferred, since token names can be duplicated).

Also, I note that both property functions have to be trusted macros to use the tokenRef parameter.

And for that matter, what happens when you run it as is?

torn mountain
#

I find it helps to actually state what's not working. By the title I'd assume properties are not being reset but that is just an assumption

spark cradle
#

ATM, it's giving the error
"Function '=' requires exactly 2 parameters; 1 were provided."

But I can't tell exactly which line is the issue.

spark cradle
halcyon stag
#

I think that error message isn't very useful, unfortunately.

First thing I'd try is to start at the bottom, and remove lines, then run the macro until the error goes away. That will tell you what line is causing it.

(You've also got an if function inside an if function, which an produce unexpected results. But that won't cause an error, just not the results you expect. Get rid of the error first, then come back to that.)

torn mountain
#

[h: Notes = strFormat("%{Clay} %{Resistance} %{Resolute} %{Colossi}"]
I think you're missing a ) here