SA-MP Forums Archive
[HELP] How to make a dynamic array? - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: [HELP] How to make a dynamic array? (/showthread.php?tid=147988)



[HELP] How to make a dynamic array? - LTomi - 15.05.2010

Hi!
I tried many ways but I couldn't give an array a dynamically changing size. I got a CarInfo variable with the 268 and cInfo parameters that looks like CarInfo[268][cInfo]. I would like to replace 268 with a variable called CarNumber, but the pawno always goes mad at compiling. The CarNumber variable is read from a file when the gamemode is started. Is there any way to solve this issue?


Re: [HELP] How to make a dynamic array? - juice.j - 15.05.2010

Not that I know, however you could just create a definitions file you include into your script where you define the array sizes.

Код:
def_arr.inc

#define MY_ARRAY_SIZE 128
In your actual script file you include this file and from then on you can create new arrays that way:

new test_array[MY_ARRAY_SIZE];


Re: [HELP] How to make a dynamic array? - Killa_ - 15.05.2010

Show us the carnumber variable.


Re: [HELP] How to make a dynamic array? - LTomi - 15.05.2010

pawn Код:
new CarNumber[32];
forward LoadCarNumber();
forward SaveCarNumber();
pawn Код:
public LoadCarNumber()
{
   new File: file11 = fopen("carnumber.cfg", io_read);
   fread(file11, CarNumber);
   fclose(file11);
   return 1;
}

public SaveCarNumber()
{
   new string[32];
   new File: file22 = fopen("carnumber.cfg", io_write);
   format(string, sizeof(string), "%d", strval(CarNumber));
   fwrite(file22, string);
   fclose(file22);
   return 1;
}

enum cInfo
{
   cModel,
   Float:cLocationx,
   Float:cLocationy,
   Float:cLocationz,
   Float:cAngle,
   cColorOne,
   cColorTwo,
   cOwner[MAX_PLAYER_NAME],
   cDescription[MAX_PLAYER_NAME],
   cValue,
   cLicense,
   cRegistration,
   cOwned,
};

new CarInfo[CarNumber][cInfo]; /*Here is the problem.*/
Any ideas are welcome.


Re: [HELP] How to make a dynamic array? - juice.j - 15.05.2010

Did you read my posting?


Re: [HELP] How to make a dynamic array? - Killa_ - 15.05.2010

remove the [32], try it like this new CarNumber;


Re: [HELP] How to make a dynamic array? - LTomi - 15.05.2010

Quote:
Originally Posted by juice.j
Did you read my posting?
Yes, but it wouldn't work. The CarNumber variable is changing every time when somebody sells or buy a vehicle, it can't be defined always as 128.


Re: [HELP] How to make a dynamic array? - juice.j - 15.05.2010

Quote:
Originally Posted by Killa_
...
He asks for a dynamically declared array which is not possible (afaik). Going back to an integer won't really help I suppose


Just use macros - best way I guess.


Re: [HELP] How to make a dynamic array? - LTomi - 15.05.2010

Quote:
Originally Posted by Killa_
remove the [32], try it like this new CarNumber;
It doesn't work.


Re: [HELP] How to make a dynamic array? - Killa_ - 15.05.2010

Post the errors