0 Favourites

List box Filter question(Solved)

This forum is currently in read-only mode.
  • 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!

  • 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.

  • Thanks for your reply....

    Still cant get it to work..I tried:

    <img src="http://dl.dropbox.com/u/22173473/token1.png" border="0" />

    None seem to work though?

  • 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

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

    <img src="smileys/smiley1.gif" border="0" align="middle" />

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • I finally got it working :

    <img src="http://dl.dropbox.com/u/22173473/getcaproj.png" border="0" />

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

    Thanks again.

  • 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.

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