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

Array problem


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
NoTiCE
Junior Member
Join Date: May 2012
Location: Lviv, Ukraine
Old 11-14-2016 , 12:48   Array problem
Reply With Quote #1

Hello! I have problem with char array
PHP Code:
public void OnPluginStart()
{
    
RegServerCmd("test"Cmd_Test);
}

public 
Action Cmd_Test(int args)
{
    
char szItems[][][] = 
    {
        {
"Auto""sm_arec"},
        {
"Low""sm_recordlow"},
        {
"Sideways""sm_recsw"},
        {
"HalfSW""sm_rechsw"},
        {
"SurfHSW""sm_recrhsw"},
        {
"W-Only""sm_recwonly"},
        {
"A-Only""sm_recaonly"},
        {
"D-Only""sm_recdonly"},
        {
"Legit""sm_recl"},
        {
"Cap""sm_reccap"},
        {
"Legit Cap""sm_reclcap"}
    };
    
    
int iSize sizeof(szItems);
    for (
int i 0iSizei++)
        
PrintToServer("%s: %s"szItems[i][0], szItems[i][1]);
    
    return 
Plugin_Handled;


This problem occurs when the array contains "sm_r" substring
How to solve?
NoTiCE is offline
OSWO
Senior Member
Join Date: Jul 2015
Location: United Kingdom, London
Old 11-14-2016 , 13:12   Re: Array problem
Reply With Quote #2

try setting the char size? [][2][128]? :/
__________________
SourceTimer | WeaponSkins++ | BasePlugins++ https://github.com/OSCAR-WOS
OSWO is offline
8guawong
AlliedModders Donor
Join Date: Dec 2013
Location: BlackMarke7
Old 11-14-2016 , 13:30   Re: Array problem
Reply With Quote #3

try sizeof(szItems[]) or sizeof(szItems[][])
and this belongs in scripting section
__________________
8guawong is offline
NoTiCE
Junior Member
Join Date: May 2012
Location: Lviv, Ukraine
Old 11-14-2016 , 13:52   Re: Array problem
Reply With Quote #4

Code:
int iSize = sizeof(szItems);
int iSize2 = sizeof(szItems[]);
int iSize3 = sizeof(szItems[][]);

PrintToServer("[%d][%d][%d]", iSize, iSize2, iSize3);


This problem occurs when the array contains "sm_r" substring
In other cases, all is well
NoTiCE is offline
Timocop
AlliedModders Donor
Join Date: Mar 2013
Location: Germany
Old 11-14-2016 , 16:16   Re: Array problem
Reply With Quote #5

This is a known compiler bug (https://github.com/alliedmodders/sou...c135a1a857af02 and https://github.com/alliedmodders/sou...ebab3ad8cc13ce i think)

You have 3 options:
  • Get the latest SourceMod 1.9 dev compiler where the bug has been fixed.
  • Constant array size. e.g array[][][128]
  • Get a pizza
PHP Code:
 public void OnPluginStart() 

    
RegServerCmd("test"Cmd_Test); 


public 
Action Cmd_Test(int args

    
char szItems[][][128] =  
    { 
        {
"Auto""sm_arec"}, 
        {
"Low""sm_recordlow"}, 
        {
"Sideways""sm_recsw"}, 
        {
"HalfSW""sm_rechsw"}, 
        {
"SurfHSW""sm_recrhsw"}, 
        {
"W-Only""sm_recwonly"}, 
        {
"A-Only""sm_recaonly"}, 
        {
"D-Only""sm_recdonly"}, 
        {
"Legit""sm_recl"}, 
        {
"Cap""sm_reccap"}, 
        {
"Legit Cap""sm_reclcap"
    }; 
     
    
int iSize sizeof(szItems); 
    for (
int i 0iSizei++) 
        
PrintToServer("%s: %s"szItems[i][0], szItems[i][1]); 
     
    return 
Plugin_Handled


Last edited by Timocop; 11-14-2016 at 16:27.
Timocop 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 08:01.


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