AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   For statement (https://forums.alliedmods.net/showthread.php?t=92077)

JProReTaRD 05-09-2009 17:14

For statement
 
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]

fysiks 05-09-2009 17:21

Re: For statement
 
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++
    } 


JProReTaRD 05-09-2009 17:30

Re: For statement
 
YES! Thank you very much for the fast and good reply! :)
You just saved my day.

+karma

Regards
[JPro] ReTaRD [ToY]

fysiks 05-09-2009 17:32

Re: For statement
 
Lucky timing I guess. I also just added a comment in my last post :).


All times are GMT -4. The time now is 01:33.

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