Eyup,
I'd like to have an optional parameter which is blank if unused, i'm trying:
import function target_animate(int, string saybg = "");
I've RTFM and have no problem setting optional int's but when trying with a string i get the following error,
Failed to save room room6.crm; details below
GlobalScript.ash(20): Error (line 20): Parameter default value must be literal
Edit: I could make the parameter none optional and just put "" in places where nothing is said but i don't like that idea and it feels unnecessary.
Cheers for any help.
You can't set it to an empty string by default (since that is not, technically, a "literal" value). What you can do is set it to 0 (which is equivalent to null):
import function target_animate(int, String saybg = 0);
(You should also use upper-case String instead of lower-case string.)
Thank you,
That's now all working as intended.
Great!
Quick side question,
Would the best approach to checking if the optional parameter has been used be along the lines of:
if (saybg != null) {
character[id].SayBackground(saybg);
}
if null is = 0?
Cheers.
Yes, something like that works. I think there's also a function called (going by memory) String.IsNullOrEmpty() that you can use.