List box Filter question(Solved)

For questions about using Classic.

Post » Wed Jan 25, 2012 11:42 pm

To fill a listbox (start of layout) with the contents of my "AppPath" I can use:

+ File: For each file in AppPath
      -> ListBox_main: Add line File.CurFile

Is there a way to filter it ? say...only include a file if its a extension is ".png" or "png"

I assumed the following would work:

+ File: For each file in AppPath
+ System: GetToken(File.CurFile,1, ".") Equal to ".png"
-> ListBox_main: Add line File.CurFile

It doesnt!

chrisbrobs2012-01-26 19:21:02
B
19
S
6
G
7
Posts: 1,204
Reputation: 7,296

Post » Thu Jan 26, 2012 2:43 am

And it is correct that it doesn't work. The token you would get with your comparison would be the filename without extension.

example.png

has two tokens if the seperator is ".": "example" and "png"
Looking for the first token (index = 1) would only be true if you'd compare to "example"
Looking for the second token (index = 2) would only be true if you'd compare with "png" (and not ".png", the dot is the seperator of your tokenized list)

This should work:
+ System: GetToken(File.CurFile, 2, ".") Equal to "png"

EDIT:
It only works with normal filenames! For example, if the filename is "somepicture.jpg.png" then you would need to compare against the third token.
A better working way for you is

+ System: GetToken(File.CurFile, NumTokens(File.CurFile, "."), ".") Equal to "png"

This will always look at the last extension of a file's name.
tulamide2012-01-26 02:48:18
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Thu Jan 26, 2012 3:29 am

Thanks for your reply....

Still cant get it to work..I tried:



None seem to work though?
B
19
S
6
G
7
Posts: 1,204
Reputation: 7,296

Post » Thu Jan 26, 2012 2:30 pm

That's odd. Maybe something else in the event sheet causes it?

I have made a .rar-archive, containig a folder with 4 files (one cap and 3 dummy files) Please extract it and run the cap. It works for me as it should.

Hopefully it will work for you as well and you can compare this one with your own cap.

http://www.mediafire.com/file/6xlp9tdyoov542z/listboxfilter.rar
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Thu Jan 26, 2012 6:20 pm

Thanks for the example...works a treat. I will have to check the other events in my game.

B
19
S
6
G
7
Posts: 1,204
Reputation: 7,296

Post » Thu Jan 26, 2012 7:19 pm

I finally got it working :


I think by adding it as a sub event (as per your example) was the key.

Thanks again.
B
19
S
6
G
7
Posts: 1,204
Reputation: 7,296

Post » Thu Jan 26, 2012 8:40 pm

Interesting. I'm so used to do subeventing, that I wouldn't have recognized it. I'm not sure what causes it to behave differently, but it tells me to further keep the subeventing-thingy.
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 1 guest