|
fienna Newbie
Joined: 09 Sep 2007 Posts: 3
|
Posted: 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! |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: 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) |
|
|
|
fienna Newbie
Joined: 09 Sep 2007 Posts: 3
|
Posted: 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 |
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: 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 |
|
|
|
|
|