Hi I’m trying to randomly pick between 5 different tile sources and assign the selected one to a tile map. I have this code bit to change the tile source which works
go.property("tile_selection", resource.tile_source("/main/tiles/tile1.tilesource"))
go.set("#tilesmap", "tile_source", self.tile_selection)
however when I do this
math.randomseed(os.time())
local random = math.random(5)
go.property("tile_selection", resource.tile_source("/main/tiles/tile" .. tostring(random) .. ".tilesource"))
go.set("#tilesmap", "tile_source", self.tile_selection)
or this
math.randomseed(os.time())
local random = math.random(5)
if random == 1 then
go.property("tile_selection", resource.tile_source("/main/tiles/tile1.tilesource"))
elseif random == 2 then
go.property("tile_selection", resource.tile_source("/main/tiles/tile2.tilesource"))
elseif random == 3 then
go.property("tile_selection", resource.tile_source("/main/tiles/tile3.tilesource"))
elseif random == 4 then
go.property("tile_selection", resource.tile_source("/main/tiles/tile4.tilesource"))
elseif random == 5 then
go.property("tile_selection", resource.tile_source("/main/tiles/tile5.tilesource"))
end
go.set("#tilesmap", "tile_source", self.tile_selection)
it doesnt work and both of those return this error
ERROR:GAMEOBJECT: Properties can not be of type ‘nil’.
ERROR:SCRIPT: /main/puzzlelogic.script:: the property ‘tile_source’ of ‘#tilesmap’ must be a hash
stack traceback:
[C] in function set
/main/puzzlelogic.script:: in function </main/puzzlelogic.script:50>
please explain this
Summary
This text will be hidden