How do I retrive array value

0 favourites
  • 5 posts
From the Asset Store
Supports 1D, 2D, 3D arrays. Import and export arrays in JSON format
  • So i set my layout with one botton and 2 texts

    tsxt1, text2 click

    I create an array called names and create few name in it.

    I make an event "ON CILCK" than i set "APPENT TEXT" to the text1 to check a value of an array based on index number.

    Names.At(0, 0, 0)

    I also try

    Names.At(0)

    Names.At(1)

    and so on.

    I am trying to make auto name generating for pc characters based on array list.

    Questions:

    1. What's wrong with the code?

    2. I need an function to retrive only one name randomly from the list, How can i do it?

    And of course, Thank You!

  • At(index) should work, as it says in the manual, if Y and Z are not provided, then they are set to 0.

    I think the problem comes from the initialization of your array. How do you fill it with names?

    You need a one dimensional array of names. Personally, I would first set the size of the array to (NAMESCOUNT, 1, 1), where NAMESCOUNT is the number of names you have, then I would fill each X index with a string value.

    Maybe you set the height or depth to 0 by mistake. From the manual : "If any of the dimensions are 0 the entire array is empty, so usually all the dimensions are at least 1."

    Please provide a capx or a screenshot of your code at least for us to provide a more detailed answer.

    Btw, you can read the manual for Array here : https://www.scirra.com/manual/108/array

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks,

    Still not working.

    This is the image from the problem please check

  • The Text object is useless for array manipulation, you only need it to display some text (like the content of your array) on screen.

    Second mistake : Array elements are different from the object's instance variables. You don't need instance variables at all in the Array object.

    To add an element to an array, use the array's Push action.

    In your event sheet, this should look like :

    • push "alex" at the end of name
    • push "martin" at the end of name
    • ... and so on.

    You should check out a tutorial for using arrays in the tutorial section on this website, there are really good ones, or check out the usage of arrays in the manual.

  • Thank you!

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