There is no argument given that corresponds to

Hello, it must be a stupid question to ask, but I’m getting this error whilst testing out with things in Section 2, the part where you add the code to manage and update the state.

The error is

Assets\AdventureGame.cs(28,32): error CS7036: There is no argument given that corresponds to the required formal parameter 'selection' of 'State.getNextStates(int)'

Here’s the code:
AdventureGame.cs)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class AdventureGame : MonoBehaviour
{
    [SerializeField] Text SceneDescription;
    [SerializeField] Text storyText;
    [SerializeField] State initializingState;

    State state;

    void Start()
    {
        UpdateState(initializingState);
    }

    void Update()
    {
        ManageState();
    }

    private void ManageState()
    {
        var nextStates = state.getNextStates();

        if (Input.GetKeyDown(KeyCode.Alpha1))
            UpdateState(nextStates[0]);
        else if (Input.GetKeyDown(KeyCode.Alpha2))
            UpdateState(nextStates[1]);
        else if (Input.GetKeyDown(KeyCode.Alpha3))
            UpdateState(nextStates[2]);
    }

    private void UpdateState(State nextState)
    {
        state = nextState;
        storyText.text = state.getSceneDescription();
        storyText.text = state.getStateStory();
    }
}

State.cs)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[CreateAssetMenu(menuName = "State")]
public class State : ScriptableObject
{
    [TextArea(1, 1)] [SerializeField] string sceneDescription;
    [TextArea(14, 14)] [SerializeField] string storyText;
    [SerializeField] State[] nextStates;

    public string getSceneDescription()
    {
        return sceneDescription;
    }

    public string getStateStory()
    {
        return storyText;
    }

    public State[] getNextStates(int selection)
    {
        return nextStates;
    }
}

This lecture is cool, thanks! <3

Hi,

In my opinion, there is no such thing as a stupid question as long as you are genuinely interested in the answer. Feel free to ask. Even if the solution/answer reveals itself to be very simple, that would be absolutely fine. :slight_smile:

The answer is simple in this case but the question is great because it allows you to learn one of the most important features of C#: method overloading.

From what I see in your code, you probably already know method overloading but I assume you are more familiar with JavaScript (or another programming language) than with C#.

Check the definition of your getNextStates method in the State class. It is defined with a parameter, thus you need to call the method and pass on an argument. That’s how C# works.

What you could try is to define a default value:
public State[] getNextStates(int selection = 0)

I think, in that case, you don’t have to pass on an argument when calling the method.

Did this help?


See also:

1 Like

Absolutely! I really appreciate how I got a such detailed answer for a roughly written question like this~

I now see the problem is pretty obvious, I called a function with no arguments provided,
but how I defined the function I requires an int variable to pass in.

Turned out that I forgot to modificate the function correctly after following the ‘challenge’ answers.
So the lesson I learnt is that I should definitely check my code again before I move my butt to ask someone kind to solve my problems instead :grin:

Thanks so much for the help!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms