Filling a table with unique numbers
jsolsona
Member Posts: 1
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
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
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
http://www.mediafire.com/?27cq4jd5dfa7mxi
Just click on the screen.
@tatiang. I never thought of deleting rows instead.
@socks. Nice and easy . 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