Demo: Randomize Table Rows
tatiang
Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
I got a little tired of using a method for extracting random table rows (e.g. randomly picking an image from a list of images, a question from a list of questions, etc.) that deletes a table row after choosing it, so I hit up Google and found a nice little algorithm. The source of the algorithm and the source of the time stamp loop (which I've posted about previously) are in the actor's notes.
Basically, this takes a table (currently 10 rows and only 1 column, but adaptable as needed) and randomly shuffles the rows "in place." I have not tested it extensively so if anyone has any criticisms or improvements, I'm all ears.
Basically, this takes a table (currently 10 rows and only 1 column, but adaptable as needed) and randomly shuffles the rows "in place." I have not tested it extensively so if anyone has any criticisms or improvements, I'm all ears.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Comments
tableCellValue( game.|T| Values ,1,1).."\n"..
tableCellValue( game.|T| Values ,2,1)
The .. concatenates or joins expressions, while the "\n" adds a new line.
You could, of course, create a separate loop to concatenate all of the row data into a single text attribute and then just display that attribute.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Great!- thanks for sharing.
Chakku
My GameSalad Academy Courses! ◦ Check out my quality templates! ◦ Add me on Skype: braydon_sfx
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Excellent, @tatiang, (I must have missed this post at the time). I have Awesomed you! :-)
Still trying to get my head around it tho' , to understand what's going on with your impressive programming.
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
OK, still good work then in the translation, so still awesome in my books! And yes, at first glance, it all looks a bit head-scratching... :-)
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps