Dynamic arrays in pawn?
#1

Hey,

i'm wondering if something like this is possible in pawn
Код:
cin>>x;
struct users
{
	char vname[15],
		 nname[15],
		 sex;
	short age;
	double wealth;
};
users *user;
user = new struct users[x];//this is where the magic happens
In this C++ example, the user can choose the number of elements trough the integer variable 'x'

in pawn, it would look like this (using enumerations, we don't have structures)
pawn Код:
//user entering a command which initializes 'x' with 5
    enum users
    {
        vname[15],
        nname[15],
        sex,
        age,
        float: wealth
    }
    new user[x][users];//and that is the part where tha magic is supposed to happen...

//or something simpler
new vect[x];//x is a variable which holds an integer value of 5
//this array should have 5 elements by now ranging from 0 to 4
but that's not possible, since x has to be constant, like in C++.
So the compiler is tellin' me
error 008: must be a constant expression; assumed zero
and that's okey, 'x' ain't constant.
i'd need a pointer... but we don't have that in pawn.. or.. do we??

anyways, im searching for a way to initialize an array in which the number of elements is set by the user, not the script.
Im sure there is a way to do something like this, someone might know
Maybe a plugin?

take your time thinking about this one, im just asking out of curiosity. no need to hurry.
Reply


Messages In This Thread
Dynamic arrays in pawn? - by CutX - 03.03.2014, 17:08
Re: Dynamic arrays in pawn? - by [XST]O_x - 03.03.2014, 17:13
Re: Dynamic arrays in pawn? - by CutX - 03.03.2014, 17:20

Forum Jump:


Users browsing this thread: 2 Guest(s)