Runtime Error - need some help!

Hi all,
I’m new to lua and programming in general. I’m a bit stuck with this particular error message. I don’t really understand what it means and where I have gone wrong.

The error message is:
“Runtime error
?:0: attempt to concatenate global ‘sceneName’ (a nil value)
stack traceback:
[C]: ?
?: in function ‘gotoScene’
/Users/William/Development/Digimals/mainMenu.lua:21: in function ‘onRelease’
?: in function <?:191>
?: in function <?:226>”

If anyone could help me out and let me know what i’m doing wrong that’d be great!
Here is my mainMenu.lua file.

[code]


– mainMenu.lua


local storyboard = require( “storyboard” )
local scene = storyboard.newScene()
local widget = require “widget”
local env = require(“env”)

– BEGINNING OF YOUR IMPLEMENTATION

local image

–Touch event listener for new game
local function newGame(event)
storyboard.gotoScene( “mainScene”, “fade”, 400 )

end

local function exitApp(event)
saveDigi()
os.exit()

end

function scene:createScene( event )
local screenGroup = self.view

image = display.newImage( ‘img/normBG.png’)
image.x, image.y = 0,0
image:setReferencePoint(display.CenterReferencePoint)
image.rotation = -90
image.x, image.y = image.height/2,image.width/2
screenGroup:insert( image )
end

– Called immediately after scene has moved onscreen:
function scene:enterScene( event )

print( “1: enterScene event” )

local newGameButton = widget.newButton{
label = “Start”,
onRelease = newGame
}
newGameButton.x = 240
newGameButton.y = 160

local exitGameButton = widget.newButton{
label = “Exit”,
onRelease = exitApp
}
exitGameButton.x = 240
exitGameButton.y = 210

end
– Called when scene is about to move offscreen:
function scene:exitScene( event )

print( “1: exitScene event” )

– remove button
display.remove(newGameButton)
display.remove(exitGameButton)

– remove touch listener for image
–image:removeEventListener( “tap”, image )

end
– Called prior to the removal of scene’s “view” (display group)
function scene:destroyScene( event )

print( “((destroying scene 1’s view))” )
end


– END OF YOUR IMPLEMENTATION

– “createScene” event is dispatched if scene’s view does not exist
scene:addEventListener( “createScene”, scene )

– “enterScene” event is dispatched whenever scene transition has finished
scene:addEventListener( “enterScene”, scene )

– “exitScene” event is dispatched before next scene’s transition begins
scene:addEventListener( “exitScene”, scene )

– “destroyScene” event is dispatched before view is unloaded, which can be
– automatically unloaded in low memory situations, or explicitly via a call to
– storyboard.purgeScene() or storyboard.removeScene().
scene:addEventListener( “destroyScene”, scene )


return scene
[/code] [import]uid: 88841 topic_id: 30760 reply_id: 330760[/import]

Make sure the file mainScene.lua exists in the folder where your other lua files are. Also make sure that it is the correct case e.g. mixed case as you have typed it.

It looks like the error is due to the file not being found and therefore cannot go to the screen as it is NIL.

[import]uid: 103163 topic_id: 30760 reply_id: 123175[/import]

Yeah I did check all that. I made sure the files were in the right folder and were named correctly.
Double and triple checked the spelling.

I can’t see anything else wrong with this file.

EDIT: I just double checked again and the files are in the same location and are named correctly.
I have renamed the ‘mainScene’ file to something else (and changed all code relating to it) and still get the error.

Can anyone else see any issues with this that I am missing? [import]uid: 88841 topic_id: 30760 reply_id: 123213[/import]

Make sure the file mainScene.lua exists in the folder where your other lua files are. Also make sure that it is the correct case e.g. mixed case as you have typed it.

It looks like the error is due to the file not being found and therefore cannot go to the screen as it is NIL.

[import]uid: 103163 topic_id: 30760 reply_id: 123175[/import]

@Leginus, I pasted your code into the storyboard sample code main.lu and changed the scene name in the goto() function to “scene1” . The error I got was that the ‘env’ module that you require on line 10 was not found. When I commented out that require, it worked just fine. Could be that you do have env.lua in your directory, but it has is an error which won’t let it load.

Also, you are calling a global saveDigi() function in your main.lua file (line 26), which is not defined. If this is not yet causing you trouble, it most likely will when the app tries to call it.

Hope this helps! And, if you’re new to programming, it would be worth it to spend some time on youtube.com/cheetomoskeeto watching Raphael Hernandez’s video tutorials.

Good luck!
Chris [import]uid: 97836 topic_id: 30760 reply_id: 123676[/import]

Yeah I did check all that. I made sure the files were in the right folder and were named correctly.
Double and triple checked the spelling.

I can’t see anything else wrong with this file.

EDIT: I just double checked again and the files are in the same location and are named correctly.
I have renamed the ‘mainScene’ file to something else (and changed all code relating to it) and still get the error.

Can anyone else see any issues with this that I am missing? [import]uid: 88841 topic_id: 30760 reply_id: 123213[/import]

@Leginus, I pasted your code into the storyboard sample code main.lu and changed the scene name in the goto() function to “scene1” . The error I got was that the ‘env’ module that you require on line 10 was not found. When I commented out that require, it worked just fine. Could be that you do have env.lua in your directory, but it has is an error which won’t let it load.

Also, you are calling a global saveDigi() function in your main.lua file (line 26), which is not defined. If this is not yet causing you trouble, it most likely will when the app tries to call it.

Hope this helps! And, if you’re new to programming, it would be worth it to spend some time on youtube.com/cheetomoskeeto watching Raphael Hernandez’s video tutorials.

Good luck!
Chris [import]uid: 97836 topic_id: 30760 reply_id: 123676[/import]

If anyone is goooogling for: “attempt to concatenate global ‘sceneName’ (a nil value)”, this might help.

I made a test project to try out gotoScenes from *menu to *Scene1 and then to Scene2. I got it to work from *menu to *scene1 and back, but got the awful “attempt to concatenate global ‘sceneName’ (a nil value)” when trying to go to *scene2.

I searched everywhere and tried everything in my code but couldnt find the answer. By accident I figured out what caused the problem.

I made *scene1.lua, saved it, and copied and pasted all the code to *scene2.lua, BUT … I forgot to save *scene2.lua  :wacko:

The simulator didnt find the *scene2.lua file because it wasnt saved in my project  :ph34r:

Hope this can help you save some headace  B)

If anyone is goooogling for: “attempt to concatenate global ‘sceneName’ (a nil value)”, this might help.

I made a test project to try out gotoScenes from *menu to *Scene1 and then to Scene2. I got it to work from *menu to *scene1 and back, but got the awful “attempt to concatenate global ‘sceneName’ (a nil value)” when trying to go to *scene2.

I searched everywhere and tried everything in my code but couldnt find the answer. By accident I figured out what caused the problem.

I made *scene1.lua, saved it, and copied and pasted all the code to *scene2.lua, BUT … I forgot to save *scene2.lua  :wacko:

The simulator didnt find the *scene2.lua file because it wasnt saved in my project  :ph34r:

Hope this can help you save some headace  B)