Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: RickJ on Fri 17/03/2006 10:39:17

Title: Optional String parameter?
Post by: RickJ on Fri 17/03/2006 10:39:17
How do I make a String parameter optional as shown below?   

// Module Script
struct WinBlu  {
   // Some stuff
   // :

   import static String   Data(String Name, String Value=null);

   // Some more stuff
   // :
};

When I set it equal to null or to ""  I get the error below.  If I set it to zero
the compiler is happy but I don't think that is right either.   

Error (line xxx): Parameter default value must be literal

I assume I am missing something really obvious here;  it makes me feel so damm noobish.    := 
Title: Re: Option String parameter?
Post by: Pumaman on Fri 17/03/2006 12:03:59
You can only have optional parameters for int and float parameters.
Title: Re: Option String parameter?
Post by: RickJ on Fri 17/03/2006 13:28:47
Whew, I feel way better now.  ;)  Thanks ...
Title: Re: Optional String parameter?
Post by: monkey0506 on Sat 18/03/2006 00:58:58
CJ you are no fun.  You can set it to 0 to make it optional (as you already figured out) and then in the function just pretend as if it's null...it works in any case.  You know me...I'm not big on "conventional."
Title: Re: Optional String parameter?
Post by: RickJ on Sat 18/03/2006 02:01:45
Generally speaking null is not necessarily guaranteed to be equal to 0 for all situations for all time.  If it were, there  wouldn't need to be a keyword for it. 

Title: Re: Optional String parameter?
Post by: monkey0506 on Sat 18/03/2006 02:22:30
Well actually I think the keyword is just something of a simplification.  Kind of like the enumerated bool value "false".  It's equal to 0 and unless some major failure of logic takes place in the near future, it always will be.

I understand the concern about using 0 instead of null and whatever...but...

Quote from: meI'm not big on "conventional.

[EDIT:]

Oh...and I think it's worthy of mentioning that enumerated values (including bool) are handled internally as an integral type, so they can be optional as well.