Most efficient way to select a random table row where column is true?
I would like to select a random row where the column "isActive" has a value of true. I currently have about 10 rows with 3 of them having "isActive" set to true. The further along in the game you get, more of the rows will be set to true, making more of them available to be selected.
I am currently attempting this by having a duplicate table that gets populated by checking each row in the master table. If "isActive" is set to true in the master table then I want to insert this row into the duplicate table. When all rows have been inserted into the duplicate table, I can select a random row with something like random(1, tablerowcount(tableDuplicate)).
Is this too convoluted and is there a simpler way? Use attributes instead of table? Any advice is well appreciated.
Comments
Hi @ellison, your approach sounds fine.
I am just curious about the above. It sounds like you are cycling through the table periodically? If you are, rather just add the appropriate row to the duplicate table as and when a row becomes "active".
MESSAGING, X-PLATFORM LEADERBOARDS, OFFLINE-TIMER, ANALYTICS and BACK-END CONTROL for your GameSalad projects
www.APPFORMATIVE.com
Yes, I figured I would check the tables at the start of each level to keep them in sync, but I guess that does sound like overkill.
Thanks for the suggestion, I will try that.