SA-MP Forums Archive
Resizing array & lists - 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: Resizing array & lists (/showthread.php?tid=163633)



Resizing array & lists - matejdro - 28.07.2010

Is there something like list avaible in SA-MP? By list i mean that i can add and remove array members at runtime without knowing max ammount of items at coding time. If not, is there any way to resize array at runtime?


Re: Resizing array & lists - Mauzen - 28.07.2010

The only solution id know atm is to create an array and to write the old one in the new one. You could add/remove something then to resize it.


Re: Resizing array & lists - matejdro - 28.07.2010

Array i want to resize is global. Can i create global arrays at runtime?


Re: Resizing array & lists - DJDhan - 28.07.2010

That is not possible. You cannot create global variables during run time.


Re: Resizing array & lists - matejdro - 28.07.2010

I have an idea about workaround, if anyone needs it:

Код:
new array[200], pointer;
pointer = 0;

//adding member
array[pointer]=something
pointer = pointer + 1

//getting members
for (new i = 0;i < pointer;i++)
{
// do something
}
Idea is that instead of using sizeof, you can use another variable that will determine highest member. It's working on my server, but there are two main problems: memory usage can be high since you have to initialize large array and what to do if number of entries still exceeds array size.