Something is wrong!

okay, heres the code, corona shows blank errors idk why:

[lua]function scene:createScene( physics )

table = display.newImageRect(“table1.png”,543,755 )
table.x = 154
table.y = 231
table.name = “img_1”

object1 = display.newImageRect(“object1.png”,140,140 )
object1.x = 162
object1.y = 586
local img_2_shape = {-47,19,18,-46,57,-70,70,-59,48,-21,-17,44,-66,70,-70,63 }
physics.addBody(object1,“static”,{density = 1, friction = 0, bounce = 0, shape = img_2_shape})
object1.name = “img_2”
object1.rotation = 135

object3 = display.newImageRect(“object3.png”,140,140 )
object3.x = 396
object3.y = 70
local img_3_shape = {-51,25,33,-58,60,-70,70,-62,60,-36,-25,51,-64,69,-68,60 }
physics.addBody(object3,“static”,{density = 1, friction = 0, bounce = 0, shape = img_3_shape})
object3.name = “img_3”
object3.rotation = 45

object2 = display.newImageRect(“object2.png”,140,140 )
object2.x = -96
object2.y = 68
local img_4_shape = {-51,23,22,-52,57,-70,69,-58,48,-21,-21,49,-62,69,-70,62 }
physics.addBody(object2,“static”,{density = 1, friction = 0, bounce = 0, shape = img_4_shape})
object2.name = “img_4”
object2.rotation = -135

end
[/lua]

I didn’t really change any other part of the code, please tell me what is the problem with this one

What’s the error message? It may be blank, but seeing the message block will help. When I run that code fragment I get this:

Copyright (C) 2009-2013  C o r o n a   L a b s   I n c . 2013-06-16 10:42:36.237 Corona Simulator[2098:707]     Version: 2.0.0 2013-06-16 10:42:36.237 Corona Simulator[2098:707]     Build: 2013.1137 2013-06-16 10:42:36.249 Corona Simulator[2098:707] The file sandbox for this project is located at the following folder:     (/Users/eudoxus/Library/Application Support/Corona Simulator/BlankError-FBE026370C1177BEA4295F1DFAD914BB) 2013-06-16 10:42:36.313 Corona Simulator[2098:707] Runtime error ...orona/MyApps/Dropbox/Public/Help/BlankError/main.lua:1: attempt to index global 'scene' (a nil value) stack traceback:     [C]: ?     ...orona/MyApps/Dropbox/Public/Help/BlankError/main.lua:1: in main chunk

I’ve now added these lines to the top of your listing:

storyboard = require( "storyboard" ) scene = storyboard.newScene()

And the error block I get is this:

Copyright (C) 2009-2013  C o r o n a   L a b s   I n c . 2013-06-16 10:45:14.831 Corona Simulator[2098:707]     Version: 2.0.0 2013-06-16 10:45:14.832 Corona Simulator[2098:707]     Build: 2013.1137 2013-06-16 10:45:14.841 Corona Simulator[2098:707] The file sandbox for this project is located at the following folder:     (/Users/eudoxus/Library/Application Support/Corona Simulator/BlankError-FBE026370C1177BEA4295F1DFAD914BB)

Which is definitely strange.

But I don’t understand why your createScene function parameter is called ‘physics’ - typically it would be called ‘event’, if you’re using the storyboard API.

[EDIT] Actually this is not strange - this is totally expected: I named the directory I put your code in “BlankError”, so this is not an error. This is simply a console message saying that nothing is happening.

okay, I changed it back to event, actually this is what I typed into level1.lua that gets created if you goto create new project and choose physics based application in corona. Now this is the console error:

[lua]

Copyright © 2009-2013  C o r o n a   L a b s   I n c .
        Version: 2.0.0
        Build: 2013.1137
Runtime error
?:0: attempt to call field ‘insert’ (a nil value)
stack traceback:
        [C]: in function ‘insert’
        ?: in function ‘addEventListener’
        ?: in function ‘addEventListener’
        ?: in function ‘_add’
        ?: in function ‘to’
        ?: in function ‘gotoScene’
        c:\u

[/lua]

And here’s a screenshot

iuOXMqeAIhOVi.png

I don’t see where you are trying to insert anything into the scene.  Normally function scene:createScene(event) has the following line of code immediately after it:

     local group = self.view

The scene’s “view” which is conveniently called “group” for you is a display.newGroup() that holds all of the scenes screen assets that you want storyboard to manage.  In this case you are not inserting anything in to the scene’s view, and this may be an issue with an empty scene.

Try putting that line  just below the function scene:createScene()  and then after you create each of your display.newImageRect() objects stick them in group like such:

     group:insert(object1)

