Hello,
I was wondering if anyone can help me figure out why I am getting “Attempt to index field ‘view’ (a nil value)” when I use “scene.view:insert(straw )” in my forward referenced function of a composer scene (at line 31)? Please see code below. Any help would be GREATLY appreciated… pulling my hair out!
[lua]
local composer = require( “composer” )
local scene = composer.newScene()
local function strawTap(e)
transition.to(e.target, { xScale = .01, yScale = .01})
end
local maxStraws = 10
local straws = {“strawberry.png”, “strawberry2.png”, “strawberry3.png”}
local allStraws = {}
local function makeAStraw(id)
local strawidx = rnd(1, 3)
local randX = rnd(400, 700)
local randY = rnd(670, 720)
local randRot = rnd(-10, 10)
local strawsize = rnd(1, 4) / 100
local straw = display.newImage( “images/” … straws[strawidx])
straw.x = randX
straw.y = randY
straw.rotation = randRot
straw:scale ( strawsize, strawsize )
straw.name = “straw” … tostring(id)
straw:addEventListener ( “tap”, strawTap )
allStraws[#allStraws+1] = straw
scene.view:insert( straw )
end
for v = 1, maxStraws do
makeAStraw(v)
end
local function turnOnStraws()
for i = 1, #allStraws do
transition.to(allStraws[i], {time = 3000, xScale = .15, alpha = 1, yScale = .15,})
end
end
[/lua]