News UnrealEd Files Mods FragBU Liandri Archives
BeyondUnreal Forums

Go Back   BeyondUnreal Forums > Unreal Development > Coding

Reply
 
Thread Tools Display Modes
Old 29th Dec 2008, 07:54 PM   #1
Zur
surrealistic mad cow
 
Zur's Avatar
 
Join Date: Jul. 8th, 2002
Posts: 11,679
Testing optional parameters in functions

In the following code :

Code:
function( optional int1, int int2 )
{
// doblah;
}
If I call the function without a first integer is it possible to test it hasn't been sent ? For example, can I do if( int1 > 0 ) ? Or will ucc fail to compile the code ? Or would this cause an error during execution ?

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.
__________________

Zur is offline   Reply With Quote
Old 30th Dec 2008, 04:07 AM   #2
Wormbo
 
Wormbo's Avatar
 
Join Date: Jun. 4th, 2001
Location: Germany
Posts: 5,785
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/JDN | 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!"
Wormbo is offline   Reply With Quote
Old 30th Dec 2008, 09:28 AM   #3
Zur
surrealistic mad cow
 
Zur's Avatar
 
Join Date: Jul. 8th, 2002
Posts: 11,679
Quote:
Originally Posted by Wormbo View Post
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.
Ok, so there are dos and don't when using optionals. Thanks for explaining this.

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.
Zur is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 08:53 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.

Copyright ©1998 - 2012, BeyondUnreal, Inc.
Privacy Policy | Terms of Use
Bandwidth provided by AtomicGamer