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 |
|
|
|
| 15 Dec 2011 07:57 AM |
| You never defined the table. |
|
|
| Report Abuse |
|
|
haxu4life
|
  |
| Joined: 02 Dec 2011 |
| Total Posts: 10 |
|
|
| 15 Dec 2011 08:28 AM |
| You never declared what "main" is. |
|
|
| Report Abuse |
|
|
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 |
|
|
|
| 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 |
|
|
|
| 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
|
  |
 |
| 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 |
|
|
|
| 15 Dec 2011 04:36 PM |
Java7 is out? :o
I'm gonna have to update .... |
|
|
| Report Abuse |
|
|
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
|
  |
| 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
|
  |
 |
| 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 |
|
|