AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Solved [PROBLEM] Array sizes do not match (https://forums.alliedmods.net/showthread.php?t=314128)

axelnieves2012 02-04-2019 17:55

[PROBLEM] Array sizes do not match
 
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?

axelnieves2012 02-04-2019 18:01

Re: [PROBLEM] Array sizes do not match
 
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

asherkin 02-05-2019 06:00

Re: [PROBLEM] Array sizes do not match
 
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.

axelnieves2012 02-05-2019 16:02

Re: [PROBLEM] Array sizes do not match
 
Quote:

Originally Posted by asherkin (Post 2638245)
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 02-05-2019 16:05

Re: [PROBLEM] Array sizes do not match
 
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];




All times are GMT -4. The time now is 14:55.

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