Raised This Month: $ Target: $400
 0% 

For statement


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
JProReTaRD
Member
Join Date: May 2009
Location: Denmark, KBH
Old 05-09-2009 , 17:14   For statement
Reply With Quote #1

Hi, I am building building an xp mod with some classes, but I can't seem to get it working.

It should be loading xp and lvl from each class, and it's this sentence that is wrong:
PHP Code:
format(vaultkey,63,"Jumper-%s-%i-xp",authid,CLASSES[sum]); 
and it's the %i and the CLASSES[sum].

I really hope someone can help me

When I compile it doesn't point out any errors, but when I run it on debug it says:

Code:
L 05/09/2009 - 20:53:35: [AMXX] Displaying debug trace (plugin "xp-mod.amxx")
L 05/09/2009 - 20:53:35: [AMXX] Run time error 4: index out of bounds 
L 05/09/2009 - 20:53:35: [AMXX]    [0] xp-mod.sma::LoadXP (line 103)
L 05/09/2009 - 20:53:35: [AMXX]    [1] xp-mod.sma::client_connect (line 120)
L 05/09/2009 - 20:53:35: [admin.amxx] Login: "[JPro] ReTaRD [ToY]<14><>" became an admin (account "STEAM_0:0:22688377") (access "abcdefghijklmnopqrstu") (address "217.60.224.194")
L 05/09/2009 - 20:53:43: [AMXX] Displaying debug trace (plugin "xp-mod.amxx")
L 05/09/2009 - 20:53:43: [AMXX] Run time error 4: index out of bounds 
L 05/09/2009 - 20:53:43: [AMXX]    [0] xp-mod.sma::LoadXP (line 103)
L 05/09/2009 - 20:53:43: [AMXX]    [1] xp-mod.sma::ChooseJumper (line 147)
PHP Code:
#define MAXCLASSES 5

new const CLASSES[MAXCLASSES][] = {
     
"None",
     
"Jumper",
     
"BHopper",
     
"CHopper",
     
"Noob" 

PHP Code:
public LoadXP(id)
{
    new 
authid[32]; 
    
get_user_authid(id,authid,31);

    new 
vaultkey[64], vaultdata[64]; 
    
    new 
i
    
new sum;
 
    for (
i=1i<=MAXCLASSESi++)
    {
               
//Load their XP
               
format(vaultkey,63,"Jumper-%s-%i-xp",authid,CLASSES[sum]); 
               
get_vaultdata(vaultkey,vaultdata,63); 
               
PlayerXP[id] = str_to_num(vaultdata);   

               
//Load their level
               
format(vaultkey,63,"Jumper-%s-%i-level",authid,CLASSES[sum]); 
               
get_vaultdata(vaultkey,vaultdata,63);
               
PlayerLevel[id] = str_to_num(vaultdata);
               
sum += i;
    }

Regards
[JPro] ReTaRD [ToY]

Last edited by JProReTaRD; 05-09-2009 at 17:18.
JProReTaRD is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 05-09-2009 , 17:21   Re: For statement
Reply With Quote #2

Array indices are zero based. A valid index is 0,1,2,3, or 4. The first code here is more efficient and you don't need a sum if the number of iterations is hardcoded.

PHP Code:
    new 

    
for (0MAXCLASSESi++)
    { 
        
//Load their XP
        
format(vaultkey,63,"Jumper-%s-%i-xp",authid,CLASSES[i]);
        
get_vaultdata(vaultkey,vaultdata,63);
        
PlayerXP[id] = str_to_num(vaultdata);

        
//Load their level
        
format(vaultkey,63,"Jumper-%s-%i-level",authid,CLASSES[i]);
        
get_vaultdata(vaultkey,vaultdata,63);
        
PlayerLevel[id] = str_to_num(vaultdata);
    } 
or

PHP Code:
    new i
    
new sum 0

    
for (0MAXCLASSESi++)
    {
        
//Load their XP
        
format(vaultkey,63,"Jumper-%s-%i-xp",authid,CLASSES[sum]);
        
get_vaultdata(vaultkey,vaultdata,63);
        
PlayerXP[id] = str_to_num(vaultdata);

        
//Load their level
        
format(vaultkey,63,"Jumper-%s-%i-level",authid,CLASSES[sum]);
        
get_vaultdata(vaultkey,vaultdata,63);
        
PlayerLevel[id] = str_to_num(vaultdata);
        
sum++
    } 

Last edited by fysiks; 05-09-2009 at 17:31.
fysiks is offline
JProReTaRD
Member
Join Date: May 2009
Location: Denmark, KBH
Old 05-09-2009 , 17:30   Re: For statement
Reply With Quote #3

YES! Thank you very much for the fast and good reply!
You just saved my day.

+karma

Regards
[JPro] ReTaRD [ToY]
JProReTaRD is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 05-09-2009 , 17:32   Re: For statement
Reply With Quote #4

Lucky timing I guess. I also just added a comment in my last post .
__________________
fysiks 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 01:33.


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