Array question

This forum is currently in read-only mode.
From the Asset Store
Supports 1D, 2D, 3D arrays. Import and export arrays in JSON format
  • Using the File object, there's an expression "get directory list" which basically gives you the names of all directories in a directy. I had a string which was being set with this. It outputs stuff like this: {"directory1","directory2","directory3"}, and the expression editor says its an array and I don't know how to handle arrays that are in expressions? I was wanting to count how many directories there were, I tried using "get token count" but the expression editor says that you can only use token stuff on strings and does not work with arrays. Anyone know what I can do?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • {<array>}@<index> 

    return element #<index>, i.e., in your case

    {"directory1","directory2","directory3"}@2

    will give you string "directory2"

  • Thanks DtrQ, do you know how I could count how many there are (3 in this case)?

  • Not realy. Only way I found is add Text object, set Text.text to {array} (simple str() and applying Global Var to convrt array to string doesn't work) and use 'get token count' on it. Don't know why it works only with text object.

    Maybe someone knows better solution

  • Oh fantastic thanks! I had tried storing it as a string variable, then doing the token count on it but that didn't work. Although setting it to text in a text object seems to work well!

  • To get the length of an array do this:

    len( <array>)

    for example

    len({"directory1","directory2","directory3"})

    will be 3

  • Oh, fantastic! I knew there's must be something like that, but it is not documented.

    I'm curious, how many hidden features still exists in Construct

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