Writing the returned value of a function into an Array
#1

[EDIT] Simplified, hoping people will understand now.

I have a function that returns an Array of data, I have that function in an INC file, and i'm including it into a gamemode. Although, I can't get the Array returned by the function to the gamemode, this is what i'm doing :

pawn Код:
{LINE 30} new information[] = GetInformation();
But then I get the following errors :

Код:
main.pwn(30) : error 008: must be a constant expression; assumed zero
main.pwn(30) : error 036: empty statement
Long part with the function below.
__________________________________________________ _____________________________

pawn Код:
new first[128], second[128], third[128];

INI:servercfg[main](name[], value[])
{
    INI_String("first", first, sizeof (first));
    INI_String("second", second, sizeof (second));
    INI_String("third", third, sizeof (third));
    return 1;
}

stock GetInfo()
{
    enum Info
    {
        firstEX,
        secondEX,
        thirdEX,
    }
    new ServerInfo[Info];
    INI_Load("config.ini");
   
    strcat(ServerInfo[firstEX], first, sizeof(first));
    strcat(ServerInfo[secondEX], second, sizeof(second));
    strcat(ServerInfo[thirdEX], third, sizeof(third));
   
    return ServerInfo;
}
That's for the function (It's in an .inc), it seems to be working, but then I need to pass that information to a the gamemode, so i'm doing this :

pawn Код:
{LINE 30} new information[] = GetInformation();
But then I get the following errors :

Код:
main.pwn(30) : error 008: must be a constant expression; assumed zero
main.pwn(30) : error 036: empty statement
Line 30 is the unique line linking to the function in the gamemode.

I have tried many ways of doing it, such as specifying the lenght of the array, etc, nothing works.

Any help appreciated
Reply
#2

b00mp
Reply
#3

Sorry Delete please
Reply
#4

Arrays always needs to be passed by reference. i.e.
pawn Код:
stock GetInformation(array[], size = sizeof array)
{
    // Access array here
}
Usage:
pawn Код:
new information[20]; // must have a predefined size
GetInformation(information);
Reply
#5

Yeah that should work.

Just adding for the sake of learning, stocks don't give errors until you use them in your script (ie GetInformation) if you only have the stock it won't compile with errors. Also it makes no difference if you have it as an include or directly in your file, the compiler merges them it's only for the simplicity for the human eye.
Reply
#6

[EDIT] Wrong topic, my bad.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)