storyboard.goToScene error

hello!

i have recently starten on a simple vertical stroller game, and im already experiencing my first error.

whenever I try to start the simulator. this error is shown:

Unexpected symbol near ‘.’

 

File: main.lua

Line: 5

I cannot spot the error and I can’t find any similar error here. 

here is my code for main.lua:


– main.lua


local storyboard.goToScene “menu”

and here is the code for my menu.lua if connected to this error:

Local bgimage = display newImage (“Sprates/menu_bg.jpg”)

Group:insert( bgimage )

bgimage:addEventListener( “touch”, gotoGame )

Local gotoGamr = function( event )

   If event.phase == “ended” then

     Storyboard.gotoScene( “lvlmenu” )

   end

end

widget = require “widget”

Local playButton = widget.newbutton  (“Sprites/button1.jpg”) {

    Id = “btnplay”,

    left = 100,

    top = 200,

    width = 120,

    height = 40’

    cornerRadius = 10,

    onEvent = gotoGame

}

group:insert( playButton )

Since you are just starting out, I’d recommend using Corona’s built in scene manager, Composer, instead. Storyboard is an old library and composer is better supported.

Also, use the code formatting tools to make your code easier to read.

You are seeing the crash because of this line:

local storyboard.goToScene "menu"

Since the row starts with  local , Lua expects that you are going to declare a local variable/function, but when you suddenly have a dot between storyboard and goToScene, Lua expects that you are trying to access a reference inside a table, which can’t happen because you are trying to create a variable, etc.

You’d fix this by first requiring storyboard library and then trying to call the function inside the library, i.e.

local storyboard = require("storyboard") -- creates a table called "storyboard" storyboard.goToScene "menu" -- accesses "goToScene" inside "storyboard" table

But, again, I’d recommend just using Composer.

If that’s your code, it’s wrong in many, many places.

  1. Lua is case-sensitive. ‘Local’ is not a valid keyword, it should be ‘local’

  2. As above, you are using both ‘group’ and ‘Group’, and ‘storyboard’ and ‘Storyboard’. Choose one and stick to it.

  3. You mis-spelt ‘gotoGame’ as ‘gotoGamr’ in the definition of the function.

  4. There is no ‘.’ between display and newImage.

  5. You mis-spelt gotoScene as goToScene

  6. The name of the scene you want to go to should be within brackets.

  7. local storyboard.goToScene “menu” is not a valid command even if you fixed the above. You need to require storyboard in one line and then call storyboard.gotoScene(“menu”)

  8. You mis-spelt ‘Sprites’ as ‘Sprates’ on you bgimage.

  9. You’re using Storyboard which is a deprecated library. Composer is the replacement.

There’s probably more I haven’t spotted. Overall, you need to re-read the API docs and learn the basics of Lua programming. Programming languages require 100% accuracy, they cannot ‘guess’ what it is you want to do. If you feed it garbage, you will get garbage out.

Code one line at a time, and check it does what you think it should before moving on. There are so many errors here that even if you got line 5 of main.lua correct, the next crash would not be very far away.

I just read Nick’s post. Like a good programmer, I just read until I found the first error, which also happened to be the error in question. :smiley:

Like Nick said, there’s a lot to improve.

thank you for all of your answers!

Since you are just starting out, I’d recommend using Corona’s built in scene manager, Composer, instead. Storyboard is an old library and composer is better supported.

Also, use the code formatting tools to make your code easier to read.

You are seeing the crash because of this line:

local storyboard.goToScene "menu"

Since the row starts with  local , Lua expects that you are going to declare a local variable/function, but when you suddenly have a dot between storyboard and goToScene, Lua expects that you are trying to access a reference inside a table, which can’t happen because you are trying to create a variable, etc.

You’d fix this by first requiring storyboard library and then trying to call the function inside the library, i.e.

local storyboard = require("storyboard") -- creates a table called "storyboard" storyboard.goToScene "menu" -- accesses "goToScene" inside "storyboard" table

But, again, I’d recommend just using Composer.

If that’s your code, it’s wrong in many, many places.

  1. Lua is case-sensitive. ‘Local’ is not a valid keyword, it should be ‘local’

  2. As above, you are using both ‘group’ and ‘Group’, and ‘storyboard’ and ‘Storyboard’. Choose one and stick to it.

  3. You mis-spelt ‘gotoGame’ as ‘gotoGamr’ in the definition of the function.

  4. There is no ‘.’ between display and newImage.

  5. You mis-spelt gotoScene as goToScene

  6. The name of the scene you want to go to should be within brackets.

  7. local storyboard.goToScene “menu” is not a valid command even if you fixed the above. You need to require storyboard in one line and then call storyboard.gotoScene(“menu”)

  8. You mis-spelt ‘Sprites’ as ‘Sprates’ on you bgimage.

  9. You’re using Storyboard which is a deprecated library. Composer is the replacement.

There’s probably more I haven’t spotted. Overall, you need to re-read the API docs and learn the basics of Lua programming. Programming languages require 100% accuracy, they cannot ‘guess’ what it is you want to do. If you feed it garbage, you will get garbage out.

Code one line at a time, and check it does what you think it should before moving on. There are so many errors here that even if you got line 5 of main.lua correct, the next crash would not be very far away.

I just read Nick’s post. Like a good programmer, I just read until I found the first error, which also happened to be the error in question. :smiley:

Like Nick said, there’s a lot to improve.

thank you for all of your answers!