Home AMX User Forum NetLinx Studio

Appending onto an integer array?

Has anyone done this before like it says in the NL keywords help on the Arrays page?

"Example:
INTEGER Len
INTEGER Array1 = {3, 4, 5, 6, 7}
INTEGER Array2[10] = {1, 2}

Len = MAX_LENGTH_ARRAY(Array1) // Len = 5
Len = MAX_LENGTH_ARRAY(Array2) // Len = 10

LENGTH_ARRAY is called to determine the effective length of Array1 and Array2.
This value is set automatically when the arrays are initialized.
Len = LENGTH_ARRAY(Array1)  // Len = 5
Len = LENGTH_ARRAY(Array2)  // Len = 2

Array2+ = Array1

Len = LENGTH_ARRAY(Array2)  // Len = 7

Array1 is appended to Array2.
Array2 now contains the values "1, 2, 3, 4, 5, 6, 7" and has an effective length of 7."

Just tried it and it didn't compile...

Comments

  • jjamesjjames Posts: 2,908
    Unfortunately you cannot use += in NetLinx. It'd be nice, but you just can't. I know you can replace arrays, but I'm fairly certain you can't append them. You're most likely gonna have to shift your values and re-assign.

    This isn't C# / C++ / Java, etc. NetLinx isn't that powerful, but I'm sure it's more powerful than Cr3stron's language.
  • jcereckejcerecke Posts: 40
    Cheers, I wouldn't normally ask, but just assume it couldn't. Just that it's in the help file and all haha. Then again it's probably not the first time the help file's been wrong.
  • a_riot42a_riot42 Posts: 1,624
    jcerecke wrote: »
    Cheers, I wouldn't normally ask, but just assume it couldn't. Just that it's in the help file and all haha. Then again it's probably not the first time the help file's been wrong.

    That part of the help file must have been written on a Friday at 4 pm. You can't define an array this way:

    integer array = {1,2,3}

    you need the brackets:

    integer array[] = {1,2,3}

    and there is no array addition or subtraction that I know of in Netlinx.
    Paul
Sign In or Register to comment.