|
hogarius Adept
Joined: 29 Jan 2003 Posts: 221 Location: islands.genesismuds.org
|
Posted: Sun Dec 03, 2006 2:30 am
[1.18] Problems with #SWITCH |
Simutronics' Modus Operandi. I am sending a bug report on this and also posting it on the website.
I'm trying to set up a GSL trigger to show in my status bar my current body position, whether I'm incapacitated and whether I'm bleeding.
In the description below, @HH="H", @GG="G", @FF="F", @II="I", @BB="B" and @OO="O". (This also seems to be a bug, having to set up variables for the %pos() function. I'll send a separate bug report on that.)
The following trigger does not work:
Pattern: P
Trigger type: GSL
Checkboxes marked: Case sensitive, Trigger on Trigger, Trigger on Newline
Script:
Code: |
$PP=%gsl(P);
BodyPos="STANDING ";
#switch
(%pos(@HH,$PP)>0) {BodyPos="SITTING "}
(%pos(@GG,$PP)>0) {BodyPos="LYING DOWN "}
((%pos(@GG,$PP)>0)&&(%pos(@HH,$PP)>0)) {BodyPos="KNEELING "}
Immobile="";
#switch
(%pos(@FF,$PP)>0) {Immobile="-IMMOBILE- "}
(%pos(@II,$PP)>0) {Immobile="-STUNNED- "}
(%pos(@BB,$PP)>0) {Immobile="*UNCONSCIOUS* "}
Bleed="";
#switch
(%pos(@OO,$PP)>0) {Bleed="^BLEEDING "} |
I got it to work by doing the following, but it somewhat defeats the purpose of the #SWITCH command.
Script:
Code: |
$PP=%gsl(P);
BodyPos="STANDING ";
#switch
(%pos(@HH,$PP)>0) {BodyPos="SITTING "};
#switch
(%pos(@GG,$PP)>0) {BodyPos="LYING DOWN "};
#switch
((%pos(@GG,$PP)>0)&&(%pos(@HH,$PP)>0)) {BodyPos="KNEELING "};
Immobile="";
#switch
(%pos(@FF,$PP)>0) {Immobile="-IMMOBILE- "};
#switch
(%pos(@II,$PP)>0) {Immobile="-STUNNED- "};
#switch
(%pos(@BB,$PP)>0) {Immobile="*UNCONSCIOUS* "};
Bleed="";
#switch
(%pos(@OO,$PP)>0) {Bleed="^BLEEDING^ "}
|
|
|
|
|
slicertool Magician
Joined: 09 Oct 2003 Posts: 459 Location: USA
|
Posted: Sun Dec 03, 2006 5:32 am |
Try putting the first case of the switch statement on the same line as the #switch. Sometimes it squabbles at you if you don't. Like so:
Code: |
$PP=%gsl(P);
BodyPos="STANDING ";
#switch (%pos(@HH,$PP)>0) {BodyPos="SITTING "}
(%pos(@GG,$PP)>0) {BodyPos="LYING DOWN "}
((%pos(@GG,$PP)>0)&&(%pos(@HH,$PP)>0)) {BodyPos="KNEELING "}
Immobile="";
#switch (%pos(@FF,$PP)>0) {Immobile="-IMMOBILE- "}
(%pos(@II,$PP)>0) {Immobile="-STUNNED- "}
(%pos(@BB,$PP)>0) {Immobile="*UNCONSCIOUS* "}
Bleed="";
#switch (%pos(@OO,$PP)>0) {Bleed="^BLEEDING "} |
|
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Sun Dec 03, 2006 10:53 am |
Okay, I responded to the other thread and I honestly can't see why this isn't working. I'm going to paste this script into an alias and change it so that $PP is set from the first parameter of the alias. I'm going to try these strings:
HGF - Kneeling and Immobile, no Bleeding
HIO - Sitting and Stunned and Bleeding
GBO - Lying down and Unconscious and Bleeding
which seem to cover all the different possibilities for results. I'll also add an #echo at the end to show me how the variables ended up.
Okay, and pasting what you have there into the editor, it immediately doesn't compile. I guess that's why it's not working ;P
After commenting out portions of the code to see which it doesn't like, it seems it's both the first and second #switch commands it's failing to compile. (btw, why use #switch for the last one? #if would do). I left the second one commented out while I tried to get the first to compile.
Okay, in order to get this to compile I had to play around with the spacing. I think this stems from the fact that if a line is indented from the line before it, the new line is ignored. If it's not, it's treated as a separate command. So the second and third #switch parameters are being treated as different commands. There were two ways I found that compiled:
Code: |
#switch
(%pos(@HH,$PP)) {BodyPos="SITTING "}
(%pos(@GG,$PP)) {BodyPos="LYING DOWN "}
((%pos(@GG,$PP))&&(%pos(@HH,$PP))) {BodyPos="KNEELING "} |
and
Code: |
#switch (%pos(@HH,$PP)) {BodyPos="SITTING "} (%pos(@GG,$PP)) {BodyPos="LYING DOWN "} ((%pos(@GG,$PP))&&(%pos(@HH,$PP))) {BodyPos="KNEELING "} |
and the same thing worked fine for the second #switch. Just to test my response from the other thread, I changed the variables to letters and ran the script a couple of times to see if it's working as intended.
I ended up with this alias
Name: test($PP)
Script:
Code: |
BodyPos="STANDING "
#switch
(%pos(H,$PP)) {BodyPos="SITTING "}
(%pos(G,$PP)) {BodyPos="LYING DOWN "}
((%pos(G,$PP))&&(%pos(H,$PP))) {BodyPos="KNEELING "}
Immobile=""
#switch
(%pos(F,$PP)>0) {Immobile="-IMMOBILE- "}
(%pos(I,$PP)>0) {Immobile="-STUNNED- "}
(%pos(B,$PP)>0) {Immobile="*UNCONSCIOUS* "}
Bleed=""
#switch
(%pos(O,$PP)>0) {Bleed="^BLEEDING "}
#echo BP:@BodyPos I:@Immobile B:@Bleed |
and it works just fine apart from one thing. You need to move the KNEELING option to the top, because if H is in the string it's going to exit out at Sitting rather than at Kneeling. You need to test for both first.
I'm not sure how exactly it wasn't working for you - you just said it wasn't working - but my only guess if it's still not working is that %gsl doesn't output a string or something. |
|
|
|
hogarius Adept
Joined: 29 Jan 2003 Posts: 221 Location: islands.genesismuds.org
|
Posted: Sun Dec 03, 2006 2:07 pm |
Slicer and Fang, I adapted your suggestions, and the following works. Thanks for your help!
Code: |
$PP=%gsl(P)
#switch (%pos(G,$PP)&&%pos(H,$PP)) {BodyPos="KNEELING "}
(%pos(G,$PP)) {BodyPos="LYING DOWN "}
(%pos(H,$PP)) {BodyPos="SITTING "}
{BodyPos="STANDING "}
#switch (%pos(F,$PP)) {Immobile="-IMMOBILE- "}
(%pos(I,$PP)) {Immobile="-STUNNED- "}
(%pos(B,$PP)) {Immobile="*UNCONSCIOUS* "}
{Immobile=""}
#switch (%pos(O,$PP)) {Bleed="^BLEEDING^ "}
{Bleed=""} |
|
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Mon Dec 04, 2006 9:42 pm |
Not sure why everyone is having so much trouble with this. Here is a test script that I used, and it worked fine:
Code: |
$PP=%1
BodyPos="STANDING "
#switch (%pos("H",$PP)>0) {BodyPos="SITTING "}
(%pos("G",$PP)>0) {BodyPos="LYING DOWN "}
((%pos("G",$PP)>0)&&(%pos("H",$PP)>0)) {BodyPos="KNEELING "}
#show @BodyPos |
Anyway, this compiles fine. You don't need extra indenting as far as I can tell. As long as the first clause is on the same line as #switch then it works fine. |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Mon Dec 04, 2006 9:45 pm |
I guess that's where mine was going wrong, because the first clause wasn't on the same line. Good to know, thanks Zugg.
|
|
|
|
|
|
|
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 vote in polls in this forum
|
|