Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
Anrok
Apprentice


Joined: 19 Nov 2010
Posts: 119

PostPosted: Mon Nov 29, 2010 2:25 pm   

How to stop the execution of the next trigger line
 
If previous line has returned true.

For example

Variables: a= 0, b=0, c=0

#IF (test=on) {#SW (@a=0) {#show a fired;var a 1} (@b=0) {#show b fired;#var b 1} (@c=0) {#show c fired;#var c 1}}

At the moment, the trigger fires everything at once because all the above variables are true. However i want it to fire in order and only one command at a time.. So first it would fire a=0 and set a to 1, then the next time it would fire b=0 and so on..

I have tried using #abort, #abort all, #break. And nothing seems to have worked for me ..

That is how i used them

#IF (test=on) {#SW (@a=0) {#show a fired;var a 1;#abort all} (@b=0) {#show b fired;#var b 1;#abort all} (@c=0) {#show c fired;#var c 1;#abort all}}
Reply with quote
Anrok
Apprentice


Joined: 19 Nov 2010
Posts: 119

PostPosted: Mon Nov 29, 2010 3:58 pm   
 
Hmm, Just made this basic test alias and it seems to be working, but fails to work in my complex trigger, off for more testing Shocked
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Mon Nov 29, 2010 4:52 pm   
 
If you tell us a bit more about what you are actually trying to do, we could probably help. From your brief description, it sounds like a multistate trigger might be a better solution.
Reply with quote
Anrok
Apprentice


Joined: 19 Nov 2010
Posts: 119

PostPosted: Mon Nov 29, 2010 5:12 pm   
 
Sorry, i jumped the gun a bit asking you guys for help - #abort all does actually work very well, i simply made a clumsy mistake . Topic closed : )
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Mon Nov 29, 2010 9:11 pm   
 
I'm surprised CMud even considers that valid syntax. You are basically trying to use #IF as a #SWITCH.
_________________
EDIT: I didn't like my old signature
Reply with quote
Anrok
Apprentice


Joined: 19 Nov 2010
Posts: 119

PostPosted: Mon Nov 29, 2010 9:46 pm   
 
Iam ? Shocked
i use #if to check for a first condition, and if that one returns true then #SW checks are activated ? What is the the proper way to build a multi-condition trigger ?
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Mon Nov 29, 2010 11:34 pm   
 
#IF syntax goes like this:

Code:
#IF (expression) {code to execute when expression is true} {code to execute when expression is false}


#SWITCH syntax goes like this:

Code:
#SWITCH (expression1) {code to execute if expression1 is true} (expression2) {code to execute if expression2 is true}...(expressionN) {code to execute if expressionN is true}


Code:
#SWITCH (expression1) {
    code to execute if expression1 is true
  }
  (expression2) {
    code to execute if expression2 is true
  }
  (expressionN) {
    code to execute if expressionN is true
  }


#SWITCH only evaluates for true, and each expression can be different from the others.
_________________
EDIT: I didn't like my old signature
Reply with quote
jakj
Novice


Joined: 30 Apr 2006
Posts: 45

PostPosted: Tue Nov 30, 2010 12:05 am   
 
And that's what he's doing. The entire code of the #switch is inside the {} of the #if.

FOO:
#SW (@a=0) {#show a fired;var a 1;#abort all} (@b=0) {#show b fired;#var b 1;#abort all} (@c=0) {#show c fired;#var c 1;#abort all}

#IF (test=on) {FOO}
Reply with quote
oldguy2
Wizard


Joined: 17 Jun 2006
Posts: 1201

PostPosted: Sun Dec 05, 2010 11:17 pm   
 
You have var a 1 instead of #var a 1 also. With the switch, it should stop on the first expression that returns true so I don't see why abort all would be necessary. Also it is a lot easier to just use (!@a) instead of (@a=0).

If you run the following alias:

Code:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
  <alias name="test" copy="yes">
    <value>#SW (!@a) {
  #print a fired
  #var a 1
  } (!@b) {
  #print b fired
  #var b 1
  } (!@c) {
  #print c fired
  #var c 1
  } </value>
  </alias>
</cmud>


On the first run it will print "a fired". On the next run it will print "b fired". On the run after that it will print "c fired". That is of course if you start with a, b, and c all set to false or 0.

If they are all true, nothing should print to the screen at all.
Reply with quote
Anrok
Apprentice


Joined: 19 Nov 2010
Posts: 119

PostPosted: Mon Dec 06, 2010 12:28 am   
 
Thanks oldguy, seems that #sw works in a different way and wont loop through values like #if would in that situation, thank you!
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
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

© 2009 Zugg Software. Hosted by Wolfpaw.net