Raised This Month: $ Target: $400
 0% 

Code stops getting executed at a for loop


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
justincase
Senior Member
Join Date: Dec 2008
Old 06-21-2010 , 14:53   Code stops getting executed at a for loop
Reply With Quote #1

Well, I have another weird issue, the snippet says it all:

Code:
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).

Last edited by justincase; 06-21-2010 at 15:02.
justincase is offline
ot_207
Veteran Member
Join Date: Jan 2008
Location: Romania The Love Country
Old 06-21-2010 , 16:41   Re: Code stops getting executed at a for loop
Reply With Quote #2

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:
PHP Code:
new array[5]
for (new 
i=0;i<5;i++)
{
 
// DO TO array[i]

__________________
My approved plug-ins | Good for newbies! | Problems?

Back, will come around when I have time.
ot_207 is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 14:50.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode