Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Problem with Getting Started
Started by Poul Jul 28 2018 01:59 AM

14 replies to this topic
getting started star explorer

Best Answer Appletreeman , 01 August 2018 - 08:45 AM

In your menu.lua file

function scene:create(event)
  local sceneGroup=self.view
  
  local background=display.newImageRect("background.png",760,1300)
  background.x=display.contentCenterX
  background.y=display.contentCenterY

  --Формат RGB-таблицы цветов реализован с делением на 255.
  local title=display.newText("Welcome to Space Shooter",display.contentCenterX,display.contentCenterY/2.6,native.systemFontBold,48)
  title:setFillColor(100/255,149/255,237/255)
    
  local playButton=display.newText("Play",display.contentCenterX-150,display.contentCenterY+25,native.systemFontBold,56)
  playButton:setFillColor(105/255,105/255,105/255)
    
  local scoreButton=display.newText("Score",display.contentCenterX+150,display.contentCenterY+25,native.systemFont,56)
  scoreButton:setFillColor(	255/255,239/255,213/255)

  playButton:addEventListener("tap",GoToGame)
  scoreButton:addEventListener("tap",GoToScoreTable)
end

the display objects that you have created are not being added to the composer scene group.  This means that when you are clicking the start button they are staying on the screen on top of anything that is being created in the game scene.

 

At the very least you should add "sceneGroup, " to each of the display objects, such as...

local title=display.newText(sceneGroup, "Welcome to Space Shooter",display.contentCenterX,display.contentCenterY/2.6,native.systemFontBold,48)

There are also some issues with your game scene but they should be easier to track down.

 

[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

Poul

[GLOBAL: userInfoPane.html]
Poul
  • Observer

  • 11 posts
  • Corona SDK

Hi all.
Help me with some problem in Getting Started. When I start project and click to "play" button, then get the next error:

"GameScene.lua:168:attempt to compare nil with number."

Its strange for me, because my code is similar codes in lessons.
Help me and I will be thanks you)

P.S. Sorry, if somewhere my English is bad.

 



[TOPIC: post.html]
#2

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 24,968 posts
  • Corona Staff

What is line 168 of GameScene.lua?

 

It sounds like it might be an "if" statement that's comparing a variable to a number based on the error. Whatever that variable is pointing to (object, table, etc. ) is nil. Your challenge is to figure out why that object is nil.

 

Rob



[TOPIC: post.html]
#3

Poul

[GLOBAL: userInfoPane.html]
Poul
  • Observer

  • 11 posts
  • Corona SDK

Yes, its operator "if":
 

167| local thisSO=SpaceObj[i]
168| if ( thisSO.x < -100 or
169| thisSO.x > display.contentWidth + 100 or
170| thisSO.y < -100 or
171| thisSO.y > display.contentHeight + 100 ) then
172|       display.remove(thisSO)
173|       table.remove(SpaceObj,i)
174| end

Adding asteroids in table is working OK and no problem. Same, if I load GameScene.lua via main.lua then game load without problems and I can to start game.
I thought that problem with file menu.lua, but haven't seen error in my code.

P.S. I added project's files in .rar, but why moderator hasn't allowed it?
P.P.S What official forum's language? Or is he absent?


[TOPIC: post.html]
#4

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 24,968 posts
  • Corona Staff

Based on the error message and this code, thisSO.x is nil. This is likely because SpaceObj[i] is nil, or not a table. Perhaps "i" isn't what you think it is. Perhaps SpaceObj[i] isn't what you think it is.

 

Some simple basic diagnostics using the print statement and the Corona console log will help you figure out what's going on.  I would add this line of code before line 167:

