[HELP] How to make a dynamic array?
#1

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?
Reply
#2

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];
Reply
#3

Show us the carnumber variable.
Reply
#4

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.
Reply
#5

Did you read my posting?
Reply
#6

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

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.
Reply
#8

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.
Reply
#9

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

Post the errors
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)