Filter an Array / Database?

For questions about using Classic.

Post » Sat Sep 04, 2010 5:35 pm

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?
Follow me on Twitter @evgLabs
B
33
S
14
G
4
Posts: 251
Reputation: 4,049

Post » Mon Sep 06, 2010 9:09 pm

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. :idea:

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! :)
B
21
S
6
G
10
Posts: 1,024
Reputation: 7,445

Post » Tue Sep 07, 2010 3:37 pm

Thanks! I;ve thought it over and that's probably the best way! Thank you!
Follow me on Twitter @evgLabs
B
33
S
14
G
4
Posts: 251
Reputation: 4,049


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 2 guests