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

Solved [PROBLEM] Array sizes do not match


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
axelnieves2012
Senior Member
Join Date: Oct 2014
Location: Argentina
Old 02-04-2019 , 17:55   [PROBLEM] Array sizes do not match
Reply With Quote #1

Hello, can anyone help me to find what am I doing wrong?
My plugin doesnt compile for some weird reason I can't understand.

PHP Code:
#include <sourcemod>
#include <sdkhooks>
#include <sdktools>
#pragma semicolon 1
#define    DEBUG    0

#define TEAM_SURVIVOR    2
#define TEAM_INFECTED    3

#define FLAGS_SURVIVOR    1
#define FLAGS_INFECTED    2
#define FLAGS_ALIVE        4
#define FLAGS_DEAD        8
#define PLUGIN_VERSION    "1.0.0"

char L4D1_Z_CLASSES[6][8]     =    {"""Smoker""Boomer""Hunter""Witch""Tank"};
char L4D1_S_CLASSES[4][8]    =    {"Bill""Zoey""Francis""Louis"};
char L4D2_Z_CLASSES[9][8]    =    {"""Smoker""Boomer""Hunter""Spitter""Jockey""Charger""Witch""Tank"};
char L4D2_S_CLASSES[8][9]    =    {"Nick""Rochelle""Coach""Ellis""Bill""Zoey""Francis""Louis"};

new 
left4dead;

//SOME CODE HERE BLABLABLA

char[] StrGetZombieClass(zombie)
{
    if (
left4dead==1)
        return 
L4D1_Z_CLASSES[zombie];
    else
        return 
L4D2_Z_CLASSES[zombie];
}

char[] StrGetSurvivorClass(survivor)
{
    if (
left4dead==1)
        return 
L4D1_S_CLASSES[survivor];
    else
        return 
L4D2_S_CLASSES[survivor]; //ERROR HERE, IN THIS LINE

Error 047: array sizes do not match, or destination array is too small.


I can't understand why I am getting this error. I was not getting this error with zombie classes.
It was compiling alright.
I got this error when I added survivor classes.
If I remove that line, plugin compiles. But I need to return Survivor names as string.
And I dont think checking model is a good idea because I have joined server where survivors were using witch and tank models.

Any idea what's is wrong with my array?

Last edited by axelnieves2012; 02-05-2019 at 16:03.
axelnieves2012 is offline
axelnieves2012
Senior Member
Join Date: Oct 2014
Location: Argentina
Old 02-04-2019 , 18:01   Re: [PROBLEM] Array sizes do not match
Reply With Quote #2

I think Sourcemod is crazy (bugged).

If I do this:
PHP Code:
char[] StrGetSurvivorClass(survivor)
{
    if (
left4dead==1)
        return 
L4D2_S_CLASSES[survivor];
    else
        return 
L4D2_S_CLASSES[survivor];

Plugin compiles. May Sourcemod 1.9 be bugged? I will try online compiler.

EDIT: Online compiler failed too

Last edited by axelnieves2012; 02-04-2019 at 21:12.
axelnieves2012 is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 02-05-2019 , 06:00   Re: [PROBLEM] Array sizes do not match
Reply With Quote #3

Code:
char L4D1_S_CLASSES[4][8]    =    {"Bill", "Zoey", "Francis", "Louis"}; 
char L4D2_S_CLASSES[8][9]    =    {"Nick", "Rochelle", "Coach", "Ellis", "Bill", "Zoey", "Francis", "Louis"};
8 != 9, all branches returning arrays need to have the same size.
Change the L4D1_S_CLASSES inner length to 9 and everything will be fine.
__________________
asherkin is offline
axelnieves2012
Senior Member
Join Date: Oct 2014
Location: Argentina
Old 02-05-2019 , 16:02   Re: [PROBLEM] Array sizes do not match
Reply With Quote #4

Quote:
Originally Posted by asherkin View Post
Code:
char L4D1_S_CLASSES[4][8]    =    {"Bill", "Zoey", "Francis", "Louis"}; 
char L4D2_S_CLASSES[8][9]    =    {"Nick", "Rochelle", "Coach", "Ellis", "Bill", "Zoey", "Francis", "Louis"};
8 != 9, all branches returning arrays need to have the same size.
Change the L4D1_S_CLASSES inner length to 9 and everything will be fine.
Thanks you. I didn't know about that rule.
I've seen it before in Motorola's 68000 assembly language, but I think I forgot it.
axelnieves2012 is offline
axelnieves2012
Senior Member
Join Date: Oct 2014
Location: Argentina
Old 02-05-2019 , 16:05   Re: [PROBLEM] Array sizes do not match
Reply With Quote #5

Solved by Asherkin:

PHP Code:
#include <sourcemod>
#include <sdkhooks>
#include <sdktools>
#pragma semicolon 1
#define    DEBUG    0

#define TEAM_SURVIVOR    2
#define TEAM_INFECTED    3

#define FLAGS_SURVIVOR    1
#define FLAGS_INFECTED    2
#define FLAGS_ALIVE        4
#define FLAGS_DEAD        8
#define PLUGIN_VERSION    "1.0.0"

char L4D1_Z_CLASSES[6][8]     =    {"""Smoker""Boomer""Hunter""Witch""Tank"};
char L4D1_S_CLASSES[4][8]    =    {"Bill""Zoey""Francis""Louis"};
char L4D2_Z_CLASSES[9][9]    =    {"""Smoker""Boomer""Hunter""Spitter""Jockey""Charger""Witch""Tank"}; //THIS LINE WAS WRONG. NOW IT IS RIGHT
char L4D2_S_CLASSES[8][9]    =    {"Nick""Rochelle""Coach""Ellis""Bill""Zoey""Francis""Louis"};

new 
left4dead;

//SOME CODE HERE BLABLABLA

char[] StrGetZombieClass(zombie)
{
    if (
left4dead==1)
        return 
L4D1_Z_CLASSES[zombie];
    else
        return 
L4D2_Z_CLASSES[zombie];
}

char[] StrGetSurvivorClass(survivor)
{
    if (
left4dead==1)
        return 
L4D1_S_CLASSES[survivor];
    else
        return 
L4D2_S_CLASSES[survivor];

axelnieves2012 is offline
Reply


Thread Tools
Display Modes

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 09:45.


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