Raised This Month: $51 Target: $400
 12% 

2d array index out of bounds


Post New Thread Reply   
 
Thread Tools Display Modes
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 12-01-2018 , 19:26   Re: 2d array index out of bounds
Reply With Quote #11

Using a non-dynamic array, you will need to size it to the max number you would ever possibly allow. Once they are loaded from db into array, just do a condition on the array to see if it holds data before adding to menu.

if ( achievements[i][name][ 0 ] )
__________________

Last edited by Bugsy; 12-01-2018 at 19:27.
Bugsy is offline
Croxeye.
Member
Join Date: Nov 2018
Old 12-01-2018 , 19:31   Re: 2d array index out of bounds
Reply With Quote #12

I set new variable 'totalAchievements' to SQL_NumResults value and I solve my problem
Croxeye. is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 12-01-2018 , 19:37   Re: 2d array index out of bounds
Reply With Quote #13

Your achievements array still needs to be sized based on what i said. But yes, num results will work for your menu
__________________
Bugsy is offline
Croxeye.
Member
Join Date: Nov 2018
Old 12-03-2018 , 18:12   Re: 2d array index out of bounds
Reply With Quote #14

Code:
error 032: array index out of bounds (variable "g_playerSkills")
PHP Code:
enum _:playerStatsTable {
    
kills,
    
deaths,
    
headshots,
    
score,
    
damage,
    
xp,
    
league,
    
timePlayed
}

new 
g_playerStats[33][playerStatsTable];

public 
client_connect(playerId) {
    if(!
is_user_bot(playerId) && !is_user_hltv(playerId)) {
        new 
Query[512], Data[1];
        
        
Data[0] = playerId;

        
formatex(Querycharsmax(Query), "SELECT * FROM `player_stats` WHERE `player`.`steam_id` = '%i'"g_player[playerId][steamId]);
        
SQL_ThreadQuery(MySQL_GlobalConnection"MySQL_LoadPlayerStats"QueryData1);
    }
}

public 
MySQL_LoadPlayerStats(FailState,Handle:SQL_Query,Error[],Errcode,Data[],DataSize) {
    if(
FailState == TQUERY_CONNECT_FAILED) {
        
console_print(0"Load - Could not connect to SQL database.  [%d] %s"ErrcodeError);
    } else if(
FailState == TQUERY_QUERY_FAILED) {
        
console_print(0"Load Query failed. [%d] %s"ErrcodeError);
    }
    
    new 
playerId;
    
    
playerId Data[0];

    if(
SQL_NumResults(SQL_Query) != 0) {
        
g_playerStats[playerId][kills] = SQL_ReadResult(SQL_Query1);
        
g_playerStats[playerId][deaths] = SQL_ReadResult(SQL_Query2);
        
g_playerStats[playerId][headshots] = SQL_ReadResult(SQL_Query3);
        
g_playerStats[playerId][score] = SQL_ReadResult(SQL_Query4);
        
g_playerStats[playerId][damage] = SQL_ReadResult(SQL_Query5);
        
g_playerStats[playerId][xp] = SQL_ReadResult(SQL_Query6); //error only here
        
g_playerStats[playerId][league] = SQL_ReadResult(SQL_Query5);
    }


Last edited by Croxeye.; 12-04-2018 at 10:15. Reason: full code
Croxeye. is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 12-03-2018 , 18:54   Re: 2d array index out of bounds
Reply With Quote #15

That is not your error as that line of code does not reference g_playerSkills.

If you want help, you need to post your full code.
__________________
Bugsy is offline
Croxeye.
Member
Join Date: Nov 2018
Old 12-04-2018 , 10:16   Re: 2d array index out of bounds
Reply With Quote #16

ok I edited post before
Croxeye. is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 12-04-2018 , 11:29   Re: 2d array index out of bounds
Reply With Quote #17

Is there no g_playerSkills in the code you provided.
__________________








CrazY. is offline
Croxeye.
Member
Join Date: Nov 2018
Old 12-04-2018 , 14:01   Re: 2d array index out of bounds
Reply With Quote #18

Yeah.. I copied wrong error but it's same for stats and skills
Croxeye. 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 07:05.


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