ID:167725
 
mob/DM
verb
set_density(d=1 as num)
set name = "set density"
density = d


This snipet of code is an exmaple on default arguments from the DM Guide(chapter 4.9). I'm having trouble understanding what the difference between the above and this is...

mob/DM
verb
set_density(d as num)
set name = "set density"
density = d


The DM Guide is great but I didn't find it too clear on this. Can someone please explain to me the purpose of the latter argument?


Basically, that means that if they don't specify an argument, its default is 1.


-Doh
In response to XxDohxX
Okay, I understand. But in this code...

mob
verb
Set_Name(n="eric" as text)
set name= "Set name"
name= n
src<< "[key] changes his name to [name]


... I say that if no argument is input,the name is Eric by default, but it only makes Eric the default when the user clicks "none"on the input window. Why doesn't it do it if the user leaves the the input box blank and clicks okay? It just says "Kireis changes his name to" when I do that, because either way isn't the input null? Is there a way to fix this?
In response to Kireis
Because "" is null, meaning nothing; 0 or "".
One way to avoid this is:

mob
verb
Set_Name(n as text)
set name= "Set name"
while(n <> "" || null)
n = input("Name?")
name = n
src<< "[key] changes his name to [name]


I think... :P

In response to Mechanios
That didn't work too well. I tried this...

mob
verb
Set_Name(n="eric" as text)
set name= "Set name"
if("")
name="eric"
world<< "[key] changes his name to [name]"
else
name= n
world<< "[key] changes his name to [name]"


It seems to make sense so why doesn't it work?
In response to Kireis
Kireis wrote:
That didn't work too well. I tried this...

mob
> verb
> Set_Name(n="eric" as text)
> set name= "Set name"
> if(n == "") // right here
> name="eric"
> world<< "[key] changes his name to [name]"
> else
> name= n
> world<< "[key] changes his name to [name]"
>

It seems to make sense so why doesn't it work?
In response to Mechanios
Or you could do this:

mob/verb
setname()
var/n = input(src, "What would you like to change your name to?","Name", src.name) as null|text
if(n)
src.name = n


Adding the null setting to input will return null if they press the cancel button.

~~> Unknown Person
In response to Mechanios
Alright! It works. Thanks for the help. That snippet of code, by the way, was just a test subject I came up with to help me understand default arguments. I wouldn't really use that in a game. I'm just doing whatever I can to help me to better understand the DM language.
In response to Kireis
Good for you :)