Issues with getting my code to refactor

Hi guys,

Hoping for some assistance, i’m having real issues with getting my code to refactor like in the course. I’m using PC, but following the method I’ve been advised and i keep getting this error message. (Extract method failed with following reasons: The selection contains an error or unknown type)

It’s even got to the point where I’ve copied and pasted Ben’s entire code and it still doesn’t work.

Any help would be much appreciated, its pretty disheartening to get stuck at such an early point :frowning:

Liam

Hi Liam,

I note that your file isn’t saved before you are trying the extract method feature, try saving the file first.

It’s very difficult to see the code in your screenshot, copy/paste typically works best for code examples, screenshots for errors and Unity editor etc…


See also;

Hi Rob

Thanks for your reply, really appreciate you taking the time, sorry i am new to all this!

I’ve moved on now by doing it all manually instead of using the refactor tool, so i can’t paste in the code now.

But i did save the code a lot of times and in the end i used the exact code copied and pasted from Ben’s resources, so i am really puzzled why it didn’t work.

Liam

Hi Liam,

I was merely going by the asterisk against the file name at the top of your screenshot, this indicates that the file isn’t saved. It occurred to me that, perhaps, when the extract method was tried it was basing the extract on the code it thought was still there, but this had changed since, hence the error.

Obviously without testing the theory it’s hard to tell. Typically the issues with the extract method come down to the actual selection of code itself.

@ben

The error at the bottom of the screen suggests an issue with a missing closing brace. If I were you I would follow your code through from top to bottom and look for both opening and closing braces/brackets and ensure you have the corresponding pairs.

If you aren’t already, you may consider using a block approach for your brackets/braces rather than the trailing approach, this can make it a lot easier to spot missing ones when you are fairly new to coding, for example;

private void Start()
{
    if(name == "Joel")
    {
        Debug.Log("Howdy Joel!");
    }
}

as opposed to;

private void Start() {
    if(name == "Joel") {
        Debug.Log("Howdy Joel!");
    }
}

On a related note, the error message was pretty much the only readable part of your screenshot. You can just copy/paste your code into the forum and then apply some characters both before and after it which will format it, this makes it very readable for everyone else, plus, they can copy/paste you back a solution from your own code, see the link below regarding the code formatting.

Hope this helps :slight_smile:


See also;

Remember, also, that in Visual Studio, if move your cursor to any { or } it will highlight its corresponding open or close brace for you. This may help nail down the elusive missing }.

1 Like

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

Privacy & Terms