Advertisement

why do I keep getting errors?

Started by July 29, 2021 12:17 AM
17 comments, last by fleabay 3Β years, 3Β months ago

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

I don't know Unity but Google tells me that works. Try and replace your line with that. You may be using an outdated tutorial.

From
https://forum.unity.com/threads/restart-a-scene-scenemanager-loadscene.430614/

πŸ™‚πŸ™‚πŸ™‚πŸ™‚πŸ™‚<←The tone posse, ready for action.

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.

Advertisement

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.

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.

so how do I implement your solution?

@thecapl I'm not into repeating myself.

πŸ™‚πŸ™‚πŸ™‚πŸ™‚πŸ™‚<←The tone posse, ready for action.

Advertisement

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.

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.

This topic is closed to new replies.

Advertisement