Store array in normal global variable and access its data?

0 favourites
  • 5 posts
From the Asset Store
Globals 2.0
$3.99 USD
Globals 2.0 stores and group variables. You can also load and save data (variables) from/to JSON files.
  • Hey there!

    Is it possible to access an array inside a global variable?

    For example, if I have a global variable called fruit which's value is ["Apple", "Orange", "Mango", "Banana"], how can I access "Orange"?

    I tried:

    • fruit(1)
    • fruit[1]
    • fruit{1}
    • fruit("1")
    • fruit["1"]
    • fruit{"1"}

    And I think some more. How can I access it? I really do not like the built in Array editor and how I need to copy and paste every single value. And even if I do, the values are cut off and there is no way to adjust the columns widths all at once.

  • tokenat(src, index, separator)

    Return the Nth token from src, splitting the string by separator. For example, tokenat("apples|oranges|bananas", 1, "|") returns oranges.

    To be honest you are better off learning how to use Arrays or Json

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Ah thanks, I didn't think about that.

    But what do you mean I should learn about arrays? I am using arrays but Construct was holding me back to do so without the use of the inconvenient array object. And I'm also using Jsons.

    But thanks anyway.

  • This data - ["Apple", "Orange", "Mango", "Banana"] may be loaded into JSON object, but not into an array. Arrays in C3 require a specific structure of JSON string. It looks like this:

    {"c2array":true,"size":[5,4,1],"data":[[[.....]

    You can use Array.AsJSON expression to export array data to JSON string, then put this string into the variable. Then you will be able to load it into the array using Array Load From JSON action.

  • Okay that is interesting!

    And it looks pretty overcomplicated to convert the array back and forth.

    For now I used sizcoz's suggestion as it's working fine.

    But I'll keep in mind what you explained for the future. Thanks.

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