Well, let's not stay off-topic with the french "affair". I'm trying to guess if his problem is not simple like random select from a table (like he thought he needed).
If it's the problem, there is several ways of random select one of the tiles you have in your code:
An easier one ( you can add other properties to you table in each row/tile like name and whatever)
Code: Select all
function love.load()
tiles = {
{ img = love.graphics.newImage("fond.png") },
{ img = love.graphics.newImage("lum.png") },
{ img = love.graphics.newImage("arbre.png") }
}
rnd = math.random(#tiles)
end
function love.update(dt)
end
function love.draw()
love.graphics.draw(tiles[rnd].img,0,0)
end
A long one (because we need this way use extra code for get info from the table since is not organized by numeric index)
Code: Select all
function love.load()
tiles = {
pierre = { img = love.graphics.newImage("fond.png") },
lumiere = { img = love.graphics.newImage("lum.png") },
arbre = { img = love.graphics.newImage("arbre.png") }
}
count = table_count(tiles)
rnd = math.random(count)
selected = table_get_index(tiles,rnd)
end
function love.update(dt)
end
function love.draw()
love.graphics.draw(tiles[selected].img,0,0)
end
function table_count(t)
local count = 0
for _ in pairs(t) do count = count + 1 end
return count
end
function table_get_index(t,pos)
local count = 0
for k,v in pairs(t) do
count = count + 1
if count == pos then return k end
end
return "Error: Out of Range"
end
I hope didn't a mistake. As you see you random choice a value from table and present it.