Help with Switch/Case! 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
vini98
Kobold
Posts: 3
Joined: Tue Sep 14, 2021 12:45 pm

Help with Switch/Case! setProperty

Post by vini98 »

Hello everyone, this is my first post here and i am new to programming and macros. English is also not my first language, so please bear with me

I'm trying to write a macro that sets the value of two properties(GdP, GeB) on a token. It works for the first one("GdP"), but not for the second one("GeB"). I want to know (1) if it is possible to do it this way and, (2) what am i doing wrong, cause as i said, im new to macro writing and i know little about it.

Code: Select all

[h: str = getProperty("Strength")]
[h,switch(str):
case "10": setProperty("GdP", '1d6-2') setProperty("GeB", '1d6');
case "11": setProperty("GdP", '1d6-1') setProperty("GeB", '1d6+1');
case "12": setProperty("GdP", '1d6-1') setProperty("GeB", '1d6+2');
]
If switch/case is not the way to go, i would appreciate some tips on how to do it. Thanks!

User avatar
aliasmask
Deity
Posts: 8729
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Help with Switch/Case! setProperty

Post by aliasmask »

It's just some incorrect syntax. Take a look at the last example here: https://wiki.rptools.info/index.php/swi ... ll_option) and the wiki on branching https://wiki.rptools.info/index.php/Mac ... TCH_Option. You need to use the code option for multiple statements. Setting a property would count as one statement. Also, if the value of str is a number, then use numbers without quotes for it to match correctly.

Code: Select all

[h: str = getProperty("Strength")]
[h,switch(str), code:
case 10: {
  [setProperty("GdP", '1d6-2')]
  [setProperty("GeB", '1d6')]
};
case 11: {
  [setProperty("GdP", '1d6-1')] 
  [setProperty("GeB", '1d6+1')]
};
case 12: {
  [setProperty("GdP", '1d6-1')] 
  [setProperty("GeB", '1d6+2')]
};
]

vini98
Kobold
Posts: 3
Joined: Tue Sep 14, 2021 12:45 pm

Re: Help with Switch/Case! setProperty

Post by vini98 »

aliasmask wrote:
Tue Sep 14, 2021 3:09 pm
It's just some incorrect syntax. Take a look at the last example here: https://wiki.rptools.info/index.php/swi ... ll_option) and the wiki on branching https://wiki.rptools.info/index.php/Mac ... TCH_Option. You need to use the code option for multiple statements. Setting a property would count as one statement. Also, if the value of str is a number, then use numbers without quotes for it to match correctly.

Code: Select all

[h: str = getProperty("Strength")]
[h,switch(str), code:
case 10: {
  [setProperty("GdP", '1d6-2')]
  [setProperty("GeB", '1d6')]
};
case 11: {
  [setProperty("GdP", '1d6-1')] 
  [setProperty("GeB", '1d6+1')]
};
case 12: {
  [setProperty("GdP", '1d6-1')] 
  [setProperty("GeB", '1d6+2')]
};
]
It worked!! Thank you for taking your time to reply, i'm having a lot of fun learning macro writing, and it's nice to have a community to get some help. Also, thanks for the links, i'm already checking on them.

Post Reply

Return to “Macros”