Skip to main content
GameDev.net gamedev.net
🔒 Locked 🎮 Unity

why do I keep getting errors?

Started by thecapl Jul 29, 2021 at 12:17 AM 17 replies 16k views
Original Post
thecapl
thecapl

ok so I've been following this tutorial for a main menu but I'm having trouble with the code because it keeps saying I have errors when I cant find any so all help is appreciated

using UnityEngine;

using UnityEngine.SceneManagement;

using System.Collections;

public class Restart : MonoBehaviour

{

public void RestartGame()

{

SceneManager.LoadScene(SceneManager.GetActiveScene().name); // loads current scene

}

}

fleabay
fleabay

Learn some basic C# before you start with Unity.

🙂🙂🙂🙂🙂<←The tone posse, ready for action.
thecapl
thecapl

yeah im taking a course but im only on the basics and cant figure the problem out for this piece

fleabay
fleabay

An opening brace has to have a closing brace and they need to be correctly matched.

Actually, this might not be the problem, the code is strangely formatted. Use code tags and post the actual errors you get. Always post the error.

🙂🙂🙂🙂🙂<←The tone posse, ready for action.
thecapl
thecapl
thecapl
thecapl

ok its not letting me post the screenshot let me add it to a google doc

thecapl
thecapl

https://docs.google.com/presentation/d/1JVtBU4wyEPnYMSOFk6gyvneOM9JVKScQLyPQkHSYNq4/edit#slide=id.p

21st Century Moose
21st Century Moose

Need to request access for that so I won't bother.

Instead of posting a screenshot can you not copy/paste the error text?

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls. 
thecapl
thecapl

the share settings should allow anyone with that link to view it

frob
frob

In the future, please just copy the text and paste it here in a code block. A screen shot image pasted into a google drive document then shared, then pasted that link is a long way around.

I'll transcribe three of the errors from that screen shot.

MainMenu.cs(10,59): error CS1001: Identifier expected
MainMenu.cs(10,59): error CS1003: Syntax error, “,” expected

Check line 59. There is probably a parameter missing. There might also be a semicolon missing at the end, or the compiler just got confused with the missing identifier.

LoadScene() has a mandatory parameter of the scene name, and an optional parameter of the mode. Check the spellings of everything.

MainMenu.cs(10,60): Error CS8124: Tuple must contain at least two elements.

Check line 60. This might be a carry-over from earlier errors, or from bigger structural errors. Possibly you have code that is outside of a function body, either because the compiler is struggling to recover from earlier errors, or because you misplaced some semicolons.

Repeat for the other errors. Line 61 and 62 are missing semicolons at the end, again either because they are actually missing or because of errors on earlier lines.

Lines 73 and 77 are missing other punctuation, but have similar issues.

thecapl
thecapl

ok sorry to sound dumb but i dont know what you mean on line 55 because there are not that many lines. ive only recently been taking a class on this and dont understand what that would mean.

fleabay
fleabay

Frob must have been in a rush.

(10,59) means there is an error around line 10, character 59. Double clicking on the first error should put your cursor very close to the problem.

Try my solution.

🙂🙂🙂🙂🙂<←The tone posse, ready for action.
thecapl
thecapl

so how do I implement your solution?

fleabay
fleabay

@thecapl I'm not into repeating myself.

🙂🙂🙂🙂🙂<←The tone posse, ready for action.
Alberth
Alberth

thecapl said:
so how do I implement your solution?

The instructions above are really pretty much literally what you have to do, but without you understanding them, there is no way for us to explain it to you.

What you need is more knowledge in the mechanics of writing code, understanding compiler output, and knowing how to fix those things in seconds to minutes(!). You can learn this by doing a few C# tutorials first before you try writing a game. Find a few C# tutorials, and write and debug small exercise programs, get some experience in writing code.

It may take a few weeks, but for making games it hardly makes a difference (it takes a lifetime anyway). It will make problems like the above trivial to fix, and you will understand much better what Unity code and its documentation is saying, it will make much more sense to you. That will speed up learning to make games a lot. As such, doing a few C# tutorials is a very good investment here.

fleabay
fleabay

thecapl said:
so how do I implement your solution?

Take this line out of your code…

SceneManager.LoadScene(SceneManager.GetActiveScene().name);

and put in this line…

SceneManager.LoadScene(SceneManager.GetActiveScene().name, LoadSceneMode.Single);

This was my solution from earlier. Originally it took me several minutes to find this and post it. I don't know if it works or not but for you to post “so how do I implement your solution?” is really lackluster.

🙂🙂🙂🙂🙂<←The tone posse, ready for action.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.