Navigation

    Fuze Arena Logo
    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Users
    • Groups
    • Help
    • Discord

    Array help

    Beginners
    3
    4
    272
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Zypher
      Zypher last edited by

      So I've got an idea for a game I want to make, but I gotta start with something that I cant quite get right. I need an array like this: array[ x, y, z ] : I need to be able to use the x, y, and a variables to access a single value, that I can both read and write. Any easy ways to do this or should I find another way to store this data?

      1 Reply Last reply Reply Quote 0
      • R
        Richard F last edited by

        You make each element of your array an array to give a multi dimensional array. Multi dimensional arrays are accessed as Array[x][y][z].

        1 Reply Last reply Reply Quote 0
        • PB____
          PB____ last edited by PB____

          Something to keep in mind with Fuze (at least in it's current implementation) is that it doesn't assign values by reference.

          So if you have a multiple dimensional array, it does matter how you iterate over them:
          For example:

              values = [
                  [0, 1],
                  [5, 6]
              ]
              print(values, "\n") // [0,1], [5,6]
              for i = 0 to len(values[0]) loop
                  values[0][i] = values[0][i] + 1
              repeat
              print(values, "\n") // [1,2], [5,6]
              row = values[0] // assigning creates copy
              for i = 0 to len(row) loop
                  row[i] = row[i] + 1
              repeat
              print(values, "\n") // [1,2], [5,6]
              print(row, "\n") // [2,3]
              values[0] = row // assigning back into the multi dimensional array
              print(values, "\n") // [2,3], [5,6]  // Added this example by editing the post
          

          So as soon as you assign values[0] to a variable, that becomes a copy of the array at values[0] and changes to that array do not apply to the original array.

          I'm not saying this is wrong, it even has it's advantages. But I didn't expect this when I tried out multi-dimensional array. So when I read that there was a bug with copying structs, I chose not to use multi-dimensional arrays in my code.

          In hind sight, now I think I get how they work, and you can take advantage of that..

          1 Reply Last reply Reply Quote 2
          • Zypher
            Zypher last edited by

            Thanks for the help. That will help alot!

            1 Reply Last reply Reply Quote 1
            • First post
              Last post