AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   dynamic array (https://forums.alliedmods.net/showthread.php?t=206138)

hypheni 01-19-2013 01:14

dynamic array
 
May be this question has asked before a few times, but I have not found anything useful.

What I'm doing is reading users.ini file and storing admins name and id in double dimension array. Now I cant assign array size for number of admins in the file (ie: No of lines in users.ini). I have to calculate the number of lines in the file first and then create that size of array.

In C I've done this with malloc but that is not supported by PAWN. Instead of hardcoding users.ini max line can it be done anyway ?

YamiKaitou 01-19-2013 01:21

Re: dynamic array
 
AMXX uses CellArrays to do this, why can't you?

Sylwester 01-19-2013 01:22

Re: dynamic array
 
check natives in cellarray.inc

hypheni 01-19-2013 02:05

Re: dynamic array
 
oh got it.

PHP Code:

    new myArray  //global
    
myArray ArrayCreate(32)

    while(!
feof(file))
    {
        
fgets(filelinea127)
        
ArrayPushString(Array:myArraylinea)
    } 

The above piece of code means dynamic sized array created with each cell limits of 32 chars. Using ArrayPushString we can grow its size as per requirement.

fysiks 01-19-2013 02:23

Re: dynamic array
 
You should tag the array variable with "Array:" when it is created.


All times are GMT -4. The time now is 13:26.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.