[Solved] How do I use text from external file in array

0 favourites
  • 4 posts
From the Asset Store
Supports 1D, 2D, 3D arrays. Import and export arrays in JSON format
  • Hi there!

    I am trying to create instances with random animations but I am having problem with text info from arrays. I made this simplified capx to see if other code was messing with the results, but I came up with the same problem:

    The sprite object has a "Name" variable. As I create the different instances in a for loop, I give each one a random value: Red, Blue or Green. Then I set the animation to Self.Name.

    For the first row of sprites, I used:

    set "Name" to choose("Red", "Blue", "Green")

    and that worked fine, but I plan on having many more values to choose from and I want to be able to modify those using an external file loaded into an array. So for the second row, I used:

    set "Name" to Array.At(round(random(Array.Width-1)))

    In the debugger, I can see that the "Name" variable works, but the set animation command seems to be ignored. I tried putting str() in front of the command, just in case it was not reading text...

    I am stumped. Can anyone please figure this out for me?

    color generator problem

  • trim(src)

    Return src with all whitespace (spaces, tabs etc.) removed from the beginning and end of the string.

    ..set "Name" to trim(Array.At(round(random(Array.Width-1))))

  • Try Construct 3

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

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

    YES!!!! So simple. I just started learning about using external files and this never came up in anything I read so far.

    Thank you so much for taking time to help me!

  • the problem was that...

    ..you have animation "Red" .....and array value (and "Name" variable) ... "Red (space) "

    ...................................."Green"............................................................................."Green(space) "...etc

    capx> http://s000.tinyupload.com/index.php?fi ... 3406840615

    you can also use trim on:

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