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.
Trying to figure out Switch
Moderators: dorpond, trevor, Azhrei, Gamerdude
Re: Trying to figure out Switch
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
DISCORD (the new MT forum!)
My stuff
Excel Tools: Table and Light editors
MT Tools: Bag of Tricks: Tools for Maptool, Dungeon Builder I, Dungeon Builder II,onMouseOverEvent.
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
DISCORD (the new MT forum!)
My stuff
Excel Tools: Table and Light editors
MT Tools: Bag of Tricks: Tools for Maptool, Dungeon Builder I, Dungeon Builder II,onMouseOverEvent.
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
Re: Trying to figure out Switch
Switches, especially in MT are a little confusing and I typically avoid them, but they are useful in certain situations. Here is the syntax:
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.
Code: Select all
[switch(condition), code:
case 1: {
<!-- stuff goes here -->
};
case 2: {
<!-- other stuff -->
};
default: {
<!-- stuff with no other matches -->
}
]
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:
- Notepad++ MapTool addon
- RPEdit details (v1.3)
- Coding Tips: Modularity and Design
- Videos: Macro Writing Tools