|
-
August 25th, 2011, 05:40 PM
#1
Can't seem to figure this out...
I just created an account to ask the users of this forum if they could figure out my problem.
So, let's get right into it. I'm coding a client for Minecraft.
First, I declared an ArrayList like so:
Code:
public ArrayList<Bind> binds = new ArrayList<Bind>();
Then, when the user types into a console "bind <key> <cmd>[;<cmd>]" it adds a Bind to the array list, like so:
Code:
if(s.startsWith("bind")) {
String[] args = s.split(" ");
if(args.length > 2) {
try {
String key = args[1].toUpperCase();
int kCode = Keyboard.getKeyIndex(key);
String cmd = "";
for(int i=2; i<args.length; i++) {
cmd += args[i] + " ";
}
boolean exists = false;
if(kCode != Keyboard.KEY_NONE) {
for(int i=0; i<binds.size(); i++) {
if(kCode == binds.get(i).keyCode) {
binds.set(i, new Bind(kCode, cmd));
mc.thePlayer.addChatMessage("Overwrote a bind!");
exists = true;
break;
}
}
}
if(!exists) {
binds.add(new Bind(kCode, cmd));
mc.thePlayer.addChatMessage(binds.get(binds.size() - 1).bind);
}
} catch (Exception e) { }
} else {
mc.thePlayer.addChatMessage("Syntax: bind <key> <cmd>[;<cmd>]");
}
}
All works fine, until I add another bind. After I add another it just sets both keys to do what the second one was set to do and I'm not sure. :|
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|