How do check through array depth 1 and use values to sort depth 0 ?

0 favourites
  • 10 posts
From the Asset Store
A very simple to set up ZElevation based depth of field system for your game. Fully commented.
  • In my game, the player performs actions (A, B, C, D, etc) in a certain order (1, 2, 3, 4, etc). At runtime, I'm using an XYZ array named Journal to store for each action a value corresponding to its order.

    The following drawing shows the status of the array at the end of the game. It reads that actions have been performed in the following order :

    E, D, A, B, I, etc

    I want to create a LogBook function for the player so that they can browse through their game history. So I need to create a function that goes through the array, pick the numbers in their order and add the corresponding action description (A, B, C, etc) to a text file to create a sort of narrative.

    How can I do that ?

    Tagged:

  • You can use a loop from the array object for each x,y,z to compare if the current value is "1" for example, then when you have the location compare at Z=0

  • Hi!

    Thanks for your reply ! This is what I thought but I didn't know how to put it together.

    Would you propose a file ?

  • Hey, if you already sorted the arrays out and ordered values on xyz then you should be able to pull values? Try it and see

  • Actually, I haven't even managed to sort the array.

  • And the point is I don't know how to code the engine tu pull values (hence my question here) :(

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • "In my game, the player performs actions (A, B, C, D, etc) in a certain order (1, 2, 3, 4, etc). At runtime, I'm using an XYZ array named Journal to store for each action a value corresponding to its order.

    The following drawing shows the status of the array at the end of the game. It reads that actions have been performed in the following order :

    E, D, A, B, I, etc"

    You created this?

  • Oh, let me explain.

    At the begining of the game, every cell in depth1 is empty.

    When in the begining of the game player performs action D, then x is stored in depth1 where D stands in depth0. Then when payer performs F, then x+A is stored in depth1 where F stands in depth0, etc

    I'm not sorting anything, just putting incremented variable in the array cells at their corresponding action coordinate.

  • There are ways to do it but you may be over complicating things a bit.

    how many choices will there be? a few, dozens, thousands? how many levels of depth do you want to keep? last one, several, lots?

    Since you know the list actions, if that list is static for the level there is no need to store it as the first element of the array.

    as actions are performed just add the action to the end of the array using a single dimension. you don't have to sort it, the first element is the first action...

    you will have a record of what happened and that can be stored in others ways for history.

    I would be happy to show an example or two if you want to see more complicated sorting if you want.

  • One way to do it would be with a second array. So if A is the first one B could be the second. And you’d do this:

    On function “journal”

    — B: set size to (0,2,1)

    — A: for each xy

    — — B: push A.at(A.curX, A.curY, 1) to front

    — — B: set at (0,1) to A.at(A.curX, A.curY, 0)

    — B: sort

    Then B would have the sorted list in the 2nd column.

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