generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Java: cannot find symbol

Previous Thread :: Next Thread 
LMBOX is not online. LMBOX
Joined: 04 Jun 2008
Total Posts: 8901
15 Dec 2011 06:34 AM
I am making a simple text game. It's very early in the making. The problem is, I'm being a little too ambitious, so I am running into a lot of problems. Right now, the only problem is this error:

error: cannot find symbol

I have it for lines 33, 36, and 39. Those are the lines that call main.path[0];. I am trying to set the first int in the array according to what character class they choose, as a way of "saving" the progress. I just need help with accessing the array path from outside the main method. Thanks!

tl;dr: I can't access the array path outside of the main method. I need to access it in the classChoice method. Help. Thanks.

----------------
import java.util.Scanner;

public class textGame
{
public static void main(String args[])
{
Scanner input = new Scanner(System.in);
int path[] = new int[64];

//Actions
System.out.println("Text Game Indev by Liam Moran");
System.out.println("----------------");

classChoice();
}

public static void classChoice();
{
Scanner input = new Scanner(System.in);

//Answers
String classIntro = "You wake up in a prison. You cannot remember what has happened. You look into a mirror.";
String classChoose = "What class are you?: warrior, mage, theif";
String error = "I cannot understand.";

//Actions
System.out.println(classIntro);
System.out.println(classChoose);
String answer = input.nextLine();

switch(answer){
case "warrior": case "Warrior": case "w": case "W":
main.path[0] = 0;
break;
case "mage": case "Mage": case "m": case "M":
main.path[0] = 1;
break;
case "theif": case "Theif": case "t": case "T":
main.path[0] = 2;
break;
default:
System.out.println(error);
classChoice();
return;

//Standard Answers
case "kill self":
System.out.println("You have died.");
}
}
}
Report Abuse
TearsofUnclarity is not online. TearsofUnclarity
Joined: 13 Dec 2011
Total Posts: 141
15 Dec 2011 07:57 AM
You never defined the table.
Report Abuse
haxu4life is not online. haxu4life
Joined: 02 Dec 2011
Total Posts: 10
15 Dec 2011 08:28 AM
You never declared what "main" is.
Report Abuse
LMBOX is not online. LMBOX
Joined: 04 Jun 2008
Total Posts: 8901
15 Dec 2011 03:51 PM
But how do I fix it? I am not understand what I do to fix it. Like, fix it for me, or tell me what to write for the line that needs fixing.
Report Abuse
TearsofUnclarity is not online. TearsofUnclarity
Joined: 13 Dec 2011
Total Posts: 141
15 Dec 2011 03:53 PM
You need to define the 'main' table. Look up tables in the Oracle site.

By the way, this sounds like an awesome idea. I would really want to help on something like this.
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
15 Dec 2011 04:27 PM
import java.util.Scanner;

public class textGame {
int path[] = new int[64];
    // Make your array a data field instead of a local variable

    public static void main(String args[]) {
        Scanner input = new Scanner(System.in);

        //Actions
        System.out.println("Text Game Indev by Liam Moran");
        System.out.println("----------------");

        classChoice();
    }

    public static void classChoice() {
        Scanner input = new Scanner(System.in);

        //Answers
        String classIntro = "You wake up in a prison. You cannot remember what has happened. You look into a mirror.";
        String classChoose = "What class are you?: warrior, mage, theif";
        String error = "I cannot understand.";

        //Actions
        System.out.println(classIntro);
        System.out.println(classChoose);
        String answer = input.nextLine();

        switch(answer){
            case "warrior": case "Warrior": case "w": case "W":
                main.path[0] = 0;
                break;
            case "mage": case "Mage": case "m": case "M":
                main.path[0] = 1;
                break;
            case "theif": case "Theif": case "t": case "T":
                main.path[0] = 2;
                break;
            default:
                System.out.println(error);
                classChoice();
                return;
        }

        //Standard Answers
        if (answer.equals("kill self")) {
            System.out.println("You have died.");
        }
    }
}



Using a switch statement, you can only use integers or characters.
Report Abuse
stravant is not online. stravant
Forum Moderator
Joined: 22 Oct 2007
Total Posts: 2893
15 Dec 2011 04:34 PM
"Using a switch statement, you can only use integers or characters."

Unless you've upgraded to Java7, which includes the big improvement of being able to switch over strings as well.
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
15 Dec 2011 04:36 PM
Java7 is out?
:o

I'm gonna have to update ....
Report Abuse
LMBOX is not online. LMBOX
Joined: 04 Jun 2008
Total Posts: 8901
15 Dec 2011 04:48 PM
Yeah, I can switch strings w/ my Java.
Report Abuse
LMBOX is not online. LMBOX
Joined: 04 Jun 2008
Total Posts: 8901
15 Dec 2011 04:56 PM
Okay, I tried your code Agent, but now I get this error:

error: non-static variable path cannot be referenced from a static context
Report Abuse
stravant is not online. stravant
Forum Moderator
Joined: 22 Oct 2007
Total Posts: 2893
15 Dec 2011 05:06 PM
Either make the path variable static or the rest of your code non-static.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image