Raised This Month: $32 Target: $400
 8% 

[SOLVED] Array sizes do not match, or destination array is too small


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
^SmileY
Veteran Member
Join Date: Jan 2010
Location: Brazil [<o>]
Old 01-29-2019 , 07:15   [SOLVED] Array sizes do not match, or destination array is too small
Reply With Quote #1

Hi, i having problems on compile a test plugin:

PHP Code:
#include <amxmodx>
#include <csstats>
#include <csx>

#include <PugCore>
#include <PugStocks>

enum _:pStats
{
    
Auth[MAX_AUTHID_LENGTH],
    
Name[MAX_NAME_LENGTH],
    
Stats[STATSX_MAX_STATS],
    
Body[MAX_BODYHITS],
    
Objective[STATSX_MAX_OBJECTIVE]
};

new 
g_Stats[33][pStats];

public 
plugin_init()
{
    
register_plugin("Pug Mod (Stats)",PUG_VERSION,PUG_AUTHOR);
    
    
register_concmd("teste","cmdTeste");
}

public 
cmdTeste(id)
{
    new 
StatsNum get_statsnum();
    
    for(new 
i;StatsNum;i++)
    {
        
get_stats2(i,g_Stats[i][Objective]);
        
        
server_print("(%s) (%s) Shots %d",g_Stats[i][Name],g_Stats[i][Auth],g_Stats[i][STATSX_SHOTS]);
    }

Code:
AMX Mod X Compiler 1.9.0.5235
Copyright (c) 1997-2006 ITB CompuPhase
Copyright (c) 2004-2013 AMX Mod X Team

Error: Array sizes do not match, or destination array is too small on line 32

1 Error.
Could not locate output file D:\Steam\steamapps\common\Half-Life\cstrike\addons\amxmodx\plugins\PugStats.amx (compile failed).
I know that g_Stats[i][Objective] is same as g_Stats[i][4], and get_stats2 needs to be STATSX_MAX_OBJECTIVE, but how use like an struct?

Thanks for help
__________________
Projects:

- See my Git Hub: https://github.com/SmileYzn
PHP Code:
set_pcvar_num(pCvar, !get_pcvar_num(pCvar)); 
^SmileY is offline
Send a message via MSN to ^SmileY Send a message via Skype™ to ^SmileY
Old 01-29-2019, 13:04
edon1337
This message has been deleted by edon1337.
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 01-29-2019 , 13:33   Re: Array sizes do not match, or destination array is too small
Reply With Quote #2

Code:
#include <amxmodx> #include <csstats> new g_Objective[33][STATSX_MAX_OBJECTIVE]; public plugin_init() {     register_plugin("Plugin", "Version", "Author");     new i, iStatsNum;     iStatsNum = min(get_statsnum(), sizeof g_Objective);     for (i = 0; i < iStatsNum; i++)     {         get_stats2(i, g_Objective[i]);         server_print("Stats[%d]^nTOTAL_DEFUSIONS=%d^nBOMBS_DEFUSED=%d^nBOMBS_PLANTED=%d^nBOMB_EXPLOSIONS=%d^n", i, g_Objective[i][STATSX_TOTAL_DEFUSIONS], g_Objective[i][STATSX_BOMBS_DEFUSED], g_Objective[i][STATSX_BOMBS_PLANTED], g_Objective[i][STATSX_BOMB_EXPLOSIONS])     } }
__________________









Last edited by CrazY.; 01-29-2019 at 13:46.
CrazY. is offline
^SmileY
Veteran Member
Join Date: Jan 2010
Location: Brazil [<o>]
Old 01-29-2019 , 14:41   Re: Array sizes do not match, or destination array is too small
Reply With Quote #3

@edon1337 Will not solve the error

@CrazY. The main idea is use enum, thanks anyway

Ps.
Any ideias?
__________________
Projects:

- See my Git Hub: https://github.com/SmileYzn
PHP Code:
set_pcvar_num(pCvar, !get_pcvar_num(pCvar)); 
^SmileY is offline
Send a message via MSN to ^SmileY Send a message via Skype™ to ^SmileY
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 01-29-2019 , 15:44   Re: Array sizes do not match, or destination array is too small
Reply With Quote #4

Quote:
Originally Posted by edon1337 View Post
PHP Code:
enum _:pStats 

    
Auth[MAX_AUTHID_LENGTH], 
    
Name[MAX_NAME_LENGTH], 
    
Stats[STATSX_MAX_STATS], 
    
Body[MAX_BODYHITS], 
    
Objective[STATSX_MAX_OBJECTIVE
}; 
-->

PHP Code:
enum _:pStats 

    
Auth[64], 
    
Name[64], 
    
Stats[64], 
    
Body[64], 
    
Objective[64
}; 
What's the difference? Why are you suggesting him to use magic numbers (also with wrong values) instead of the newly defined constants in 1.9? That is very bad advice.

On topic: try get_stats2(i, g_Stats[][Objective]).
__________________

Last edited by OciXCrom; 01-29-2019 at 15:46.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Old 01-29-2019, 18:10
Bugsy
This message has been deleted by Bugsy.
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 01-29-2019 , 18:19   Re: Array sizes do not match, or destination array is too small
Reply With Quote #5

get_stats() and get_stats2() retrieve data from csstats.dat, it is not always associated with a player who is actively on your server. I am pointing this out because you have this: new g_Stats[33][pStats];

Take a look at this: https://forums.alliedmods.net/showpo...80&postcount=5
__________________
Bugsy is offline
^SmileY
Veteran Member
Join Date: Jan 2010
Location: Brazil [<o>]
Old 01-29-2019 , 20:45   Re: Array sizes do not match, or destination array is too small
Reply With Quote #6

Quote:
Originally Posted by Bugsy View Post
get_stats() and get_stats2() retrieve data from csstats.dat, it is not always associated with a player who is actively on your server. I am pointing this out because you have this: new g_Stats[33][pStats];

Take a look at this: https://forums.alliedmods.net/showpo...80&postcount=5
Thanks, but is not this, i plan to reset stats in every map changes, also current map will not have more players enter/exiting than 33 etc. Soo it is not for each player, but create a struct for it.

I take a look in your plugin, also i need to store in array first since i will try to send using curl, mysql or sockets to a web server

Thanks again
__________________
Projects:

- See my Git Hub: https://github.com/SmileYzn
PHP Code:
set_pcvar_num(pCvar, !get_pcvar_num(pCvar)); 
^SmileY is offline
Send a message via MSN to ^SmileY Send a message via Skype™ to ^SmileY
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 01-29-2019 , 20:55   Re: Array sizes do not match, or destination array is too small
Reply With Quote #7

Your usage looks correct to me, but the compiler is temperamental sometimes when passing enumerator sized arrays to a function. Save yourself the headache and use individual arrays for stats and stats2, as I did in my linked plugin/thread. There's no need/benefit that I can think of to pack it all into an array.

get_stats2(i,g_Stats[i][Objective]);
__________________
Bugsy is offline
^SmileY
Veteran Member
Join Date: Jan 2010
Location: Brazil [<o>]
Old 01-29-2019 , 21:30   Re: Array sizes do not match, or destination array is too small
Reply With Quote #8

Yes, that will be the solution.

Thanks again
__________________
Projects:

- See my Git Hub: https://github.com/SmileYzn
PHP Code:
set_pcvar_num(pCvar, !get_pcvar_num(pCvar)); 
^SmileY is offline
Send a message via MSN to ^SmileY Send a message via Skype™ to ^SmileY
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 01-30-2019 , 08:12   Re: Array sizes do not match, or destination array is too small
Reply With Quote #9

Quote:
Originally Posted by OciXCrom View Post
What's the difference? Why are you suggesting him to use magic numbers (also with wrong values) instead of the newly defined constants in 1.9? That is very bad advice.

On topic: try get_stats2(i, g_Stats[][Objective]).
I didn't know the values of these defines that he used so I randomly used 64.
I thought he had the same problem as me in this code:

If for example you change AIRDROP_CLASSNAME to 63 meanwhile the destination is declared as 64 it would throw same error as him, just a little misunderstanding.

PHP Code:
enum _:Config
{
    
AIRDROP_CLASSNAME64 ],
    
AIRPLANE_CLASSNAME64 ],
    
