Blocked with random values

Hi all! I’m trying to shuffle a table with a x and y values and put these values in 9 images. I put the images in a storyboard template scene…

But the x and y values repeat in much case… Is possible only shuffle with storyboard in create scene function?

  
local storyboard = require( "storyboard" )  
local scene = storyboard.newScene()  
  
local jing1, jing2, jing3, jing4, jing5, jing6, jing7, jing8, jing9  
  
local puz = { {x=98,y=207},{x=92,y=367},{x=95,y=564},{x=273,y=763},{x=946,y=584},{x=786,y=708},{x=541,y=708},{x=943,y=207},{x=950,y=418}}  
local u = 9  
local o  
function scene:createScene( event )  
  
 local group = self.view  
 o = math.random(u)  
 jing1 = display.newImageRect( "images/2.png", 135, 86 )  
 jing1.x = puz[o].x  
 jing1.y = puz[o].y  
 jing1.id = "p1"  
  
..............................  
jing2 = display.newImageRect( "images/1.png", 135, 86 )  
jing2.x =   
jing2.y =   
jing2.id = "p2"  
more jin3, jing4  
...................  
  

Thanks for the help [import]uid: 69841 topic_id: 24859 reply_id: 324859[/import]

If your code is representative of what you’re doing, you should see that although you’re making 9 images, you’re only picking one value for ‘o’.

I suggest at the very least you put your images into a table so you can do something like this:

[lua]local puz = { stuffx9 }
local jing = {}

function scene:createScene( event )
local group = self.view

for i=1,#puz do
jing[i] = display.newImagerect( group, “images/”…i…".png", 135, 86 )
jing[i].x, jing[i].y = puz[i].x, puz[i].y
jing[i].id = “p”…i
end
end[/lua]

So much simpler. If you want these things to take a random position from the puz table, there are a couple of ways to do it, one such is like this:

[lua]local this_puz = table.remove( puz, math.random(#puz) )
jing[i].x, jing[i].y = this_puz.x, this_puz.y[/lua] [import]uid: 44647 topic_id: 24859 reply_id: 100896[/import]

Thx very much!!! It works!.

I debt you one beer :slight_smile:
[import]uid: 69841 topic_id: 24859 reply_id: 100978[/import]