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

Get help using Construct 2

Post » Sun May 17, 2015 4:20 am

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
Last edited by SimoneT on Sun May 17, 2015 1:12 pm, edited 1 time in total.
B
16
S
9
G
5
Posts: 74
Reputation: 4,120

Post » Sun May 17, 2015 5:31 am

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))))
B
67
S
24
G
7
Posts: 1,518
Reputation: 11,072

Post » Sun May 17, 2015 1:09 pm

@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!
B
16
S
9
G
5
Posts: 74
Reputation: 4,120

Post » Sun May 17, 2015 1:23 pm

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:
Image
B
67
S
24
G
7
Posts: 1,518
Reputation: 11,072


Return to How do I....?

Who is online

Users browsing this forum: MrSkailo and 25 guests