I have a problem with the following shuffle function. I’m trying to shuffle table (animalNames) values with a function (shuffle). It works in the simulator but not on a device. Any help is appreciated!
( I need this to be able to create display objects with random images. Maybe there is some other way to do this? )
[code]
animalNames = {}
table.insert (animalNames,“animal-duck-l.png”)
table.insert (animalNames,“animal-frog-l.png”)
table.insert (animalNames,“animal-giraffe-l.png”)
table.insert (animalNames,“animal-hippo-l.png”)
table.insert (animalNames,“animal-monkey-l.png”)
table.insert (animalNames,“animal-octopus-l.png”)
– function that shuffles the table values
function shuffle( a )
local c = #a
for i = 1, c do
local ndx0 = math.random( 1, c )
a[ndx0], a[i] = a[i], a[ndx0]
end
return a
end
– shuffle animalNames table
shuffle (animalNames)
[/code] [import]uid: 13507 topic_id: 8189 reply_id: 308189[/import]