well I made this script to randomly spawn an item checking some conditions, it turns out that when it can't spawn in the checked condition it just doesn't spawn, I wanted to know how I could make it check the position and if it couldn't generate a new position and then yes spawn the item.
Lua:
function spawnItemOnArea(from, to, itemId, itemCount)
local spawnTilesNames = {
"grass",
}
local randX, randY = math.random(from.x, to.x), math.random(from.y, to.y)
local random = {x=randX, y=randY, z=7}
local randomTile = Tile(random)
local thing = randomTile:getThing()
for _,v in ipairs(spawnTilesNames) do
if (thing:getName() == v) and (randomTile:getThingCount() <= 1) then
doCreateItem(itemId, itemCount, randomTile:getPosition())
end
end
end