I want to have a macro that prints something depending on 1d100 result. For example let's say that I have a table of the form:
01-20: A
21-50: B
51-60: C
61-90: D
91-00: E
What is the most efficient way to program this? First I guessed that SWITCH could be used, but my understanding is that it only works with strings. Can I avoid nested ifs?
switch for numerical values?
Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice
- Full Bleed
- Demigod
- Posts: 4736
- Joined: Sun Feb 25, 2007 11:53 am
- Location: FL
Re: switch for numerical values?
Why not use an actual table to store the data?gmg wrote: ↑Thu Aug 20, 2020 1:46 pmI want to have a macro that prints something depending on 1d100 result. For example let's say that I have a table of the form:
01-20: A
21-50: B
51-60: C
61-90: D
91-00: E
What is the most efficient way to program this? First I guessed that SWITCH could be used, but my understanding is that it only works with strings. Can I avoid nested ifs?
http://lmwcs.com/rptools/wiki/Introduction_to_Tables
Then you have a whole host of functions to work with: http://lmwcs.com/rptools/wiki/Category:Table_Function
Maptool is the Millennium Falcon of VTT's -- "She may not look like much, but she's got it where it counts."
Re: switch for numerical values?
Oh, I didn't know about tables :/
Thanks for that
Thanks for that
Re: switch for numerical values?
Here's another non-table method.
Code: Select all
<!-- use highest to demark breaks. -->
[H: indexes = "20,50,60,90,100"]
[H: values = "A,B,C,D,E"]
[H: roll = 1d100]
[H: result = 0]
[H, foreach(index,indexes), code: {
[H, if(roll > index): result = result + 1]
}]
[H: finalValue = listGet(values,result)]
Downloads:
- Notepad++ MapTool addon
- RPEdit details (v1.3)
- Coding Tips: Modularity and Design
- Videos: Macro Writing Tools
- Full Bleed
- Demigod
- Posts: 4736
- Joined: Sun Feb 25, 2007 11:53 am
- Location: FL
Re: switch for numerical values?
NP.
Glad you jumped in to get the info. The stuff MT can do and people don't know about is staggering.
Maptool is the Millennium Falcon of VTT's -- "She may not look like much, but she's got it where it counts."