Home AMX User Forum AMX Technical Discussion
Options

Can't get multi dimensional arrays to work

doesn't work:
LONG NORMAL_TIMELINE_TIMES_1[] = {10000,10001,10002,10003}
LONG NORMAL_TIMELINE_TIMES_2[] = {10000,10001,10002,10003}
LONG NORMAL_TIMELINE_TIMES_3[] = {10000,10001,10002,10003}
LONG NORMAL_TIMELINE_TIMES_4[] = {10000,10001,10002,10003}

LONG NORMAL_TIMELINE_TIMES[][] = { NORMAL_TIMELINE_TIMES_1,NORMAL_TIMELINE_TIMES_2,NORMAL_TIMELINE_TIMES_3,NORMAL_TIMELINE_TIMES_4}

works fine:
INTEGER My3DArray[5][3][4] =

{

 {

 {1,2,3,4},

 {5,6,7,8},

 {9,10,11}

 },

 {

 {13,14}

 }

}

Comments

  • Options
    PhreaKPhreaK Posts: 966
    You can't use a variable to instance another variable. You will have to define your multidimensional array with set bounds then fill it in your code, or instance it with the real values in one go.
  • Options
    viningvining Posts: 4,368
    What if you tried constant arrays instead of var arrays?
  • Options
    PhreaKPhreaK Posts: 966
    If I remember correctly that may work. Actually you may be able to define your timelines as constant arrays they have your timelines container (multidimensional array) defined as a variable. That way you can populate it with the constants upon instatiation for readability and still have it mutable so you can update it at runtime.
  • Options
    travistravis Posts: 180
    The above are all constants.

    I'm pretty sure I try to do this every time I start a new project after not using AMX for a while.
  • Options
    rfletcherrfletcher Posts: 217
    If LONG NORMAL_TIMELINE_TIMES[][] is a constant that's the problem, You can't use a constant to define another constant. If you change the multi-dimensional array to a variable I think It'll work.
  • Options
    I'm pretty sure I try to do this every time I start a new project after not using AMX for a while.
    I remember you had this issue last time too. http://www.amxforums.com/showthread.php?t=5263.

    Did you ever get that working last time by just filling the variable array at DEFINE_START?
    PhreaK and Vining's suggestion should work.

    --John
  • Options
    travistravis Posts: 180
    You can use a constant to define another constant.

    DEFINE_CONSTANT
    INTEGER foo1 = 1
    INTEGER foo2 = 2
    INTEGER foo3 = 3
    INTEGER bar[] = {foo1, foo2, foo3, foo4}


    It's just when you get more dimensions it starts breaking. I think?

    I don't want to make these variables. These aren't variable; They are constant, immutable.
Sign In or Register to comment.