|
Bluebear Beginner
Joined: 10 Oct 2007 Posts: 17
|
Posted: Sun Feb 10, 2008 8:33 pm
#Abort and #Switch |
Hi all,
I have a bunch of scripts with hundreds of #if statements
The statements have roughly the following format
#if (@var=@a) {performactiona;#abort 1}
#if (@var=@b) {performactionb;#abort 1}
catch_all_alias_at_end
Some scripts are more than 100 lines long. I have had alot of problems with multiple #if statements being activated despite the #abort 1 in every line (I didnt have these problems in zmud).
I have also had problems with the catch_all_alias_at_end firing every time the script is run, even when one of the prior #if statments was true.
So I decided to try the #switch command, in the helpfile is has a beautiful pretty format of
#switch
() {}
() {}
But in reality I dont seem to be able to list the different 'elseif' statements on different lines. IE the format is
#swith () {} () {} () {}
which is really not very easy to read when you have a hundred elseif lines.
Can anybody tell me if I'm missing something in my formatting?
Thanks |
|
|
|
Vijilante SubAdmin
Joined: 18 Nov 2001 Posts: 5182
|
Posted: Sun Feb 10, 2008 8:37 pm |
You have to put one portion of the switch on the same line as the command.
#switch () {}
() {}
() {} |
|
_________________ The only good questions are the ones we have never answered before.
Search the Forums |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Sun Feb 10, 2008 9:10 pm |
If you're testing the value of a single variable, you can use the prettier format, Viji, which I believe is what he's talking about. That looks like this:
Code: |
#switch (variable to test)
(value to compare) {command to send}
(value to compare) {command to send}
eg
#switch (@var)
(@a) {performactiona}
(@b) {performactionb}
{catchall} |
Note how the @var is on the first line, Bluebear. You can only use the = operator with this layout, but should be fine for your purposes. |
|
|
|
Arde Enchanter
Joined: 09 Sep 2007 Posts: 605
|
Posted: Sun Feb 10, 2008 10:22 pm |
Bluebear
If you gonna put condition and script on different lines, then the main rule is that your commands, placed in {}, must be at least 1 indent deeper than your condition () is placed. You may see my comment to the SWITCH help article at the very end : #SW - I've paste that code from my real script and it works perfectly. Working with #SWITCH, watch for the colors the editor highlights your code. If your expression did not get colored even after you click "Save" button, try to place it at another indention level. But sometimes this rule reverses, I'll give you an example. And Fang, your "prettier" format actually works even if you gonna use full expression check! It is hard to document this though, I understand.
Here is another working example from my settings (2 nested #SWITCH). Again, note the indention, especially for outer #SWITCH and its second condition (@GroupMode >= @GModeGrouped), as it is the key to get the #SWITCH to work.
Code: |
#SWITCH (@GroupMode <= @GModeSelf)
{
#IF ($Target <> "")
{
//Cast spell on specified target and save it
cast '$SpellName' $Target;
Target = $Target;
}
{
#IF (@valActAutoTgt == 0)
{
//No target specified and autotarget is OFF: cast without a target
cast '$SpellName'
}
{
//No target and autotarget is ON
#SWITCH (@CombatState)
(1)
{
}
(2)
{
}
(3)
{
}
}
}
}
(@GroupMode >= @GModeGrouped)
{
#IF (@GroupTarget <> "")
{
...
}
{
...
}
}
|
|
|
|
|
|
|