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


Joined: 09 Sep 2007
Posts: 3

PostPosted: Sun Sep 09, 2007 7:44 pm   

How can i create my own function?
 
Hi -

I'm trying to create something to return a word based on a number - pseudocode would look something like this:

if 0 < number < 10 then myword = "pathetic"
if 11 < number < 20 then myword = "mighty"
etc...

I would like to call this function from an alias within the same class - something like

myword = getword(10)

is this possible? i am really new to programming with zmud.

thanks!
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Mon Sep 10, 2007 12:09 am   
 
Short answer - you can't. "Real" functions were just added to the new CMUD beta, and aren't available in zMUD. Long answer is that functions can be stored as a literal string inside a variable:

#function something {%if(%1="yes",something1,something2)}

This creates a variable @something with the literal value "%if(%1="yes",something1,something2)" and zMUD does some jiggery pokery to make this work:

#say @something("yes")

and so on. Note that you can only use other functions inside these pseudo-functions, so your example would look something like this:

#function getword {%if(%1<10,"pathetic",%if(%1<20,"mighty",...etc...))}

Then you use it

myword = @getword(10)
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
fienna
Newbie


Joined: 09 Sep 2007
Posts: 3

PostPosted: Mon Sep 10, 2007 3:29 am   
 
thanks, i actually got this to work, in theory. it might be a little long, but i think it will do the job.

is there a limit to how long these lines can be?

thanks
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Mon Sep 10, 2007 4:41 am   
 
When it comes to the executed code in a trigger, alias, button, or other setting, there's no artificial limit to how long it can be.

The same is definitely not true in other places where executable code can be stored--the other com textbox in the room properties window, the textbox for sending commands to the game for #DIRECTIONs, and so on. For these things, if you need something long you should stuff the code into an alias and call the alias from these places.
_________________
EDIT: I didn't like my old signature
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