Be aware you should not use a name like “table” as a variable as it will trash the “table” api, which can have very problematic circumstances (and in reality, I bet it’s what’s generating your error.)   You should also consider localizing those objects (either put the word “local” at the beginning of each line that calls display.newImageRect() etc. (but not in front of where you are setting the x, and y’s… just when you create it).  or put

local  object1

at the top of your code outside of the createScene function.

Wow! Thanks a ton! You solved my problem!

Just 1 thing, why are you suggesting adding local, it works without it too.

Anyways, I extremely appreciate you helping, thanks again.

You should always declare variables as local because if you don’t you are declare a global variable. Global variables stick around in memory and are accessible from all code. If you have a variable name which is likely to get used often (the name, not the variable) then you want to make sure that it is applicable in each piece of code and not widely used. What I mean is: if a small function has a variable called “width” you don’t want it to be global because then it loses its meaning.

This is a good starting point to read up on: http://www.coronalabs.com/blog/2012/03/27/storyboard-scene-events-explained/

I’m pretty sure there was a good tutorial on the blog about global and local variables some time ago, and one this month: http://www.coronalabs.com/blog/topics/tutorials/

Also, take a look at the official Lua language documentation: http://www.lua.org/manual/5.1/

What’s the error message? It may be blank, but seeing the message block will help. When I run that code fragment I get this:

Copyright (C) 2009-2013  C o r o n a   L a b s   I n c . 2013-06-16 10:42:36.237 Corona Simulator[2098:707]     Version: 2.0.0 2013-06-16 10:42:36.237 Corona Simulator[2098:707]     Build: 2013.1137 2013-06-16 10:42:36.249 Corona Simulator[2098:707] The file sandbox for this project is located at the following folder:     (/Users/eudoxus/Library/Application Support/Corona Simulator/BlankError-FBE026370C1177BEA4295F1DFAD914BB) 2013-06-16 10:42:36.313 Corona Simulator[2098:707] Runtime error ...orona/MyApps/Dropbox/Public/Help/BlankError/main.lua:1: attempt to index global 'scene' (a nil value) stack traceback:     [C]: ?     ...orona/MyApps/Dropbox/Public/Help/BlankError/main.lua:1: in main chunk

I’ve now added these lines to the top of your listing:

storyboard = require( "storyboard" ) scene = storyboard.newScene()

And the error block I get is this:

Copyright (C) 2009-2013  C o r o n a   L a b s   I n c . 2013-06-16 10:45:14.831 Corona Simulator[2098:707]     Version: 2.0.0 2013-06-16 10:45:14.832 Corona Simulator[2098:707]     Build: 2013.1137 2013-06-16 10:45:14.841 Corona Simulator[2098:707] The file sandbox for this project is located at the following folder:     (/Users/eudoxus/Library/Application Support/Corona Simulator/BlankError-FBE026370C1177BEA4295F1DFAD914BB)

Which is definitely strange.

But I don’t understand why your createScene function parameter is called ‘physics’ - typically it would be called ‘event’, if you’re using the storyboard API.

[EDIT] Actually this is not strange - this is totally expected: I named the directory I put your code in “BlankError”, so this is not an error. This is simply a console message saying that nothing is happening.

okay, I changed it back to event, actually this is what I typed into level1.lua that gets created if you goto create new project and choose physics based application in corona. Now this is the console error:

[lua]

Copyright © 2009-2013  C o r o n a   L a b s   I n c .
        Version: 2.0.0
        Build: 2013.1137
Runtime error
?:0: attempt to call field ‘insert’ (a nil value)
stack traceback:
        [C]: in function ‘insert’
        ?: in function ‘addEventListener’
        ?: in function ‘addEventListener’
        ?: in function ‘_add’
        ?: in function ‘to’
        ?: in function ‘gotoScene’
        c:\u

[/lua]

And here’s a screenshot

iuOXMqeAIhOVi.png

I don’t see where you are trying to insert anything into the scene.  Normally function scene:createScene(event) has the following line of code immediately after it:

     local group = self.view

The scene’s “view” which is conveniently called “group” for you is a display.newGroup() that holds all of the scenes screen assets that you want storyboard to manage.  In this case you are not inserting anything in to the scene’s view, and this may be an issue with an empty scene.

Try putting that line  just below the function scene:createScene()  and then after you create each of your display.newImageRect() objects stick them in group like such:

     group:insert(object1)

Be aware you should not use a name like “table” as a variable as it will trash the “table” api, which can have very problematic circumstances (and in reality, I bet it’s what’s generating your error.)   You should also consider localizing those objects (either put the word “local” at the beginning of each line that calls display.newImageRect() etc. (but not in front of where you are setting the x, and y’s… just when you create it).  or put

local  object1

at the top of your code outside of the createScene function.

Wow! Thanks a ton! You solved my problem!

Just 1 thing, why are you suggesting adding local, it works without it too.

Anyways, I extremely appreciate you helping, thanks again.

You should always declare variables as local because if you don’t you are declare a global variable. Global variables stick around in memory and are accessible from all code. If you have a variable name which is likely to get used often (the name, not the variable) then you want to make sure that it is applicable in each piece of code and not widely used. What I mean is: if a small function has a variable called “width” you don’t want it to be global because then it loses its meaning.

This is a good starting point to read up on: http://www.coronalabs.com/blog/2012/03/27/storyboard-scene-events-explained/

I’m pretty sure there was a good tutorial on the blog about global and local variables some time ago, and one this month: http://www.coronalabs.com/blog/topics/tutorials/

Also, take a look at the official Lua language documentation: http://www.lua.org/manual/5.1/