MonoDevelop: Problems with default parameters

Hi,

I’m using MonoDevelop that was installed with Unity for implementation. There seem to be a problem with default parameters. E.g.:

public myMethod( int parameterOne, int parameterTwo = 0)

It is underlined red owing to the second parameter that has a default value. Does someone know how to fix this?

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 ? :smile:

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 :wink: ). Instead you’ll have to overload the functions in this way:

public myMethod(int parameterOne) {

     myMethod(parameterOne, 0);

}

public myMethod(int parameterOne, int parameterTwo);
1 Like

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.

1 Like

@PipRobbins

I’m having the same issue, and I would also like to know more.

@Metron: Thanks for the workaround. I had in mind that I already tried to overload the functions, but it seemed that I was wrong :wink:

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…

I upgraded to MonoDevelop 2.6ß3 (2.5.92) today - seems to have solved this issue. No apparent bugs - yet :slight_smile:

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…

It appears to be working now, although I noticed that mono-develop will not indicate that its optional in the inteli sense which is a pity.

I’ve exactly the same problem with unity 3.4.2f3.

How I can solve that, please ? :face_with_spiral_eyes:

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.

PS
Tested in Unity 3.5.0b6 and MonoDevelop 2.8.2

1 Like

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 :frowning:

PS :
You’ve you noticed ? Since the 2.8.X, Monodevelop don’t handle anymore the Semantic Highlighting \0/

Debugging is only possible if Unity is launched by MonoDevelop. If it is already running, close it, and then start debugging.

I wasn’t aware the previous versions did. I use MonoDevelop for debugging only.

In this case, it’s simpler to use built-in Unity Debugger.

And just out of curiosity what code editor do you use ?

You mean Debug.Log ? This way you can’t trace your code step by step, line by line.

Microsoft Visual Studio

Yes, but it’s enough in most cases.

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…