GAME_SOUNDS_FILE64 ],
    
GAME_MODELS_FILE64 ],
    
GAME_WEAPONS_FILE64 ],
    
PLANE_ORIGINS_FILE64 ],
    
GAME_CUSTOM_SPAWN_POINTS_FILE64 ],
    
ARROW_ICON_SPRITE64 ],
    
AUTO_POINTS_FILE64 ],
    
ZONE_ORIGINS_FILE64 ]
};

ReadConfig( )
{
    new 
szFilename256 ];
    
formatexszFilenamecharsmaxszFilename ), "%s/%s/%s"g_szConfigsDirPATH_MANAGMENTCSBR_Config_File );
    
    new 
iFile fopenszFilename"rt" );
    
    if( 
iFile )
    {
        new 
szData128 ], szValue64 ], szKey64 ];
        }
        ...

__________________
edon1337 is offline
^SmileY
Veteran Member
Join Date: Jan 2010
Location: Brazil [<o>]
Old 01-30-2019 , 08:37   Re: Array sizes do not match, or destination array is too small
Reply With Quote #10

get_stats2 have a fixed array for parameter. that is why im having troubles.

The solution is use as separated array, or just use a copy() to copy into the struct.
__________________
Projects:

- See my Git Hub: https://github.com/SmileYzn
PHP Code:
set_pcvar_num(pCvar, !get_pcvar_num(pCvar)); 
^SmileY is offline
Send a message via MSN to ^SmileY Send a message via Skype™ to ^SmileY
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 21:58.


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