No multiple versions of a function?

Post » Mon Jun 18, 2012 11:28 pm

In every modern programming language, you can do something like this:
float Function AddThese(float X, Float Y)   return X+Yendfunctionfloat Function AddThese(int X, Float Y)   return (X as float)+Yendfunctionfloat Function AddThese(float X, int Y)   return X+(Y as float)endfunctionint Function AddThese(int X, int Y)   return X+Yendfunction

The compiler would then pick the right function based on the types of the variables being passed.

However, Papyrus won't let you make multiple function definitions with the same name, even if they have different parameter lists!

YU no work!?
User avatar
Rhi Edwards
 
Posts: 3453
Joined: Fri Jul 28, 2006 1:42 am

Post » Tue Jun 19, 2012 8:20 am

That's called function overloading, and correct its not available in papyrus, because its just not supported/implemented.
User avatar
Soraya Davy
 
Posts: 3377
Joined: Sat Aug 05, 2006 10:53 pm

Post » Tue Jun 19, 2012 1:26 am

And it won't let us assign defaults that are references either...for example, for the global variable "Gvar.MyGlobalObjectReference", you can't use

[code]
Function MyFunctionWithDefaultValues(ObjectReference PassThis=Gvar.MyGlobalObjectReference)
; Do stuff with either the passed or default reference
EndFunction
[code]
User avatar
Julia Schwalbe
 
Posts: 3557
Joined: Wed Apr 11, 2007 3:02 pm

Post » Mon Jun 18, 2012 10:52 pm

Of course not, that would be an expression, not a constant statement. Objects default to none Papyrus's version of null.
User avatar
:)Colleenn
 
Posts: 3461
Joined: Thu Aug 31, 2006 9:03 am

Post » Tue Jun 19, 2012 2:37 am

OK, so you could (Kind of) do this sort of thing, but it takes a bit of what we used to call "Ugly code"

Function DefaultRefFunc(ObjectReference InObjectRef)   ObjectReference LocalObjectRef  = Gvar.MyGlobalObjectReference   If inObjectRef	  LocalObjectRef = InObjectRef   endif   ; Do stuff with LocalObjectRefEndFunction
User avatar
April
 
Posts: 3479
Joined: Tue Jun 20, 2006 1:33 am


Return to V - Skyrim