Page 1 of 1

Help with Switch/Case! setProperty

Posted: Tue Sep 14, 2021 1:52 pm
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!

Re: Help with Switch/Case! setProperty

Posted: Tue Sep 14, 2021 3:09 pm
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')]
};
]

Re: Help with Switch/Case! setProperty

Posted: Tue Sep 14, 2021 5:58 pm
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.