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

There is no way to do it, it's not supported in this language.
Anyway, it's pretty easy to get along without it, it's not a necessity.
Reply
#3

Quote:
Originally Posted by [XST]O_x
Посмотреть сообщение
There is no way to do it, it's not supported in this language.
Anyway, it's pretty easy to get along without it, it's not a necessity.
thanks for the quick answer!
I know that we don't really really need it... as i said, im just curious

further answers are still welcome, if you know of some neat trick regarding this,
don't hesitate! do tell me
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)