Filling a table with unique numbers

I'm trying to fill a simple table (with only 4 columns and only 1 row) with unique numbers. (between 1 and 4)

I figured it would go something like this:

counter = 1
if counter <=4
num = random (1,4)
used = false
for x=1 to 4
if num in cell(1,x)
used = true
x++
if used = false
cell (1, counter) = num
counter++


But somehow this doesn't seem to work.

In GS
it looks something like this:


on mouse down
counter =1
timer
on rule counter <= 4
num = random (1,4)
used = false
x = 1
timer
on rule x <=4
if num = cell (1,x)
used = true
x = x + 1
on rule used = false
cell (1, counter) = num
counter = counter + 1


My problem seems to be that I can't loop through the x <=4 part (in the middle where the second timer is)

I wish I could do:
if x in list

Anyway, any other easier way to get random unique numbers in a table? I'm new at GS and I guess I'm still trying to get my head around timers

Thanks

Comments

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    The idea is to create a separate table with possible values as rows and then as random rows are chosen, delete the chosen row and pick another random row from the remaining rows. Here's a demo:

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • SocksSocks London, UK.Member Posts: 12,822
    edited December 2012
    Here's another way to do it.

    http://www.mediafire.com/?27cq4jd5dfa7mxi

    Just click on the screen.
  • jsolsonajsolsona Member Posts: 1
    Thanks.

    @tatiang. I never thought of deleting rows instead.

    @socks. Nice and easy :D. My actual table is a bit bigger than 1x4. It's more like 1x16 or 1x25, but I like the simplicity of it.

    Thanks again
  • SocksSocks London, UK.Member Posts: 12,822
    My actual table is a bit bigger than 1x4. It's more like 1x16 or 1x25, but I like the simplicity of it.
    At 1 x 25, my technique would consume the rest of your natural life generating the various permutations. : ) I'd stick with tatiang.


Sign In or Register to comment.