looping array

0 favourites
  • 4 posts
From the Asset Store
For Adventure, Action, Heroes, Sci-fi and Action-RPG games.
  • hey im newby...trying to store x and y positions of instances in an array then print out the array to a text object

    not quit sure how to go about it. got it working for the x diumension but confused about storing and accessing x and y together..

    looks like there is no loopindex for array loops so i created a variable and am incrementing on each loop which seems to work

    capx:

    dl.dropboxusercontent.com/u/8035591/array%20test.capx

    image of events:

    postimg.org/image/d35vog0gn

    image of layout:

    postimg.org/image/8qi9xy9sb

    thank you for your assistance

  • For the array index when doing a For Each you use array.curX or array.curY or array.curZ

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I always thought using "X", "Y", and "Z" for the three dimensions of an array could be misleading for beginners. And this is a good example for it.

    If I understand it correctly, you're having some instances of a sprite and want to store their X/Y position values into an array?

    Let's assume there are 10 instances. For each instance you need to store 2 values (X and Y). That makes 20 values to be stored.

    But if you use an array with width and height set to 10, there are 100 cells (10*10), so there are 80 cells in the array that you never use.

    Try to think of other names for the array's dimension. For example, call the width of an array "sprite instance" and the height "position values". Now it gives you a better approach.

    If you think of it like that, you would set the dimensions of the array: "sprite instance" to 10 and "position values" to 2. That creates an array with 10 * 2 = 20 cells, exactly the amount needed.

    And you would access them with an index. 0 = first instance, 1 = second instance, etc.

    Array.at(0,0) -> x-position of first instance

    Array.at(0,1) -> y-position of first instance

    Array.at(1,0) -> x-position of second instance

    Array.at(1,1) -> y-position of second instance

    etc.

    For the index, there are several options. For example, if the instances of the sprite are once created and then never destroyed, you could simply use their .IID or you could add an instance variable that you set to a unique number per instance, beginning with 0.

    I know this sounds confusing at first, but if you get used to it you will avoid further issues. (Just think of 80 sprite instances for example, that would make your array use 6400 cells with your current method, although only 160 are needed)

  • Yeah i had understood the part about the array size conceptually, but im having trouble understanding how to implement it..

    Also a problem is how to pull information from the array sequentially.

    Am I correct in hearing that array.curX is more or less like loopindex?

    If that?s the case then there is no need for me to have that incrementing variable - ticker.

    what i?m trying to do is have 2 rows of information : row one with the X position and row 2 with the Y position. The idea that i might be able to record all the sprites positions or the mouse position for example.

    But also looking for something incredibly simple. A lot of times programming examples can get too complex to understand fundamental concepts. I think the manual needs more information on this feature. or more practical examples. the best video i found was this youtube.com/watch

    incidentally i actually got it working saving and displaying the value of the x position...then i got confused about how to save both X and Y. do you do it in the same loop?

    conceptual problems.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)