0 Favourites

How do I Load Data Into An Array

  • Hey there,

    Do I use "On Start of Layout" and then fill it in with events? Or is there some other way? Like a text file?

    Thank You

  • Hey there,

    Do I use "On Start of Layout" and then fill it in with events? Or is there some other way? Like a text file?

    Thank You

    You can do the on start of layout + events, however, it is not the best technique, the best is I think to load a JSON file (which can be a project file) into it when it is created.

    I do not remember the exact syntax though

  • Ahh, haven't touched Json yet. I'll hit the manual and see where I end up with that. Thanks!

  • {"c2array":true, 
    "size" :[2,5,1], 
    "data":[
    [["(0,0)"],["(0,1)"],["(0,2)"],["(0,3)"],["(0,4)"]],
    [["(1,0)"],["(1,1)"],["(1,2)"],["(1,3)"],["(1,4)"]]
    ]
    }[/code:9rupk4q1]
    
    should return an array like this:
    
    
    

    "(0,0)" | "(1,0)?

    "(0,1)" | "(1,1)"

    "(0,2)" | "(1,2)"

    "(0,3)" | "(1,3)"

    "(0,4)" | "(1,4)"

    Hope that helps (I do not know about a 3D array though)

  • Aphrodite Where would that code even go?

  • Aphrodite Where would that code even go?

    The "proper way" to do it would be to use a project file (which is actually just a text file containing that code, which is actually a C2 array in a JSON format), to call it using the AJAX object, and to load the Ajax request result inside the array using the array's action "Load".

    https://www.scirra.com/manual/108/array

    https://www.scirra.com/manual/107/ajax

    https://www.scirra.com/manual/141/files

    However it might be a little too much to worry about if you don't know yet how to do all this.

    I suggest you go by setting each value with a "set at X/XY/XYZ" for now, just remember that if your array is not large enough you could have issues(a value outside an array is always 0).

  • Hi. I'm also struggling to get data from a text file into an array, so if anybody can enlighten me.

    I have a list of 500 Words in a TXT file. looking like this:

    and

    when

    sell

    up

    to

    five

    hiundred

    Should it be formatted otherwise?

    I want an array, from which I can select a random word.

    Anybody?

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • Hi. I'm also struggling to get data from a text file into an array, so if anybody can enlighten me.

    I have a list of 500 Words in a TXT file. looking like this:

    Should it be formatted otherwise?

    I want an array, from which I can select a random word.

    Anybody?

    I think for a list that simple, you could do something like:

    and|when|sell|up|to|five|hiundred[/code:3ddusuwd]
    
    And retrieve one of them with the tokenat expression: [url=https://www.scirra.com/manual/126/system-expressions]https://www.scirra.com/manual/126/system-expressions[/url]
    
    With the parameter index equals to int(random(number of elements))
  • Thanks, that's quick!

    Still I'd like to import the list and make an array, as this is the first app I'm converting to Windows, (I used Stencyl to make it for iOs, but they don't support HTML5 or Windows touchscreens.) and down the road I'll need multidim arrays for other apps.

    I feel a little lost, as I know what I want to do, but can't quite figure out where to find the solutions, yet.

    (I used a list object , which is one of the nice aspects of Stencyl, for this.)

  • gplar : I've made a little function (using C2's Function Object) that can take your list

    and

    when

    sell

    up

    to

    five

    hiundred

    into a one dimensionnal array:

    First it clears the array, then it size it accordingly to the number of values, then it enters the values inside it, you may wonder "how do I concretely use that thing", well, like this:

    The first parameter is the list itself (I put it directly, but it can be a separate project file), the second parameter is the characters between each elements of the list (here it is newline, because each part of the list is separated by a new line)

    The debugger shows that at the end, the array has the correct values after using it.

    Hope that helps

  • Thanks ever so much! I´ll try this tonight.

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