How do I add items to my array?

0 favourites
  • 6 posts
From the Asset Store
Kids Game
$49 USD
New Sounds Added Update: 115 new sound effects added for no additional cost!
  • Hi All,

    I have a question about updating arrays.

    I have my array "Array_Cemetery" where I want to add the following data to the first raw every time I click a button:

    - Player Name

    - Days

    - Hours

    - Minutes

    - PlayerAnimation

    - 1 or 0 value

    I don't want to overwrite raws that are already inside my array.

    I'm doing the following (with trigger once) but it is not working.

    Have tried also the Push function but it continuesly add items to the array.

    Someone could help please?

  • You push the first value on X axis. Then update other elements on Y axis:

    I also suggest trying JSON object. It's better suited to store such data, a lot more flexible and easier to use.

  • Thanks a lot dop!

    I was able to perform what I wanted :)

    One more thing: as you can see from following image, in the array I only see the playername but not other informations inserted. How to see if they are correctly inserted?

    What I need to achieve now is to retrieve all the information inserted in the array, when I click on the playername that now is showed in the list. Probably by inserting these information in some text boxes in the layout.

    How to pick these data from the array and use them in the text box?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You need to set the correct array size. If your array grows on X axis and contains 6 elements on Y axis, the initial size should be (width=0, height=6, depth=1)

    How to pick these data from the array and use them in the text box?

    Use Array.At() expression. For example Array.at(20,0) is the name of the player #21

  • Use Array.At() expression. For example Array.at(20,0) is the name of the player #21

    Thanks, I’ve done something similar. But If I have a 100 player list I don’t know which player I’m going to select from this list, so I need some expression that retrieve from the array the position of the selected player with related information, without inserting manually the X and Y of the array.

  • That's why I suggested JSON, it's a lot easier to work with. Say, if each player has a unique name, you could access any value directly using an expression like JSON.Get("Name.value")

    With a 2D array you need to find the X index of the player first. You can use a loop, or Array.indexOf() expression. For example:

    Array.at(Array.indexOf("name"), 0)

    Refer to the documentation:

    construct.net/en/make-games/manuals/construct-3/plugin-reference/array

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