Reputation: 735
so I have the a script used in a game mod, the script allowed you to hit the up arrow to quickly view other messages that you previously typed out. It stores that ONE message as chat.previous. Is there a way to turn "chat.previous" into an array, then I can just use a for loop through that array everytime the up arrow is pushed down?
Here is the snippet of the script.
else if (event.which == 13 && chat.input != null) {
var value = chat.input.children("input").val();
if (value.length > 0) {
chat.previous = value;
if (value[0] == "/") {
value = value.substr(1);
if (value.length > 0 && value.length <= 100)
mp.invoke("command", value);
}
else {
if (value.length <= 100)
mp.invoke("chatMessage", value);
}
}
enableChatInput(false);
hide();
}
else if (event.which == 27 && chat.input != null) {
enableChatInput(false);
hide();
}
else if (event.which == 38 && chat.input != null) {
chat.input.children("input").val(chat.previous);
}
As you can see, when enter is pushed, it stores that chat message as chat.previous I would like to change it from being able to store only 1, to possibly storing 10. Then I should be able to FOR LOOP through the results. Please correct me if I am wrong.
Thanks guys.
Upvotes: 0
Views: 37
Reputation: 211540
Normally you can do this:
if (!chat.previous) {
chat.previous = [ ];
}
chat.previous.push(value);
Having something that might be an array is annoying to deal with. Make it consistently an array.
Upvotes: 1