RPTools.net

Discussion and Support

Skip to content

It is currently Sun Feb 25, 2018 10:56 pm 






Reply to topic  [ 3 posts ] 

Previous topic | Next topic 

  Print view

Author Message
 Offline
Kobold
 
Joined: Thu Aug 03, 2017 11:21 am
Posts: 6
 Post subject: Trying to figure out Switch
PostPosted: Thu Aug 03, 2017 11:43 am 
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.


Top
 Profile  
 
User avatar  Offline
Deity
 
Joined: Fri Mar 20, 2009 4:40 am
Posts: 9485
Location: Netherlands
 Post subject: Re: Trying to figure out Switch
PostPosted: Thu Aug 03, 2017 1:32 pm 
youre using [[ ]] which is a syntax error. it must be [ ]. you might also want to read the 'read this' link in my sig.

_________________
GETTING STARTED WITH MAPTOOLS - TUTORIALS, DOCS, VIDEOS, TOOLS, ETC

My stuff
Excel Tools: Table and Light editors
MT Tools: Bag of Tricks: Tools for Maptool, Dungeon Builder I, Dungeon Builder II,onMouseOverEvent and
DPI.
Frameworks: Dark Heresy, Rogue Trader, Deathwatch, Black Crusade, Only War, SET Card Game, RoboRally
Wiki: Debugging Tutorial, Speed Up Your Macros, Working With Two CODE Levels, Shortcut Keys, Avoiding Stack Overflow, READ THIS


Top
 Profile  
 
User avatar  Offline
Deity
 
Joined: Tue Nov 10, 2009 6:11 pm
Posts: 8015
Location: Bay Area
 Post subject: Re: Trying to figure out Switch
PostPosted: Thu Aug 03, 2017 4:39 pm 
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:
[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.

_________________
Downloads:


Top
 Profile  
 
Display posts from previous:  Sort by  
Reply to topic  [ 3 posts ] 

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:

Who is online

In total there is 1 user online :: 0 registered, 0 hidden and 1 guest (based on users active over the past 5 minutes)
Most users ever online was 243 on Sun Nov 04, 2012 6:14 am

Users browsing this forum: No registered users and 1 guest





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

Style based on Andreas08 by Andreas Viklund

Style by Elizabeth Shulman