Please correct me


is this correct codeing can you help me if I am wronge

Hi,

Please refrain from posting screenshots of your code because it’s impossible to copy and paste lines from them. Instead, paste it here and format it properly. Also refrain from writing on screenshots.

Have you already compared your code to the Lecture Project Changes which can be found in the Resources of this lecture? Make sure the semicolons are at the correct position. They are not. That’s why the Visual Studio/compiler complains.

Can you spot the issue?

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

public class hacker : MonoBehaviour {
private const int V = 1;

// Use this for initialization
void Start () {
    ShowMainMenu();
    print("Hello" + "World");
}
void ShowMainMenu()
{
   
    Terminal.WriteLine("What would you like to hack into");
    Terminal.WriteLine(" Press 1 for the local library");
    Terminal.WriteLine("Press  2 for the police Station");
    Terminal.WriteLine("Enter your Selection");
   

}

void OnUserInput(string input)
{
    if (input == "menu")
    {
        ShowMainMenu();
    }
    else if (input == "1")
    {
        Terminal.WriteLineYOUVE SELECTED LEVEL 1");
    }
    else if (input == "007")
    {
        Terminal.WriteLine("please select a level mr bond");

    }
    else
    {
        Terminal.WriteLine("please enter a valid level");


    }
}

private void startGame(int v)
{
    throw new NotImplementedException();
}

}

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

public class hacker : MonoBehaviour {
private const int V = 1;

// Use this for initialization
void Start () {
    ShowMainMenu();
    print("Hello" + "World");
}
void ShowMainMenu()
{
   
    Terminal.WriteLine("What would you like to hack into");
    Terminal.WriteLine(" Press 1 for the local library");
    Terminal.WriteLine("Press  2 for the police Station");
    Terminal.WriteLine("Enter your Selection");
   

}

void OnUserInput(string input)
{
    if (input == "menu")
    {
        ShowMainMenu();
    }
    else if (input == "1")
    {
        Terminal.WriteLineYOUVE SELECTED LEVEL 1");
    }
    else if (input == "007")
    {
        Terminal.WriteLine("please select a level mr bond");

    }
    else
    {
        Terminal.WriteLine("please enter a valid level");


    }
}

private void startGame(int v)
{
    throw new NotImplementedException();
}

}

Is this the fixed code?

no
its not a fixed code
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class hacker : MonoBehaviour {
private const int V = 1;

// Use this for initialization
void Start () {
    ShowMainMenu();
    print("Hello" + "World");
}
void ShowMainMenu()
{
   
    Terminal.WriteLine("What would you like to hack into");
    Terminal.WriteLine(" Press 1 for the local library");
    Terminal.WriteLine("Press  2 for the police Station");
    Terminal.WriteLine("Enter your Selection");
   

}

void OnUserInput(string input)
{
    if (input == "menu")
    {
        ShowMainMenu();
    }
    else if (input == "1")

{
Terminal.WriteLineYOUVE SELECTED LEVEL 1");
}
else if (input == “007”)
{
Terminal.WriteLine(“please select a level mr bond”);

    }
    else
    {
        Terminal.WriteLine("please enter a valid level");


    }
}

private void startGame(int v)
{
    throw new NotImplementedException();
}

here is a rest of the code

A good organisation is important when you want to become a programmer and/or a game developer. For this reason, please put a bit more effort into the presentation of your problem. Usually, if you have a problem in your code, you will also find an error message in the Unity console.

As an exception, I will mark the issue in your screenshot because I cannot find the issue again in the unformatted code. I will not do that with screenshots featuring a wall of text because it is difficult for me to read code on images, and I cannot copy and paste code from them.


image

  1. Remove the semicolon.
  2. Add the semicolon.

Remember you can also look at the lecture code changes via the link in the Resources of each lecture.

Did this help? :slight_smile:


See also:

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

Privacy & Terms