Raised This Month: $ Target: $400
 0% 

For statement


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
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
 



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