Constant Arrays?
#1

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

pawn Код:
new const Array[5] = {1, 2, ...};
works for me.
Reply
#3

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
Reply
#4

I rat, in this case you better use defines

Код:
#define DIALOGID 1
#define DIALOGID 2
Reply
#5

Thanks but i think it's more efficient to use "if/else if"s.
Reply
#6

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..?
Reply
#7

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.
Reply
#8

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, ...};
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)