Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

They just don't. The compiler won't complain, though.

Optional string function parameters

Cthulhu contributed this:

If you have an optional string parameter in a function signature with a default value, then try to call the function using a string that's longer than that parameter, the game will crash as the engine doesn't seem to allocate sufficient space for the string.

Code Block
languagecpp
function MyMethod(optional string ExtraPar = "ABCD");
 
....
 
function CrashTheGame()
{
	//this will crash with a buffer overlow; "ABCDEF" is longer that "ABCD"
	MyMethod("ABCDEF");
}
function EverythingIsOkay()
{
	//this won't crash; "ABC" is shorter than "ABCD"
	MyMethod("ABC");

}

If you need a default string value for an optional string parameter, the ideal solution then would seem to be:

Code Block
languagecpp
function MyBetterMethod(optional string ExtraPar)
{
	if(ExtraPar == "")
	{
		ExtraPar = "ABCD";
	}
}