My StartGame insists on (int level) argument

If I follow your example I use this with nothing in the argument for StartGame
void StartGame()
currentScreen = Screen.Password;
Terminal.WriteLine("You have chosen level " + level);
Terminal.WriteLine(“Please enter your password.”);

and I get an error (Assets/WM2000/Scripts/Hacker.cs(37,12): error CS1501: No overload for method StartGame' takes1’ arguments) same on line 43 where I use StartGame.

If I keep the argument in:
void StartGame(int level)
Then it works

Please explain.

I’ll try. An “overload” or “overloaded method” is one that uses the same method name for multiple uses. It’s possible to have a program that works with either of these statements:


but you need to explicitly create the overload method. If your error message is “no overload for this method…” it means you’re invoking the method in a way the compiler doesn’t recognize.

So it looks like you need to either 1) make the overload that doesn’t require an argument, or 2) use it with an Int argument the way you have it designed.

To be more explicit, I’ve created a short bit of code to try to help you wrap your head around overloads.

Overloaded Methods in C#, example: (click to expand)
private void MethodWithOverloads()
    // this method can't take-in any arguments.

private void MethodWithOverloads(int integer)
    // this method requires 1 INT argument.
    Debug.Log(integer); // print the argument to the debug console

private void MethodWithOverloads(string words)
    // this method required a string argument.
    Debug.Log(words); // print the argument to the debug console

private void UseOverloads()
    MethodWithOverloads("Hello World!");

Thanks for that. But I still don’t get why his method works, I don’t see what he did differently so that it doesn’t require a method.

Maybe if you post more of your code…
Hacker.cs from the end of lecture 12

This is what Ben has posted, and his is used:


If yours only works with an Int argument, like:

int level = 1 

The you’ve done something differently.

Hi Jack,
I just wanted to say thanks. I got it working, I’m in China so the internet is very spotty. It’s really nice to get questions answered from here.

1 Like

Fantastic! Keep at it!

Privacy & Terms