Trying to figure out Switch

If you have searched the other User Creations subforums and an answer to your question has not been found, please post here!

Moderators: dorpond, trevor, Azhrei, Gamerdude

Post Reply
monstro44122
Kobold
Posts: 6
Joined: Thu Aug 03, 2017 12:21 pm

Trying to figure out Switch

Post by monstro44122 »

So, I'm not a programmer. I'm using Maptools because I'm hoping to link a bunch of tables I've gained over 30+ years of gaming so as to automate rolling on all of them to get one kind of grand result for an encounter. I've now read about 15 wiki pages and I can't figure out what in the world I'm doing wrong.

Here are some basics:
1: the macro that the code calls works.
2: Outside of the switch, the macro call works, and the macro it calls works (it gets the passed variable and uses it).

I then tried to add the switch option. I copied and pasted from the example in the wiki and replaced the variables. Here's the code (the --> are not in the actual code; I've just added it here as documentation).

[h:NumberOfPotions=d6] --> Not actually used in the Macro currently.
[h:PotionRoll=1 --> This will later be a d20
[h, SWITCH (PotionRoll), CODE:
case 1: { --> because the variable is currently set to 1, this should be the only case that will come up.
[[macro("RollAttackPotions1@this"): PotionRoll]]--> Again, RollAttackPotions does what it's supposed to do outside of the Macro.
};
case 2: { -->This option, because PotionRoll is set to 1, should never come up.
["You have not rolled an attack potion:<br>]
}]

This is the result in the chat window:
[h, SWITCH (PotionRoll), CODE: case 1: { [[macro("RollAttackPotions1@this"): PotionRoll]] }; case 2: { ["You have not rolled an attack potion: ] }]

To me it doesn't look like it's even going into the Switch. It's just printing it out. It's not going into the Macro (when it goes into the Macro, it should print "Test" to the chat window). It's just spitting the code out to chat without evaluating it as code.

So, what am I doing wrong?

Thoughts? Anyone? Very much appreciated.

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: Trying to figure out Switch

Post by wolph42 »

youre using [[ ]] which is a syntax error. it must be [ ]. you might also want to read the 'read this' link in my sig.

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

Re: Trying to figure out Switch

Post by aliasmask »

Switches, especially in MT are a little confusing and I typically avoid them, but they are useful in certain situations. Here is the syntax:

Code: Select all

[switch(condition), code:
   case 1: {
      <!-- stuff goes here -->
   };
   case 2: {
      <!-- other stuff -->
   };
   default: {
      <!-- stuff with no other matches -->
   }
]
condition - be careful of the value of condition because the switch will look at it via regex. If you're using just numbers or just alphanumeric strings then you'll be okay.
case X - where X can not be a variable. It must be a number or a string in quotes.
You'll also have to be aware of the 2 {{}} limit. So, if you use {} in the case then you're limited to just 1 set.

Post Reply

Return to “Requests for HELLLLP!”