Change Player target to target.
I recommend learning basic java first.
|
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?
Change Player target to target.
I recommend learning basic java first.
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:
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.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;
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 = "";
« Previous Thread | Next Thread » |
Thread Information |
Users Browsing this ThreadThere are currently 1 users browsing this thread. (0 members and 1 guests) |