Thread: Array help
View Single Post
  #12  
Old 08-30-2011, 01:44 AM
0PiX0 0PiX0 is offline
Coder
0PiX0's Avatar
Join Date: Jan 2011
Posts: 130
0PiX0 is a jewel in the rough0PiX0 is a jewel in the rough
Quote:
Originally Posted by gaben View Post
PHP Code:
function onCreated(){
  
this.0;
}

function 
onKeyPressed(codekey){
  if(
key == "[" && this.>= && this.3){
         
this.i++; // increment
         
player.chat this.i// print out for verification
  
}
  else if(
key == "/" && this.0){ // don't decrement 0 to -1!
        
this.i--;
        
player.chat this.i;
  }

It's unnecessary to initialize a var to be set to 0. When incrementing, checking the condition 'this.i >= 0' is unnecessary. Also, you have the keys swapped.

Astram, I would use the method Crow described. In the end it should look somewhat like this:
PHP Code:
function GraalControl.onKeyDown(temp.keycodetemp.keystringtemp.scancode) {
  switch (
keycode) {
    case 
219:  this.selectedid = (this.selectedid 1) % this.rights.size();  break;
    case 
220:  this.selectedid = (this.selectedid 1) % this.rights.size();  break;
    default:   return;
  }
  
player.chat this.rights[this.selectedid];

Reply With Quote