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

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
ernestwong
Newbie


Joined: 27 Aug 2002
Posts: 4
Location: Hong Kong

PostPosted: Tue Aug 27, 2002 3:53 pm   

Functions
 
Hi,
I have written quite a lot of triggers. There are some times when I need to call a section of code over and over again in many different triggers. I would like to have a function to store this section of code. I've tried to store if in a variable with no parameter but it doesn't work. What should I do? Thanks.
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Tue Aug 27, 2002 7:42 pm   
 
Sounds like #ALIAS to me.

LightBulb
Senior Member
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Wed Aug 28, 2002 3:45 am   
 
quote:

Hi,
I have written quite a lot of triggers. There are some times when I need to call a section of code over and over again in many different triggers. I would like to have a function to store this section of code. I've tried to store if in a variable with no parameter but it doesn't work. What should I do? Thanks.



If the code you want to run does not have any Zscript commands (ie, #TRIGGER), you can use the #FUNCTION command to contain the code. Otherwise you'd have to use #ALIAS as Lightbulb said.

If, however, you're using proper #FUNCTION code and it simply isn't firing with a null argument list perhaps you can use a dummy argument or post the code here to see if we can spot any not-so-obvious problems or causes.

li'l shmoe of Dragon's Gate MUD
Reply with quote
ernestwong
Newbie


Joined: 27 Aug 2002
Posts: 4
Location: Hong Kong

PostPosted: Thu Aug 29, 2002 3:28 am   
 
Thanks for the advice, however, what I want is a little more.

1. I would like the code to allow me to use lots of commands (#if instead of %if())...

2. in case the above request cannot be fulfilled, I would like to know how to use %if(expression,true,false) where the true/fales are multiple commands
for example, translate the following code from command to function:
#if (@leader == "abc") {
fighting = 1;
#show Leader is now fighting;
assist;
#TI ON
}

thanks.
Reply with quote
Kjata
GURU


Joined: 10 Oct 2000
Posts: 4379
Location: USA

PostPosted: Thu Aug 29, 2002 4:50 am   
 
What you need then is an alias. Just put the code that is repated inside an alias and then call it from other triggers. Example:
#ALIAS myAlias {#IF (@leader = "abc") {fighting = 1;#SHOW Leader is now fighting;assist;#TI ON}}

then, whenever you want to execute that particular piece of code, you put this line on wherever it is you are going to execute it:
myAlias

Kjata
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD 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