Is something like this possible? I know that as is, it throws an error.
[switch(spellName), code:
case "Barkskin": {
[h : stateName = "Barkskin2"]
[h, if(theCasterLevel >= 6) : stateName = "Barkskin3"]
[h, if(theCasterLevel >= 9) : stateName = "Barkskin4"]
[h, if(theCasterLevel >= 12) : stateName = "Barkskin5"]
[h : buff = json.set(buff, "Duration", theCasterLevel*100, "State1", stateName)]
};
case "A", "B", "Z": {
[h : buff = json.set(buff, "Duration", theCasterLevel*100, "State1", "ABorZ")]
};
But is it possible to have multiple options in a given case? If so, is there a specific syntax?
Switch statement with more than one option on a line
Moderators: dorpond, trevor, Azhrei
Forum rules
PLEASE don't post images of your entire desktop, attach entire campaign files when only a single file is needed, or generally act in some other anti-social behavior.
PLEASE don't post images of your entire desktop, attach entire campaign files when only a single file is needed, or generally act in some other anti-social behavior.
Re: Switch statement with more than one option on a line
yes its possible, please use code blocks and whats the error?
edit: I misread the post, no its not possible.
edit: I misread the post, no its not possible.
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: Switch statement with more than one option on a line
I guess i'm not clear where the "code blocks" should be in this situation.
Code as written throws
line 1:9: unexpected char: '['
as error.
Entirely of this test macro looks like...
And if its like that (where "A" is its own line, as opposed to something like "A", "B", "C" on that line), then it works fine.
But I was hoping there would be a way to group all the similar spells (mainly the cure ones) on a single line, for readability.
Code as written throws
line 1:9: unexpected char: '['
as error.
Entirely of this test macro looks like...
Code: Select all
[h : spellName = spellName]
[h : buff = json.set("{}", "SpellName", spellName)]
[h : theCasterLevel = 10]
[switch(spellName), code:
case "Barkskin": {
[h : stateName = "Barkskin2"]
[h, if(theCasterLevel >= 6) : stateName = "Barkskin3"]
[h, if(theCasterLevel >= 9) : stateName = "Barkskin4"]
[h, if(theCasterLevel >= 12) : stateName = "Barkskin5"]
[h : buff = json.set(buff, "Duration", theCasterLevel*100, "State1", stateName)]
};
case "A": {
[h : buff = json.set(buff, "Duration", theCasterLevel*100, "State1", "ABorZ")]
};
case "Breath of Life": {
[h : isCureSpell = 1]
};
case "Cleanse": {
[h : isCureSpell = 1]
};
case "Cure Light Wounds": {
[h : isCureSpell = 1]
};
case "Cure Moderate Wounds": {
[h : isCureSpell = 1]
};
case "Cure Serious Wounds": {
[h : isCureSpell = 1]
};
case "Cure Critical Wounds": {
[h : isCureSpell = 1]
};
case "Enlarge Person": {
[h : buff = json.set(buff, "Duration", theCasterLevel*10, "State1", "EnlargePerson")]
};
default : {
[h : tbd = 5]
};
]
[broadcast(buff)]
But I was hoping there would be a way to group all the similar spells (mainly the cure ones) on a single line, for readability.
Re: Switch statement with more than one option on a line
Unfortunately switch statements in java suck. You would need to go with a series of if statements, which is what I usually do.
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 statement with more than one option on a line
Or you can just give A, B, and Z their own case with the same result in each.
Maptool is the Millennium Falcon of VTT's -- "She may not look like much, but she's got it where it counts."
Re: Switch statement with more than one option on a line
The weird part about java switch statement that it uses regex for the condition, so you could potentially match multiple cases, but it only executes the first or last one (I don't recall). For example:
output is "apple", so it's the first matching. I haven't really found a use for this.
Code: Select all
[H: condition = "a.*"]
[H, switch(condition):
case "apple": b = "apple";
case "ape": b = "ape";
case "bear": b = "bear";
default: b = "no choice"
]
[r: b]
Downloads:
- Notepad++ MapTool addon
- RPEdit details (v1.3)
- Coding Tips: Modularity and Design
- Videos: Macro Writing Tools
Re: Switch statement with more than one option on a line
apologies, I misread your post. No that's not possible. I thought you meant the usual use of options e.g. 'h,' within switch. Everything has been said: either use multiple case lines (one for each) or switch to if()
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: Switch statement with more than one option on a line
Gotcha...no worries, it can be split into multiple lines...just would have made life a little easier!