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
FriedDuck
Newbie


Joined: 29 Sep 2002
Posts: 4

PostPosted: Sun Sep 29, 2002 3:45 am   

Newbie needs a little help with functions
 
I am trying to get functions to work, and I need a little help.

I have read the help files in zMud and tried to enter an example directly from them as follows:

#VARIABLE kk {kill %1;stun %1}

Then tried to execute this:

@kk(parrot)

And the mud gives me back "Try typing that again". I have tried both commands separate from the function, and they both work. I have opened up the function in the GUI, and it looks exactly like the help file shows it, so I don't know what I am doing wrong.

Any help is appreciated.

Duck
Reply with quote
Charbal
GURU


Joined: 15 Jun 2001
Posts: 654
Location: USA

PostPosted: Sun Sep 29, 2002 4:21 am   
 
It appears that you may be confusing functions and aliases. Functions in zMUD return values, aliases execute commands.

So, a sample function that calculates the factorial of a number would be like:

#FUNC factorial {%if(%1 > 1, %eval(%1*@factorial((%1-1))), 1)}

Then #SAY @factorial(5)

Outputs:
120

What it appears you want is an alias:

#ALIAS kk {kill %1;stun %1}

Links:
Introduction to Aliases
#FUNCTION command



 - Charbal
Reply with quote
benny1564
Novice


Joined: 22 Jun 2004
Posts: 48

PostPosted: Thu Sep 01, 2005 1:19 pm   
 
What if I want an alias that returns something?
_________________
Reply with quote
Guinn
Wizard


Joined: 03 Mar 2001
Posts: 1127
Location: London

PostPosted: Thu Sep 01, 2005 2:26 pm   
 
for the alias example you used
#VARIABLE kk {kill %1;stun %1}

You would then need to type (for example)
kk bigbadmonster

zmud would then send
kill bigbadmonster
stun bigbadmonster

so it does return something
the function is completely different from the alias, so unless you want to make something similar to the factorial example that Charbal mentioned I'd put it out of your mind for now and just focus on the aliases

Hope it helps
Reply with quote
benny1564
Novice


Joined: 22 Jun 2004
Posts: 48

PostPosted: Thu Sep 01, 2005 4:15 pm   
 
So a function that sends stuff to the mud and the returns an integer is not possible today?
_________________
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Thu Sep 01, 2005 9:50 pm   
 
Getting a function to do both is a very complex business. More often then not zScript provides 6 different ways to do any given thing. In the exact example you gave:
#VARIABLE kk {kill %1;stun %1}
The kk variable should be stored as "kill ;stun ". If done from the command line it may keep the %1's though. A small oddity, that I am not about to test and check. In any case, if kk actually contained "kill %1;stun %1" then the use of '@kk(parrot) ' in a single line within a script will send to the mud "kill parrot;stun parrot". It is more in how it is used then anything else. Functions may not be the best thing to use, so I would suggest you let us know what you want to do and we can suggest some good methods that will work.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
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