Multidimensional arrays assigning
#1

Good lord, I didn't have occasion to code lately and I forget the basics. Anyway, here's piece of code:

pawn Код:
#define MAX_ALLOWED_CARGOS 26

enum NS-><CargoTypes> {
    id,
    name[SHORT_STRING],
    weightRange[2],
    carsPermitted[MAX_VEHICLE_TYPES]
};

new NS-><Cargos[MAX_ALLOWED_CARGOS][NS-><CargoTypes>]>;
NS-><Cargos[0]> = { 1, "Hello", { 1, 2 }, {1} };
Here's the same code after preprocessing (these are simple macros for namespacing includes)

pawn Код:
enum Modules__Cargo__CargoTypes {
    id,
    name[64],
    weightRange[2],
    carsPermitted[8]
};

new Modules__Cargo__Cargos[26][Modules__Cargo__CargoTypes];
Modules__Cargo__Cargos[0] = { 1, "Hello", { 1, 2 }, {1} };
Modules__Cargo__Cargos[1] = { 2, "Hello", { 1, 2 }, {1} };
Now I get invalid function or declaration error line starting with "Modules__Cargo__Cargos[0]".

This code on the other hand:
pawn Код:
new Modules__Cargo__Cargos[26][Modules__Cargo__CargoTypes] = {
    { 1, "Hello", { 1, 2 }, {1} };
    { 2, "Hello", { 1, 2 }, {1} };
};
will work as planned. I don't want to use this syntax due to further complications. Can someone tell my where am I making a mistake?
Reply
#2

you can either use initializing values
pawn Код:
new Modules__Cargo__Cargos[26][Modules__Cargo__CargoTypes] = {
    { 1, "Hello", { 1, 2 }, {1} };
    { 2, "Hello", { 1, 2 }, {1} };
};
or assign values in a callback/function like OnGameModeInit
pawn Код:
public OnGameModeInit()
{
Modules__Cargo__Cargos[0] = { 1, "Hello", { 1, 2 }, {1} };
Modules__Cargo__Cargos[1] = { 2, "Hello", { 1, 2 }, {1} };
}
but you can not assign values outside of a function.
Reply
#3

Hah, thinking in modules sometimes causes confusion. Thank you guys.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)