Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

storyboard.goToScene error
Started by w.ummels Sep 07 2019 02:41 AM

4 replies to this topic
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

w.ummels

[GLOBAL: userInfoPane.html]
w.ummels
  • Observer

  • 15 posts
  • Corona SDK

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 )


[TOPIC: post.html]
#2

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Contributor

  • 892 posts
  • Corona SDK

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.



[TOPIC: post.html]
#3

nick_sherman

[GLOBAL: userInfoPane.html]
nick_sherman
  • Corona Geek

  • 1,820 posts
  • Corona SDK

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.


  • SGS likes this

[TOPIC: post.html]
#4

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Contributor

  • 892 posts
  • Corona SDK

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. :D

 

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



[TOPIC: post.html]
#5

w.ummels

[GLOBAL: userInfoPane.html]
w.ummels
  • Observer

  • 15 posts
  • Corona SDK

thank you for all of your answers!




[topic_controls]
[/topic_controls]