Hello. I dont speak English fluently so excuse me for that/
One time I decided to make a snake simulator. The code works well on simulator but on device the same code gives next:
Runtime error
F:\Скидосик\Game\main.lua:111:attempt to index upvalue ‘settingsView’ (a nil value)
I saw 111th string. Here I declare that settingsView.anchorX = 0
Maybe you know where is the mistake. Here is my code from 1 to 125 string. 111th string is bold.
Thank you
–Declaring width and height
_W = display.contentWidth; _H = display.contentHeight
–Hide status bar
display.setStatusBar(display.HiddenStatusBar)
–adding physics
local physics = require “physics”
physics.start()
–set gravity
physics.setGravity(0, 0)
local bg = display.newImage(“menuBg1.png”)
–setting anchor points
bg.anchorX = 0;
bg.anchorY = 0
–add main menu buttons
local playBtn
local settingsBtn
local titleView
–Settings
local settingsView
–Game Background
local gameBg
–[We move the train not by buttons but by swipes]
local cabinGFX
local cabinHitArea
local cabin
local up
local down
local left
local right
–Cabin
–Score
local score
–Sounds
local bombGrab = audio.loadSound(“bomby.wav”)
local gameOver = audio.loadSound(“gameOv.wav”)
–Variables
local dir --current direction of the train
local started --used to start the timer
local timerSrc
local speed = 200
local mConst = 60 --number of pixels to move every timer count
local bombs --bombs group
local mans --man group
local lastWagon --last Wagon added to train
local firstWagon
local parts --parts group
local current = 0 --a number assigned to each part
–Now we declare functions
local Main = {}
local startButtonListeners = {}
local showSettings = {}
local hideSettings = {}
local showGameView = {}
local gameListeners = {}
local moveTrain = {}
local hitTestObjects = {}
local update = {}
–Main function
function Main()
playBtn = display.newImage(“playBtn.png”, _W*0.2, _H*0.93)
settingsBtn = display.newImage(“settingsBtn.png”, _W*0.7, _H*0.93)
titleView = display.newGroup(playBtn, settingsBtn)
startButtonListeners(“add”)
end
function startButtonListeners(action)
if (action == “add”) then
settingsBtn:addEventListener(“tap”, showSettings)
playBtn:addEventListener(“tap”, showGameView)
else
settingsBtn:removeEventListener(“tap”, showSettings)
playBtn:removeEventListener(“tap”, showGameView)
end
end
function showSettings:tap(e)
playBtn.isVisible = false
settingsBtn.isVisible = false
settingsView = display.newImage(“Settings.png”, 0, 0)
settingsView.anchorX = 0
settingsView.anchorY = 0
transition.to(settingsView, {time = 700, y = 200, transition = easing.outBounce, onComplete = function() settingsView:addEventListener(“tap”, hideSettings) end})
end
function hideSettings:tap(e)
playBtn.isVisible = true
settingsBtn.isVisible = true
transition.to(settingsView, {time = 500, y = 0, onComplete = function() settingsView:removeEventListener(“tap”, hideSettings) display.remove(settingsView) end})
end
function showGameView:tap(e)
transition.to(titleView, {time = 500, x = -titleView.height, onComplete = function() startButtonListeners(“rmv”) display.remove(titleView) titleView = nil end})
local bg = display.newImage(“gameBg.png”)
bg.anchorX = 0; bg.anchorY = 0