Filter an Array / Database?

This forum is currently in read-only mode.
  • Hi, I have a list of components in an ini file (so it can be edited by the user) and one of the items is what other value of components can go together (2's can only go with 2's etc.) But If I do a condition that Item = 2 then blah blah blah. It just takes to long and/or is buggy. If I put the ini file into an array is there a way to filter it pick a random entry based on a matching value?

  • You could create keys in a hash table on startup for each group of the ini. Add the relevant item as value of the key. Then you can loop through all the keys and for every key that matches the value you could spawn a dummy sprite with a PV that equals the keyname. Now you can pick a random dummy sprite and will therefore have selected a random group that matches.

    EDIT: Or instead of creating those sprites just add the keyname to a string with a divider attached. And then pick one by random with Gettoken(Random(Numtokens)+1) or something of the sort.

    It doesn't seem very clever to me right now, but that's the only thing I could think of on top of my head . And seeing that you haven't got any replies yet I thought I'd share.

    Oh, and if you already found a better solution please post!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks! I;ve thought it over and that's probably the best way! Thank you!

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