Results 1 to 4 of 4
  1. #1
    Kuetsum is offline Member
    Join Date
    Jan 2011
    Posts
    2
    Rep Power
    0

    Question Command not registering.

    I have a project that requires us to make a text based game.

    My game has a small talk method that only occurs between two characters. What is supposed to happen is that when you initiate the command by putting in "talk" which is changes a boolean variable to true which changes the available command words to only "help" and "say".

    The help command works but the say command does nothing. You are supposed to type say and a number out of a list of available sentences that prints out, but it will not work.

    The debugger suggests that the parser is skipping over the section in the code that uses the command while it is searching for available commands.

    Here is the section with the command:

    gui.println(commandLine);
    Command command = parser.getCommand(commandLine);

    if(command.isUnknown()) {
    gui.println("I don't know what you mean...");
    return;
    }

    String commandWord = command.getCommandWord();

    ...

    else if(player.getTalk() == true)
    {
    if (commandWord.equals("help")){
    gui.println(player.talkHelp());
    }
    else if (commandWord.equals("say"))
    gui.println(player.talking(command));
    }

    the first if (marked by the ...) before hand is if getTalk() is false and holds all of the regular commands.

    the talking command just takes the second word and if it equals 1,2,3,4, or 5 will print out the sentence.


    Sorry this is wordy but I wanted to fully explain.

  2. #2
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Location
    Destiny Islands
    Posts
    692
    Rep Power
    4

    Default

    Do you get errors? If so, please post full error contents & line numbers.

    Does the "gui.println(player.talking(command));" line never execute? I find this an unlikely issue, but if so, try adding println statements earlier on to see what commandWord is equivalent to.

    Does something weird print out? If so, what is the entire .talking() method?

  3. #3
    Kuetsum is offline Member
    Join Date
    Jan 2011
    Posts
    2
    Rep Power
    0

    Default Strange fix

    Quote Originally Posted by Zack View Post
    Do you get errors? If so, please post full error contents & line numbers.

    Does the "gui.println(player.talking(command));" line never execute? I find this an unlikely issue, but if so, try adding println statements earlier on to see what commandWord is equivalent to.

    Does something weird print out? If so, what is the entire .talking() method?
    There are no compiling errors, and the only thing that prints is the standard error message when the type entered doesn't match with an available command.

    the line does not execute at all, i've tried putting in a println before the command to see if was registering "Say" but that did not print. I also tried putting it in an else statement but that didn't work either.

    OK, i just put the command in the final else statement and I set the second word to be "1" for testing purposes and what happened is that if you typed in the old commands like "go north" then it would work, but if the text you entered did not equal an old command it displayed the error message.

    Talk is changed to true in this method:

    public void talk()
    {
    Talk = true;
    talkHelp(); //prints out commands
    getTalk(); //returns talk
    }

    Talking method:

    public String talking(Command command)
    {
    if (Talk = true){
    String x = command.getSecondWord();
    z = "";
    if(x.equals("1"))
    {
    z = "You: Who are you?" + "\n";
    Credits.sleep(500);
    z += "Ana: My name is Ana, you?";
    }
    else if(x.equals("2"))
    {
    z = "You: Do you know what's happening?" + "\n";
    Credits.sleep(500);
    z += "Ana: I have no idea! I don't know how I got here! \n I can't remeber a thing!";
    }
    else if(x.equals("3"))
    {
    z = "You: What were you doing?" + "\n";
    Credits.sleep(500);
    z += "Ana: I was searching this body for supplies.";
    }
    else if(x.equals("4"))
    {
    z = "You: Want to team up?" + "\n";
    Credits.sleep(500);
    z += "Ana: Sure! I could use the help. Let's go!";
    }
    else if(x.equals("5"))
    {
    z = "You: Goodbye." + "\n";
    Credits.sleep(500);
    z += "Ana: Alright.";
    Talk = false;
    y = 2;
    }
    else if((x.equals("1")) && (y == 2))
    {
    z = "You: How are you?" + "\n";
    Credits.sleep(500);
    z += "Ana: I'm doing alright.";
    }
    else if((x.equals("2")) && (y == 2))
    {
    z = "You: Goodbye." + "\n";
    Credits.sleep(500);
    z += "Ana: Alright.";
    Talk = false;
    }
    }
    else{}
    return z;
    }

    if i add "say" to the regular commands it works, but that's not what i wanted. I need the commands to change when talk becomes true.

  4. #4
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Location
    Destiny Islands
    Posts
    692
    Rep Power
    4

    Default

    There are no compiling errors, and the only thing that prints is the standard error message when the type entered doesn't match with an available command.
    Wait a second... you mean, it prints: "I don't know what you mean..."? That means that the isUnknown() method is the problem. The "say" command is probably not listed in that function as a known command.

Similar Threads

  1. Multiple email greetings on registering.
    By MadJack in forum Suggestions & Feedback
    Replies: 0
    Last Post: 09-26-2010, 11:05 PM
  2. JAX-RPC Registering a Client-Side Handler Problem
    By memzback in forum New To Java
    Replies: 0
    Last Post: 05-12-2010, 06:43 PM
  3. Registering problem
    By trini32 in forum New To Java
    Replies: 1
    Last Post: 06-25-2009, 04:35 AM
  4. command
    By dirtycash in forum New To Java
    Replies: 8
    Last Post: 01-02-2008, 07:52 PM
  5. Unable to execute command line command in java
    By LordSM in forum New To Java
    Replies: 1
    Last Post: 08-08-2007, 12:23 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •