![]() |
|
|
#1 |
|
Testing optional parameters in functions
In the following code :
Code:
function( optional int1, int int2 )
{
// doblah;
}
If the code is valid, is a default value given to int1 when I call the function without the first parameter ? P.S: I purposefully placed an optional parameter first just in case it's a bad practise.
__________________
![]()
|
|
|
|
|
|
|
#2 |
|
Optional parameters must not be followed by non-optional parameters. You'll find that out when you try to compile the code.
As for detecting whether an optional parameter was specified or not: Omitted parameter values will end up being the null value of the corresponding type. Only in Unreal engine 3 you can specify a default value for parameters, UE1/2 always use 0, "", None, False, etc.
__________________
Wormbo's UT/UT2004/UT3 mods | YouTube channel | PlanetJailbreak | Unreal Wiki | Liandri Archives Everything you ever wanted to know about replication | UnrealScript security considerations <elmuerte> you shouldn't do all-nighters, it's a waste of time and effort <TNSe> nono <TNSe> its always funny to find code a week later you dont even remember writing <Pfhoenix> what's worse is when you have a Star Wars moment <Pfhoenix> "Luke! I am your code!" "No! Impossible! It can't be!" |
|
|
|
|
|
|
#3 | |
|
Quote:
So, about testing these optionals, let's say int2 is optional instead. if I do a if( int2 > 0), this should work ? I'm asking because the compiler usually complains if you test something that isn't a local variable. In this case (I haven't got round to testing it yet), the test will do fine then I assume ?
__________________
![]()
Last edited by Zur; 30th Dec 2008 at 09:57 AM. |
||
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|