|
ernestwong Newbie
Joined: 27 Aug 2002 Posts: 4 Location: Hong Kong
|
Posted: 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. |
|
|
|
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Tue Aug 27, 2002 7:42 pm |
Sounds like #ALIAS to me.
LightBulb
Senior Member |
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: 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 |
|
|
|
ernestwong Newbie
Joined: 27 Aug 2002 Posts: 4 Location: Hong Kong
|
Posted: 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. |
|
|
|
Kjata GURU
Joined: 10 Oct 2000 Posts: 4379 Location: USA
|
Posted: 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 |
|
|
|
|
|