How can I randomize cell values in a specific set of rows and columns of a table?
In my table, there are 10 Rows and 9 Columns.
I would like the numbers from Row 2 to 9 of Column 2 to 8 to be randomized whatever the trigger is. And here's the kicker to make things more complicated, I'd like the number in Row 9 Column 8 to remain the same.
I hope this makes sense and is possible for it'll take me a million years to learn how to make it happen, lol
Again, thanks in advance to those who'll spare some of their precious time to answer this for me wink wink ahem @Socks. hahaha...
Best Answer
-
tintran Posts: 453
on a touch is pressed event.
Have a single loop that counts from 0 to < numbers of random swaps desired (in my example i use 9 swaps)
and inside the loop just set some variables to point to a random cell (let's call it cell a) and another random cell (let's call it cell b).
if cell a is tablecell(3,3)
--do nothing
else
--if cell b is tablecell(3,3)
----do nothing
--else
----set save_value to cell a's value
----set cell a to cell b's value
----set cell b to saved_value
here's the example, just click on actor and see it swap leaving tablecell(3,3) untouched.
http://www.mediafire.com/download/29vdpsel9cgnsu2/swaptablevalues.zip
PS: you're on a MAC, i am assuming you can open GS project files that are created on Windows. Because I am on Windows and I have no problem opening GS project files created on MAC, I just get some extra _MACOSX folder that i don't need.
Answers
Are you saying that you want to sort the numbers in a random order or that you want to choose a random value from those rows and columns? And what do you mean by trigger? Can you give an example of what this might look like (for instance, if you had a table that was 3 rows by 3 columns and values below, what would the trigger be and what might a result look like)?
123
456
789
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Definitely @tatiang's area this one !
Yes, I want the numbers sorted randomly.
let's say for argument's sake I wanna trigger it with a touch press and results will either be
1.
367
241
589
2.
821
257
639
3.
628
754
139
and as you notice, the number 9 stays at the slot of row 3 and column 3 permanently.
I would say so too lol
Okay, so you're randomly shuffling the numbers in those rows/columns but keeping a single cell static. Got it. Not the easiest thing to do!
I've played around with loops within loops but you'll most likely need a custom set of rules to do this.
There are other members here who have done card shuffling and such but you might start by checking out this demo: http://ezinterweb.com/gamesalad/fisher-yates-shuffle.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
There are probably many ways to do this. Here is one.
Thanks guys, will let you know what happens.
Thanks again for all the help guys, I found that Tintran's method is what solved my problem but I appreciate all your suggestions equally the same.
Here's a video sample of how the shuffler looks in my game, thanks again.