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
Dyron
Apprentice


Joined: 08 Apr 2004
Posts: 103
Location: USA

PostPosted: Sun Dec 07, 2008 8:22 pm   

Trigger question
 
Code:
#if (@cancheck = 1) {#abort 2}
#IF (%ismember( paralysis, @afflictionlist)) {
  cancheck=1
  #DELITEM afflictionlist "paralysis"
  afflictable
  #alarm "CanCheck" +.5 {cancheck = 0}
  #abort 2
  }
#IF (%ismember( slickness, @afflictionlist)) {
  cancheck=1
  #DELITEM afflictionlist "slickness"
  #alarm "CanCheck" +.5 {cancheck = 0}
  #abort 2
  }


This is code from zmud.. I need to make it work in cmud.. How do I make it stop after one of these has been met?
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Sun Dec 07, 2008 10:43 pm   
 
Replace every instance of "#abort 2" with "#EXIT".

The #ABORT command in zMud was very bad, and I would never have reccommended anyone use it. I would have structured that code as an if-else chain. CMud introduced #EXIT to leave a script immediately, #BREAK to end a loop immediately, #CONTINUE to jump to the top of a loop as its next iteration immediately, #RESULT to set the return value of a function, and #RETURN to preform a combination of #RESULT and #EXIT. These are all similar to things that have existed in C and Pascal for years, and some programmers don't even know how to write code without them.

If the snippet you posted belongs to a larger script with many more %ismember checks then you might want to look at the #SWITCH command. The purpose of this command is to make an if-else chain in a more readable fashion. It also gains some speed over the repeated #IFs because it has a smaller compiled size reducing how much interpretaion is required to find the result. Using #SWITCH would eliminate the need for #EXIT within each of the got a match script portions.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
Dyron
Apprentice


Joined: 08 Apr 2004
Posts: 103
Location: USA

PostPosted: Mon Dec 08, 2008 4:55 am   
 
Sweet.. exactly what I wanted.. Thanks Vij
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