what dose this mean! help

 what dose this error mean

 Attempt to index local ‘planet’ (a nil value)

?: in function ‘dispatchEvent’

    ?: in function ‘gotoScene’

local planet = display.newImage(“planet.png”)

planet:setReferencePoint(display.BottomLeftReferencePoint)

planet.x = 0

planet.y = 480

p.s until this is solved i can’t continue to code

(push) please help

I’m going to guess that “planet.png” doesn’t exist

[quote name=“Rob Miracle” post=“231022” timestamp=“1392342678”]I’m going to guess that “planet.png” doesn’t exist[/quote] It dose and its in the same folder

Check the file name and case of the file. Are you sure it’s not in a folder named “images” or something?

i fixed it but now i have another error

heres what it is

Line: 157

Attempt to index global ‘planet1’ (a nil value)

all the code for that object

    local planet1 = display.newImage(“planet.png”)

    planet1.anchorX = 0.5

    planet1.anchorY = 0.5

    planet1.x = 0

    planet1.y = 480

    Group:insert(planet1)

and 

function scrollPlanet (self,event)

 if self.x < -393 then

self.x = 393

else

     self.x = self.x -10

   

end

end

also last thing

this is line 157 and 158

planet1.enterFrame = scrollPlanet  

Runtime : addEventListener(“enterFrame” , planet1)

Hi wpcorley02,

As it is your code works.

I believe there few lines of code in between  start of your code to line 157.

The reason line 157 cause error because it did not ‘recognise’ the line local planet1 = …

This could happen if you declare your local planet1 in another local function() and your planet1.enterFrame is out of this function.

e.g

local function myFunction()

  local planet1 = display.newImage(“planet.png”)   — this is localise within the function

  —

end

planet1.enterFrame = scrollPlanet  — this is outside of the function so lua doesn’t know what is planet1.

Also, if you are using storyboard, check that there are together in the same scene function. like scene:createScene() or scene:enterScene()

Good Luck!

burhan

thank you soooo much

i tried forever now it worked

one question

it made me put all the functions and graphics and event listeners

in create scene

what goes in enter scene?

thank you

i got it to work by making all the locals global

Making all the locals to global is not the best solution although it may work.

Try to avoid using global where possible.

You may want to read up on some tutorials on using storyboard and tips on how to remove globals and use local.

Start using local earlier on your development. 

Trust me. if your code gets longer and memory usage is critical then you might start banging your head. :o

burhan

Here is an example how you do local from your code.

local storyboard = require ("storyboard") local scene = storyboard.newScene() local planet1 --\> declare local here first function scene:createScene(event) --- planet1 = display.newImage("planet.png") --\> this planet1 is declared local above planet1.anchorX = 0.5 planet1.anchorY = 0.5 planet1.x = 0 planet1.y = 480 --- end local function scrollPlanet (self,event) ---\> other functions can be local ---- end function scene:enterScene(event) planet1.enterFrame = scrollPlanet ---\> should not have nil error Runtime:addEventListener("enterFrame" , planet1) end

Happy coding!

burhan

I’m going to guess that “planet.png” doesn’t exist

[quote name=“Rob Miracle” post=“231022” timestamp=“1392342678”]I’m going to guess that “planet.png” doesn’t exist[/quote] It dose and its in the same folder

Check the file name and case of the file. Are you sure it’s not in a folder named “images” or something?

i fixed it but now i have another error

heres what it is

Line: 157

Attempt to index global ‘planet1’ (a nil value)

all the code for that object

    local planet1 = display.newImage(“planet.png”)

    planet1.anchorX = 0.5

    planet1.anchorY = 0.5

    planet1.x = 0

    planet1.y = 480

    Group:insert(planet1)

and 

function scrollPlanet (self,event)

 if self.x < -393 then

self.x = 393

else

     self.x = self.x -10

   

end

end

also last thing

this is line 157 and 158

planet1.enterFrame = scrollPlanet  

Runtime : addEventListener(“enterFrame” , planet1)

Hi wpcorley02,

As it is your code works.

I believe there few lines of code in between  start of your code to line 157.

The reason line 157 cause error because it did not ‘recognise’ the line local planet1 = …

This could happen if you declare your local planet1 in another local function() and your planet1.enterFrame is out of this function.

e.g

local function myFunction()

  local planet1 = display.newImage(“planet.png”)   — this is localise within the function

  —

end

planet1.enterFrame = scrollPlanet  — this is outside of the function so lua doesn’t know what is planet1.

Also, if you are using storyboard, check that there are together in the same scene function. like scene:createScene() or scene:enterScene()

Good Luck!

burhan

thank you soooo much

i tried forever now it worked

one question

it made me put all the functions and graphics and event listeners

in create scene

what goes in enter scene?

thank you

i got it to work by making all the locals global

Making all the locals to global is not the best solution although it may work.

Try to avoid using global where possible.

You may want to read up on some tutorials on using storyboard and tips on how to remove globals and use local.

Start using local earlier on your development. 

Trust me. if your code gets longer and memory usage is critical then you might start banging your head. :o

burhan

Here is an example how you do local from your code.

local storyboard = require ("storyboard") local scene = storyboard.newScene() local planet1 --\> declare local here first function scene:createScene(event) --- planet1 = display.newImage("planet.png") --\> this planet1 is declared local above planet1.anchorX = 0.5 planet1.anchorY = 0.5 planet1.x = 0 planet1.y = 480 --- end local function scrollPlanet (self,event) ---\> other functions can be local ---- end function scene:enterScene(event) planet1.enterFrame = scrollPlanet ---\> should not have nil error Runtime:addEventListener("enterFrame" , planet1) end

Happy coding!

burhan