dynamic array allocation
#1

Ok so i got an unkdown number of vehicles , wich i load from mysql
Curently i have the variable defined as this
pawn Код:
new CarInfo[MAX_VEHICLES][cInfo];
I reaaly thot about a way of replacing MAX_VEHICLES with the exact number of the vehicles from mysql , but the question is , can i change the array size of a variabile after being created ? If not , can any1 thinks of a way to do this ?

PS :Ive just given a example , i also load things like Faction/gates/pickups and much more from mysql
Reply
#2

I think you would have to undefine MAX_VEHICLES the just define it again. I'm not sure that's such a good idea though as that may make your array go out of bounds.

In fact I'm not even sure the code would compile TBH. The array size I THINK has to stay static which means setting it to the MAX number of vehicles possible on the system.
Reply
#3

#if defined MAX_VEHICLES
#undef MAX_VEHICLES
#define MAX_VEHICLES number
#endif
Reply
#4

Not natively, in Pawn array sizes need to be known at compile time.

You can download one of the two plugins that give dynamic memory allocation capabilities: Vectoral Pawn & CSTL.
Reply
#5

lol I'm waiting for the array out of bounds errors...

Changing an array size mid script is a horrible idea unless your entire script is retrofitted to handle it.

For Example.

- loop starts using MAX_VEHICLES as an end point
- Array size changes mid loop
- CRASH!!!!!!!! (or maybe not but it'll feck with ur code)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)