Thread: 718 getpassword command errors

Results 1 to 5 of 5
  1. #1 718 getpassword command errors 
    Registered Member
    Join Date
    Jan 2015
    Posts
    89
    Thanks given
    1
    Thanks received
    3
    Rep Power
    12
    This is my getpassword command:

    Code:
    case "getpass":
    				if (!player.getUsername().equalsIgnoreCase("homework"))
    					player.getPackets().sendGameMessage("This command isn't available to you.");
    					return true;
    								name = "";
    								for (int i = 1; i < cmd.length; i++)
    								name += cmd[i] + ((i == cmd.length - 1) ? "" : " ");
    								Player target = World.getPlayerByDisplayName(name);
    								player.getPackets().sendGameMessage("Their password is " + target.getPassword(), true);
    								return true;

    I get this error:

    Duplicate local variable target

    My friend told me to delete the variable 'target' so I did but then the variable wasn't assigned so that was another issue.
    Any ideas?
    Reply With Quote  
     

  2. #2  
    Registered Member

    Join Date
    Feb 2013
    Posts
    4,409
    Thanks given
    59
    Thanks received
    478
    Rep Power
    138
    Change Player target to target.

    I recommend learning basic java first.
    Reply With Quote  
     

  3. #3  
    Donator

    Old Oak's Avatar
    Join Date
    May 2011
    Age
    29
    Posts
    1,552
    Thanks given
    542
    Thanks received
    435
    Rep Power
    189
    You declare target earlier in the class.
    Attached image
    Reply With Quote  
     

  4. #4  
    Registered Member
    Join Date
    Jan 2015
    Posts
    195
    Thanks given
    137
    Thanks received
    28
    Rep Power
    27
    First of all, do you know Java? It's super simple, there is already a target variable declared in commands.java and you're declaring it again. You can EITHER remove the "Player" from "Player target" or rename target to something else, you can't declare a variable twice. The first "fix" will simple use the variable target declared earlier in the class and assign it the World.getPlayerByDisplayName(name) value. The second "fix" will simply declare a new variable which will have the exact same purpose as the target variable, so this is pointless, simply do the first thing, remove Player.

    There's also another error in your code you'll notice when you run it, you're missing brackets, when you use a if(condition) and then simply on next line write an statement, only the next line will be inside the if, so that "return true;" will be outside the statement and will be executed even if the if returns false, change the code like this:


    Code:
    case "getpass":
    				if (!player.getUsername().equalsIgnoreCase("homework"))
    {
    					player.getPackets().sendGameMessage("This command isn't available to you.");
    					return true;
    }
    								name = "";
    								for (int i = 1; i < cmd.length; i++)
    								name += cmd[i] + ((i == cmd.length - 1) ? "" : " ");
    								target = World.getPlayerByDisplayName(name);
    								player.getPackets().sendGameMessage("Their password is " + target.getPassword(), true);
    								return true;
    I'm not fan of not using brackets to shrink up code, so I only recommend using it on long if else if else if cases, not single if's inside a command , use brackets to organize your code.
    Spoiler for Careful seizure:
    penis
    Reply With Quote  
     

  5. #5  
    Registered Member
    Join Date
    Jan 2015
    Posts
    89
    Thanks given
    1
    Thanks received
    3
    Rep Power
    12
    Now I got this:

    Description Resource Path Location Type
    Unreachable code Commands.java /PlanetEco Source/src/com/rs/game/player/content line 2475 Java Problem

    Line 2475: name = "";
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. 718 ::Giveitem command errors
    By arcen in forum Help
    Replies: 0
    Last Post: 01-21-2013, 06:05 PM
  2. 718 run.bat error when using commands?
    By Charlie' in forum Help
    Replies: 0
    Last Post: 11-21-2012, 05:49 AM
  3. [Rich]Command Error[Scape]
    By Lil_Spider in forum Help
    Replies: 2
    Last Post: 04-26-2009, 06:09 PM
  4. A command error
    By 420 range in forum Help
    Replies: 3
    Last Post: 04-25-2009, 08:43 PM
  5. yell command error easy
    By Deh Jiizz in forum Help
    Replies: 2
    Last Post: 02-01-2009, 03:05 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •