I am trying to choose randomobject (color) from table and then applying it to newrect but i am getting the follwoing error
Attempt to index local ‘hex’ (a nil value)
File: main.lua
Line: 17
stack traceback:
main.lua:17: in function ‘convHexColor’
main.lua:40: in function ‘_listener’
?: in function <?:167>
?: in function <?:205>
Here is the code
local physics = require( “physics” )
physics.start()
display.setDefault(“background”, 1, 0, 0)
function randomcolor()
local colors = { “2ecc71”, “3498db”, “9b59b6”, “2c3e50”, “e74c3c” }
local choosecolor = color[math.random(1,5)]
end
local function addnewobject()
local bombstartnew = display.newRect( 150, -340, 50, 50)
physics.addBody( bombstartnew )
bombstartnew.enterFrame = offscreen
bombstartnew:setFillColor( convHexColor( choosecolors ))
Runtime:addEventListener( “enterFrame”, bombstartnew )
end
timer.performWithDelay( 500, addnewobject, 0 )