SA-MP Forums Archive
Multidimensional arrays assigning - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Multidimensional arrays assigning (/showthread.php?tid=412252)



Multidimensional arrays assigning - Misiur - 01.02.2013

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?


AW: Multidimensional arrays assigning - Kwashiorkor - 01.02.2013

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.


Re: Multidimensional arrays assigning - Misiur - 01.02.2013

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