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

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Mon Apr 12, 2010 6:17 pm   

Custom Functions question
 
Can I give my function a default parameter? i.e. entering the parameter is optional, if you don't, then it defaults to the specified default?
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
Martaigne
Wanderer


Joined: 05 Jan 2002
Posts: 88
Location: Atlanta, GA

PostPosted: Mon Apr 12, 2010 6:50 pm   
 
The simple solution would probably be to check to see if %1 = "" then act accordingly...
_________________
Unwritten Legends
Reply with quote
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Mon Apr 12, 2010 7:55 pm   
 
Huh? As far as I know, you have to define parameters. I should probably give a bit more info.

Here's the function:
Code:

<func name="formatclan" id="526">
  <value>#IF ($_color) {
  $_c_color = @clancolor( $_clan)
  #SWITCH (%ismember( $_clan, @_clan_list)) {#RETURN "[ "%ansi( $_c_color)$_clan%ansi( reset)" ]"}
   ($_clan="Shalonesti-k") {#RETURN %ansi( 11)"("%ansi( 3)Shalonesti%ansi( 11)")"%ansi( reset)}
   (%ismember( $_clan, @_kingdom_list)) {#RETURN %ansi( 11)"("%ansi( 3)$_clan%ansi( 11)")"%ansi( reset)}
   (%ismember( $_clan, @_remort_list)) {#RETURN "( "%ansi( $_c_color)$_clan%ansi( reset)" )"}
   ($_clan="Retired") {#RETURN %ansi( 3)"("%ansi( $_c_color)$_clan%ansi( 3)")"%ansi( reset)}
  }
  {#SWITCH (%ismember( $_clan, @_clan_list)) {#RETURN "[ "$_clan" ]"}
   ($_clan="Shalonesti-k") {#RETURN "(Shalonesti)"}
   (%ismember( $_clan, @_kingdom_list)) {#RETURN "("$_clan")"}
   (%ismember( $_clan, @_remort_list)) {#RETURN "( "$_clan" )"}
   ($_clan="Retired") {#RETURN "("$_clan")"}}</value>
  <arglist>$_clan, $_color</arglist>
</func>


The function takes TWO parameters, one is mandatory, and one I would like to be optional. The parameters are:
$_clan, $color

The function can't work without a clan to go to it, and putting a default clan would be silly for the way this function is used. However, color is simply a true false. 9 time out of 10, I want it formatted with color. So, rather than having to type
@formatclan($_clan, 1)

every single time, I would rather it defaults to 1, and I would have to put a 0 there instead if I specifically didn't want color. This is less about amount of typing and more about what I remember to do. The function did not have the color parameter for the longest time, so, I'm used to typing it without that argument.
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Mon Apr 12, 2010 8:05 pm   
 
Any arguments that are not provided will default to %null. All arguments are optional. You cannot change the default value. So your script just needs to test to see if an argument is null using the

#IF ($_clan = "") ...
or
#IF (%null($_clan)) ...
syntax

And no, you are not required to define arguments. You can still refer to them by the old %1..%99 notation. That concept of "named arguments" is new to the 2.x version of CMUD and makes scripts more readable.
Reply with quote
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Mon Apr 12, 2010 8:56 pm   
 
Ah, thanks Zugg. By the way, have a look at the odd issue post, I think it's a bug!
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD 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