PDA

View Full Version : Code stops getting executed at a for loop


justincase
06-21-2010, 14:53
Well, I have another weird issue, the snippet says it all:

public handleKey(id) {
new keys[4];
new keynames[4][16];

for (new x=0; x<=4; x++) {

keys[x] = random_num(0, 8);


switch(keys[x]) {
case 0: copy(keynames[x], 15, "MOUSE1");
case 1: copy(keynames[x], 15, "JUMP");
case 2: copy(keynames[x], 15, "CROUCH");
case 3: copy(keynames[x], 15, "FORWARD");
case 4: copy(keynames[x], 15, "BACK");
case 5: copy(keynames[x], 15, "USE");
case 6: { copy(keynames[x], 15, "MOVE LEFT"); keys[x] = 9; }
case 7: { copy(keynames[x], 15, "MOVE RIGHT"); keys[x] = 10; }
case 8: { copy(keynames[x], 15, "MOUSE2"); keys[x] = 11; }
}

client_print(0, print_chat, "A") // THIS GETS PRINTED OUT 4 TIMES INSTEAD OF 5 TIMES
}

client_print(0, print_chat, "FU"); // THIS DOESN'T GET PRINTED OUT

// CONCLUSION: THE WHOLE EXECUTION STOPS SUDDENDLY AFTER 4 ROUNDS
}What's the problem? Yet another weird issue like the last time where the script suddenly stopped executing when equipping the player with a ammo_556mm_box, LOL.


EDIT: Ok, when I make it one field larger (keys[5]), it works, but why is that needed? These aren't strings, and I only need 0, 1, 2, 3, 4 (total 5).

ot_207
06-21-2010, 16:41
The index can go up to 4.
When you declare an array with size 5 for example that means that you have 5 cells.
0,1,2,3,4

Ex:
new array[5]
for (new i=0;i<5;i++)
{
// DO TO array[i]
}