local json = require("json")
print( "i = ", i, "SpaceObj[i] type = ", type(SpaceObj[i] )
print( json.prettify( SpaceObj[i] )

This will tell you what those variables are and may clue you as to why they are not what you're expecting them to be.

 

Next, when posting code, it's always best to use code formatting. The easiest way to do this is when you want to post your code, click on the blue <> button in the formatting row with Bold, Italic, etc. In the popup window, paste your code into it and there should be an option to put in a starting line number, when line numbers are important.  This will help everyone looking to help you greatly.

 

Regarding .rar files, not everyone can decode them. We ask that you use .zip for sharing code projects. Also, there is limited upload space, so it's always best to put your .zip file on a service like DropBox, Google Drive, etc. and post a sharing link here to the archive on your cloud storage.

 

Finally, English is the official forum language. There are a few sub-forums that are language specific, like Spanish, Italian, etc. We ask that posts outside of those language specific forums be posted in English.

 

Rob



[TOPIC: post.html]
#5

Poul

[GLOBAL: userInfoPane.html]
Poul
  • Observer

  • 11 posts
  • Corona SDK

Variables are what Im expecting them to be: "i" is number and "SpaceObj" is table.
My all project: https://drive.google.com/file/d/1hkUCL02dAVJiDwLYKe9c08lc6At1qTJn/view?usp=sharing

But why my game normal starting if I start this in main.lua:

local composer = require( "composer" )

-- Hide status bar
display.setStatusBar( display.HiddenStatusBar )
 
-- Seed the random number generator
math.randomseed( os.time() )

-- Go to the menu screen
composer.gotoScene( "GameScene" )

But when I started the game in menu.lua then have error?



[TOPIC: post.html]
#6

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 24,968 posts
  • Corona Staff

Can you copy/paste the results of the print statements in your console log for us?

 

Rob



[TOPIC: post.html]
#7

Poul

[GLOBAL: userInfoPane.html]
Poul
  • Observer

  • 11 posts
  • Corona SDK

Ofcourse:

18:53:53.696  i = 1 ; SpaceObj[i] type = table
18:53:53.696  {
18:53:53.696    "_class":{
18:53:53.696      "removeEventListener":"<type 'function' is not supported by JSON.>",
18:53:53.696      "addEventListener":"<type 'function' is not supported by JSON.>",
18:53:53.696      "__index":"<reference cycle>"
18:53:53.696    },
18:53:53.696    "_proxy":"<type 'userdata' is not supported by JSON.>",
18:53:53.696    "myName":"meteor"
18:53:53.696  }
18:53:54.218  i = 2 ; SpaceObj[i] type = table
18:53:54.218  {
18:53:54.218    "_class":{
18:53:54.218      "removeEventListener":"<type 'function' is not supported by JSON.>",
18:53:54.218      "addEventListener":"<type 'function' is not supported by JSON.>",
18:53:54.218      "__index":"<reference cycle>"
18:53:54.218    },
18:53:54.218    "_proxy":"<type 'userdata' is not supported by JSON.>",
18:53:54.218    "myName":"meteor"
18:53:54.218  }
18:53:54.218  i = 1 ; SpaceObj[i] type = table
18:53:54.218  {
18:53:54.218    "_class":{
18:53:54.218      "removeEventListener":"<type 'function' is not supported by JSON.>",
18:53:54.218      "addEventListener":"<type 'function' is not supported by JSON.>",
18:53:54.218      "__index":"<reference cycle>"
18:53:54.218    },
18:53:54.218    "_proxy":"<type 'userdata' is not supported by JSON.>",
18:53:54.218    "myName":"meteor"
18:53:54.218  }
18:53:54.728  i = 2 ; SpaceObj[i] type = table
18:53:54.728  {
18:53:54.728    "_class":{
18:53:54.728      "removeEventListener":"<type 'function' is not supported by JSON.>",
18:53:54.728      "addEventListener":"<type 'function' is not supported by JSON.>",
18:53:54.728      "__index":"<reference cycle>"
18:53:54.728    },
18:53:54.728    "_proxy":"<type 'userdata' is not supported by JSON.>",
18:53:54.728    "myName":"meteor"
18:53:54.728  }
18:53:54.728  i = 1 ; SpaceObj[i] type = table
18:53:54.728  {
18:53:54.728    "_class":{
18:53:54.728      "removeEventListener":"<type 'function' is not supported by JSON.>",
18:53:54.728      "addEventListener":"<type 'function' is not supported by JSON.>",
18:53:54.728      "__index":"<reference cycle>"
18:53:54.728    },
18:53:54.728    "_proxy":"<type 'userdata' is not supported by JSON.>",
18:53:54.728    "myName":"meteor"
18:53:54.728  }
18:53:55.228  i = 3 ; SpaceObj[i] type = table
18:53:55.228  {
18:53:55.228    "_class":{
18:53:55.228      "removeEventListener":"<type 'function' is not supported by JSON.>",
18:53:55.228      "addEventListener":"<type 'function' is not supported by JSON.>",
18:53:55.228      "__index":"<reference cycle>"
18:53:55.228    },
18:53:55.228    "_proxy":"<type 'userdata' is not supported by JSON.>",
18:53:55.228    "myName":"meteor"
18:53:55.228  }
18:53:55.228  i = 2 ; SpaceObj[i] type = table
18:53:55.228  {
18:53:55.228    "_class":{
18:53:55.228      "removeEventListener":"<type 'function' is not supported by JSON.>",
18:53:55.228      "addEventListener":"<type 'function' is not supported by JSON.>",
18:53:55.228      "__index":"<reference cycle>"
18:53:55.228    },
18:53:55.228    "_proxy":"<type 'userdata' is not supported by JSON.>",
18:53:55.228    "myName":"meteor"
18:53:55.228  }
18:53:55.228  i = 1 ; SpaceObj[i] type = table
18:53:55.228  {
18:53:55.228    "_class":{
18:53:55.228      "removeEventListener":"<type 'function' is not supported by JSON.>",
18:53:55.228      "addEventListener":"<type 'function' is not supported by JSON.>",
18:53:55.228      "__index":"<reference cycle>"
18:53:55.228    },
18:53:55.228    "_proxy":"<type 'userdata' is not supported by JSON.>",
18:53:55.228    "myName":"meteor"
18:53:55.228  }
18:53:55.748  i = 4 ; SpaceObj[i] type = table
18:53:55.748  {
18:53:55.748    "_class":{
18:53:55.748      "removeEventListener":"<type 'function' is not supported by JSON.>",
18:53:55.748      "addEventListener":"<type 'function' is not supported by JSON.>",
18:53:55.748      "__index":"<reference cycle>"
18:53:55.748    },
18:53:55.748    "_proxy":"<type 'userdata' is not supported by JSON.>",
18:53:55.748    "myName":"meteor"
18:53:55.748  }
18:53:55.748  i = 3 ; SpaceObj[i] type = table
18:53:55.748  {
18:53:55.748    "_class":{
18:53:55.748      "removeEventListener":"<type 'function' is not supported by JSON.>",
18:53:55.748      "addEventListener":"<type 'function' is not supported by JSON.>",
18:53:55.748      "__index":"<reference cycle>"
18:53:55.748    },
18:53:55.748    "_proxy":"<type 'userdata' is not supported by JSON.>",
18:53:55.748    "myName":"meteor"
18:53:55.748  }
18:53:55.748  i = 2 ; SpaceObj[i] type = table
18:53:55.748  {
18:53:55.748    "_class":{
18:53:55.748      "removeEventListener":"<type 'function' is not supported by JSON.>",
18:53:55.748      "addEventListener":"<type 'function' is not supported by JSON.>",
18:53:55.748      "__index":"<reference cycle>"
18:53:55.748    },
18:53:55.748    "_proxy":"<type 'userdata' is not supported by JSON.>",
18:53:55.748    "myName":"meteor"
18:53:55.748  }
18:53:55.748  i = 1 ; SpaceObj[i] type = table
18:53:55.748  {
18:53:55.748    "_class":{
18:53:55.748      "removeEventListener":"<type 'function' is not supported by JSON.>",
18:53:55.748      "addEventListener":"<type 'function' is not supported by JSON.>",
18:53:55.748      "__index":"<reference cycle>"
18:53:55.748    },
18:53:55.748    "_proxy":"<type 'userdata' is not supported by JSON.>",
18:53:55.748    "myName":"meteor"
18:53:55.748  }
18:53:56.488  i = 5 ; SpaceObj[i] type = table
18:53:56.488  {
18:53:56.488    "_class":{
18:53:56.488      "removeEventListener":"<type 'function' is not supported by JSON.>",
18:53:56.488      "addEventListener":"<type 'function' is not supported by JSON.>",
18:53:56.488      "__index":"<reference cycle>"
18:53:56.488    },
18:53:56.488    "_proxy":"<type 'userdata' is not supported by JSON.>",
18:53:56.488    "myName":"meteor"
18:53:56.488  }
18:53:56.488  i = 4 ; SpaceObj[i] type = table
18:53:56.488  {
18:53:56.488    "myName":"meteor"
18:53:56.488  }
18:53:56.498  ERROR: Runtime error


[TOPIC: post.html]
#8

Poul

[GLOBAL: userInfoPane.html]
Poul
  • Observer

  • 11 posts
  • Corona SDK

Well...is it error in engine or it my error anywhere in code?



[TOPIC: post.html]
#9

Appletreeman

[GLOBAL: userInfoPane.html]
Appletreeman
  • Contributor

  • 403 posts
  • Corona SDK

  Best Answer

In your menu.lua file

function scene:create(event)
  local sceneGroup=self.view
  
  local background=display.newImageRect("background.png",760,1300)
  background.x=display.contentCenterX
  background.y=display.contentCenterY

  --Формат RGB-таблицы цветов реализован с делением на 255.
  local title=display.newText("Welcome to Space Shooter",display.contentCenterX,display.contentCenterY/2.6,native.systemFontBold,48)
  title:setFillColor(100/255,149/255,237/255)
    
  local playButton=display.newText("Play",display.contentCenterX-150,display.contentCenterY+25,native.systemFontBold,56)
  playButton:setFillColor(105/255,105/255,105/255)
    
  local scoreButton=display.newText("Score",display.contentCenterX+150,display.contentCenterY+25,native.systemFont,56)
  scoreButton:setFillColor(	255/255,239/255,213/255)

  playButton:addEventListener("tap",GoToGame)
  scoreButton:addEventListener("tap",GoToScoreTable)
end

the display objects that you have created are not being added to the composer scene group.  This means that when you are clicking the start button they are staying on the screen on top of anything that is being created in the game scene.

 

At the very least you should add "sceneGroup, " to each of the display objects, such as...

local title=display.newText(sceneGroup, "Welcome to Space Shooter",display.contentCenterX,display.contentCenterY/2.6,native.systemFontBold,48)

There are also some issues with your game scene but they should be easier to track down.

 



[TOPIC: post.html]
#10

Poul

[GLOBAL: userInfoPane.html]
Poul
  • Observer

  • 11 posts
  • Corona SDK

Thank you. All work.
And, what is some issues with my game scene?



[TOPIC: post.html]
#11

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 24,968 posts
  • Corona Staff

The code you first posted is removing objects that have left the screen. It appears that object #4 is getting removed somewhere else in your code.  If you look at the first time it prints out you see:

18:53:55.748  i = 4 ; SpaceObj[i] type = table
18:53:55.748  {
18:53:55.748    "_class":{
18:53:55.748      "removeEventListener":"<type 'function' is not supported by JSON.>",
18:53:55.748      "addEventListener":"<type 'function' is not supported by JSON.>",
18:53:55.748      "__index":"<reference cycle>"
18:53:55.748    },
18:53:55.748    "_proxy":"<type 'userdata' is not supported by JSON.>",
18:53:55.748    "myName":"meteor"
18:53:55.748  }

but right before it crashes, it prints this:

18:53:56.488  i = 4 ; SpaceObj[i] type = table
18:53:56.488  {
18:53:56.488    "myName":"meteor"
18:53:56.488  }
18:53:56.498  ERROR: Runtime error

So the _class and _proxy entries are missing. These are the parts that make an object a "display object" that gives it .x and .y properties and so much more.

 

This tells me there is a display.remove() call happening somewhere else that's not removing the object from your SpaceObj table, since the code you're posting does remove it from the table.

 

Rob



[TOPIC: post.html]
#12

Poul

[GLOBAL: userInfoPane.html]
Poul
  • Observer

  • 11 posts
  • Corona SDK

I understood it as:
I forgot some objects in menu.lua as "title", "playButton" and "scoreButton" add to sceneGroup. And when I start the game then it started, but I didn't see this —> I tryed load GameScene second time via button that can see. Finally, Corona can't start game, that was started and I got error about this.

And now all work. Without errors.



[TOPIC: post.html]
#13

Poul

[GLOBAL: userInfoPane.html]
Poul
  • Observer

  • 11 posts
  • Corona SDK

I think that can to close this topic, because problem was decided.
Thank all.



[TOPIC: post.html]
#14

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 24,968 posts
  • Corona Staff

As a rule, we leave our forum posts open so others can learn about them. If you want and a particular response solved the problem you can mark the thread solved with which post solved the issue, but that's not required.

 

Rob



[TOPIC: post.html]
#15

Poul

[GLOBAL: userInfoPane.html]
Poul
  • Observer

  • 11 posts
  • Corona SDK

Right. Just, I know some forums where moderators close topics after best answer, leaving visible them. Thank for information, Rob.




[topic_controls]
[/topic_controls]

Also tagged with one or more of these keywords: getting started, star explorer