Constant Arrays? -
bilakispa - 12.03.2010
Simple Question, can i declare constant array? And How?
I tried:
pawn Код:
const Array[5] = {1,2,...};
but it gives: error 001: expected token: "=", but found "["
I also tried:
pawn Код:
new const Array[5] = {1,2,...};
but it gives: error 008: must be a constant expression; assumed zero
When i declare a constant variable (example const var = 5
it doesn't give me error's
Am i doing something wrong?
Re: Constant Arrays? -
pen_theGun - 12.03.2010
pawn Код:
new const Array[5] = {1, 2, ...};
works for me.
Re: Constant Arrays? -
bilakispa - 12.03.2010
Hmmm, i will give more info because still doesn't work.
I have declared as global this:
pawn Код:
new const DialogIdList[20] = {0,1, ...};
And i have OnDialogRespone
pawn Код:
switch(dialogid)
{
case DialogIdList[0]:
{
...commands...
}
case DialogIdList[1]:
{
...commands...
}
...
...
...
case DialogIdList[19]:
{
...commands...
}
}
...
I get these errors at the case lines : error 008: must be a constant expression; assumed zero
P.S. Anyway, i will change it to if
Re: Constant Arrays? -
pen_theGun - 12.03.2010
I rat, in this case you better use defines
Код:
#define DIALOGID 1
#define DIALOGID 2
Re: Constant Arrays? -
bilakispa - 12.03.2010
Thanks but i think it's more efficient to use "if/else if"s.
Re: Constant Arrays? -
pen_theGun - 12.03.2010
Quote:
Originally Posted by bilakispa
Thanks but i think it's more efficient to use "if/else if"s.
|
is it working now, when you use if/else..?
Re: Constant Arrays? -
bilakispa - 12.03.2010
Yes, but "if" isn't limited to constants like switch, so it doesn't mean now the array is constant (even i have declared it as a constant).
P.S. I opened a new file, declared constant array and using switch still brings the same results. Probably, switch isn't too good as if.
Re: Constant Arrays? -
pen_theGun - 12.03.2010
i think its more, that you use switch stament wrong.
switch(
dialogid)
{
case
DialogIdList[0]:
{
i do understand that DialogIdList is a constant, but how we see something goes wrong
like i said you better use the defines,
because i dont get, how you know which dialogid you use at the moment,
if you have something like this
new const DialogIdList[20] = {0,1, ...};