Array question

For questions about using Classic.

Post » Mon Aug 08, 2011 9:44 am

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?
B
134
S
65
G
16
Posts: 1,766
Reputation: 19,190

Post » Mon Aug 08, 2011 10:07 am

[code]{<array>}@<index> [/code]
return element #<index>, i.e., in your case
[code]{"directory1","directory2","directory3"}@2[/code]
will give you string "directory2"
B
2
S
2
G
2
Posts: 158
Reputation: 1,366

Post » Mon Aug 08, 2011 10:11 am

Thanks DtrQ, do you know how I could count how many there are (3 in this case)?
B
134
S
65
G
16
Posts: 1,766
Reputation: 19,190

Post » Mon Aug 08, 2011 11:15 am

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
B
2
S
2
G
2
Posts: 158
Reputation: 1,366

Post » Mon Aug 08, 2011 11:29 am

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!alspal2011-08-08 11:29:39
B
134
S
65
G
16
Posts: 1,766
Reputation: 19,190

Post » Mon Aug 08, 2011 8:46 pm

To get the length of an array do this:
len( <array>)

for example
len({"directory1","directory2","directory3"})
will be 3
B
79
S
24
G
54
Posts: 4,746
Reputation: 40,755

Post » Mon Aug 08, 2011 10:40 pm

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 ConstructDtrQ2011-08-08 22:41:37
B
2
S
2
G
2
Posts: 158
Reputation: 1,366


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 2 guests