If you’re defining a function, why have a definition in the declaration? if it was an if statement I could see that, or iterating in a for-loop. If you are hard-coding the value for parameterTwo why include it at all ?
But back to the coding → Wouldn’t you simply encode this as:
public myMethod(int parameterOne, int parameterTwo) {
parameterOne = some value;
parameterTwo = 0;
}
@afalk: Now that’s someone who doesn’t understand how default parameter values work…
@Kathrin-Jennifer: C# doesn’t allow for default parameters (unfortunately; well… C#4.0 can but that is not included in Unity ). Instead you’ll have to overload the functions in this way:
public myMethod(int parameterOne) {
myMethod(parameterOne, 0);
}
public myMethod(int parameterOne, int parameterTwo);
Has there been anything else on this topic? Unity3 does indeed have support for default parameters, and their interaction with MonoDevelop leaves a lot to be desired: it will stop allowing code completion after their usage and will fail to index the class.
Anyone else know much about this? Default parameters do work for me, monodevelop leaves it underlined with red, but does not report any errors or warnings.
@Metron: Thanks for the workaround. I had in mind that I already tried to overload the functions, but it seemed that I was wrong
It would be much better to have default parameters instead of overloading the functions. But I haven’t found a solution for using it with monodevelop so far…
Downloaded Unity 3.4.0 today thinking for some reason that there was a MonoDevelop upgrade from 2.4 to 2.5, but I was wrong. And any minor changes that may have come, did not fix this. I’ll have to try upgrading MD on its own…
I have found a temporary solution. For example, you use Visual Studio, that works fine with named and optional arguments, as a primary IDE, but switch to MonoDevelop from time to time for debugging. Just switch “target framework” of all your C# projects to Mono / .NET 4.0:
But be prepared that every time you restart Unity, it will change it back to 3.5.
I’ve just upgraded to 3.5 Developer Preview, he comes with MonoDevelop 2.8.2 (I don’t change the target framework to 4.0), and now that work fine.
Thank you anyway alexzzzz !
MonoDevelop 2.8.2 doesn’t highlight default parameters as errors, but still doesn’t allow me to start debugging until I change the target framework, because first it tries to compile the code and fails.
Yes, I’ve also this error when I use Run > Debug, but even if I solve this by switching to Mono / .NET 4.0, MD tries to open a new Unity instance and that fail
PS :
You’ve you noticed ? Since the 2.8.X, Monodevelop don’t handle anymore the Semantic Highlighting \0/
Ive been having this problem recently as well, as the A* Pathfinding Project now uses these default parameters.
The problem im having is that EVERY time i change it to Mono/.NET 4.0 in the options, when i debug the probject(or do anything really that runs the Unity Project) it always gets set back to 3.5
Ive tried force saving on both Mono and Unity…but it always reverts back to 3.5 and its driving me insane, i cant even work on my game because its too frustrating resetting it every 30 seconds when i find a bug and have to debug a few times.
You guys updating your Mono, how did you overwrite it to make Unity use the new one? By default i just had another Mono install…not sure how you set it up to debug into Unity…