?:0: attempt to index field 'parent' (a nil value) message stack traceback:

Hi there, 

I’m running against to the following error:

?:0: attempt to index field ‘parent’ (a nil value)

message

stack traceback:

    ?: in function <?:218>

    [C]: ?

    ?: in function <?:400>

    ?: in function <?:218>

    

No line indication (there is no line 218 in the code).

It is happening every single time I click on an image (after run the listener code)

-- -- Story -- display.setStatusBar( display.DefaultStatusBar ) local storyboard = require( "storyboard" ) storyboard.purgeOnSceneChange = true -- create the new scene (story) local scene = storyboard.newScene() local content, navButton1, navButton2 local translation = require ("scripts.translation") local getTranslation = translation.getTranslation local widget = require( "widget" ) local green = 100 local variation = -.5 local mainGroup local navButton1 local navButton2 local frameButton local backButton local scrollView function onBackButtonTouch( event ) -- listener cannot appear after define the button if event.phase == "began" then Runtime:removeEventListener("enterFrame", changeFrameColor) local storyboardOptions = {effect="slideLeft", time=750} storyboard.gotoScene( "menu", storyboardOptions ) end return true end function changePage ( event ) if event.phase == "began" then showPageNavigation(event.target.pageNumber) end return true -- \<\<\<---HERE IS WHERE THE ERROR IS RAISING end function loadContent(pageNumber) content = display.newImageRect( getTranslation("story", language, "PAGE" .. pageNumber), 744, 1052) content.x = (contentWidth / 2) content.y = content.contentHeight / 2 content:setReferencePoint(display.TopLeftReferencePoint) if scrollView.numChildren \> 1 then scrollView:remove(1) end scrollView:insert( content ) scrollView:scrollTo( "top", { time = 1 } ) end function showPageNavigation(currentPage) if currentPage == 1 then frameButton.y = navButton1.y else frameButton.y = navButton2.y end loadContent(currentPage) end function changeFrameColor( event ) frameButton:setFillColor(green, green, green-99,255) green = green + variation if green \< 100 or green \> 180 then variation = variation \* -1 end end function setupInterface() navButton1 = display.newImageRect( getTranslation("story", language, "THUMB1"), 90, 127) navButton2 = display.newImageRect( getTranslation("story", language, "THUMB2"), 90, 127) navButton1.x = navButton1.contentWidth / 1.3 navButton1.y = navButton1.contentHeight navButton1.pageNumber = 1 navButton1:setReferencePoint(display.CenterReferencePoint) navButton2.x = navButton2.contentWidth / 1.3 navButton2.y = navButton2.contentHeight \* 2.2 navButton2.pageNumber = 2 navButton2:setReferencePoint(display.CenterReferencePoint) frameButton = display.newRect(navButton1.x, navButton1.y, navButton1.contentWidth + 16, navButton1.contentHeight + 16) frameButton.x = navButton1.x frameButton.y = navButton1.y frameButton:setFillColor(5, green, 5, 255) frameButton:setReferencePoint(display.CenterReferencePoint) -- Create a ScrollView scrollView = widget.newScrollView { backgroundColor={0,0,0}, left = 0, top = 0, width = contentWidth, height = contentHeight, scrollWidth = contentWidth, scrollHeight = contentHeight, id = "onBottom", horizontalScrollingDisabled = true, verticalScrollingDisabled = false, } backButton = display.newImageRect("images/back.png", 90, 101) backButton.x = frameButton.x backButton.y = contentHeight - frameButton.contentHeight / 2 backButton:setReferencePoint(display.CenterReferencePoint) backButton:addEventListener("touch", onBackButtonTouch) navButton1:addEventListener("touch", changePage) navButton2:addEventListener("touch", changePage) end -- Called when the scene's view does not exist: function scene:createScene( event ) local prior\_scene = storyboard.getPrevious() if prior\_scene ~= nil then storyboard.removeScene( prior\_scene ) end mainGroup = self.view setupInterface() showPageNavigation(1) mainGroup:insert(scrollView) mainGroup:insert(frameButton) mainGroup:insert(navButton1) mainGroup:insert(navButton2) mainGroup:insert(backButton) Runtime:addEventListener("enterFrame", changeFrameColor) end -- Called immediately after scene has moved onscreen: function scene:enterScene( event ) end -- Called when scene is about to move offscreen: function scene:exitScene( event ) local group = self.view end -- If scene's view is removed, scene:destroyScene() will be called just prior to: function scene:destroyScene( event ) local group = self.view end ----------------------------------------------------------------------------------------- -- END OF YOUR IMPLEMENTATION ----------------------------------------------------------------------------------------- -- "createScene" event is dispatched if scene's view does not exist scene:addEventListener( "createScene", scene ) -- "enterScene" event is dispatched whenever scene transition has finished scene:addEventListener( "enterScene", scene ) -- "exitScene" event is dispatched whenever before next scene's transition begins scene:addEventListener( "exitScene", scene ) -- "destroyScene" event is dispatched before view is unloaded, which can be -- automatically unloaded in low memory situations, or explicitly via a call to --storyboard.purgeScene() or storyboard.removeScene(). scene:addEventListener( "destroyScene", scene ) -- Without the folloing line the code would bomb with a "gotoScene" error return scene -----------------------------------------------------------------------------------------

The code above could be improved a lot, but I’m stuck with this error…

Any ideas anyone ?

Regards, Emerson

It’s possible line 64 is throwing the error.  Can we see getTranslation code?  Or maybe on line 63 do print(getTranslation(“story”, language, “PAGE” … pageNumber)

Hi, 

Thank you for your reply. 

I double checked getTranslation and it  is returning localized image used as page navigation correctly.

This is the output after include the print before image creation line, as requested:

    images/Page_1_BR.png   

    images/Page_2_BR.png    

First line > first time the module is executed

Second line > after click on second image button

However, I’ve noticed that the error is happening in a different place…The listener code actually finish without an error, but after its execution, the “enterFrame” event is fired as expected, running the following code:

function changeFrameColor( event ) frameButton:setFillColor(green, green, green-99,255) green = green + variation if green \< 100 or green \> 180 then variation = variation \* -1 end end \<\<\< THIS IS WHERE ACTUALLY THE ERROR IS HAPPENING

When the code above finish the error is raised. Oddly enough that code is fine and running correctly after every enter frame event until I click in an image (which triggers the listener “changePage”). The frameButton object is fine, so green and variation variables. The error occurs right after the end of the changeFrameColor function. 

Emerson

Ah…damn scrollview…

here is what happened…

The code below was inserted to prevent a memory leak…memory leak that would not happen if the code was correct in first place…instead to load the image every time the user click in a different page it should (and will) load it once and then alternate it…well…anyways…somehow by removing a scrollview child object it was messing with other objects, specifically navButton 1 & 2, so that its parent object reference became nil (mainGroup?), raising the error…at least that’s how it seems to me…

if scrollView.numChildren > 1 then

   scrollView:remove(1)

end

 

Remember kids, don’t mess with scrollViews :slight_smile:

 

Regards, Emerson

It’s possible line 64 is throwing the error.  Can we see getTranslation code?  Or maybe on line 63 do print(getTranslation(“story”, language, “PAGE” … pageNumber)

Hi, 

Thank you for your reply. 

I double checked getTranslation and it  is returning localized image used as page navigation correctly.

This is the output after include the print before image creation line, as requested:

    images/Page_1_BR.png   

    images/Page_2_BR.png    

First line > first time the module is executed

Second line > after click on second image button

However, I’ve noticed that the error is happening in a different place…The listener code actually finish without an error, but after its execution, the “enterFrame” event is fired as expected, running the following code:

function changeFrameColor( event ) frameButton:setFillColor(green, green, green-99,255) green = green + variation if green \< 100 or green \> 180 then variation = variation \* -1 end end \<\<\< THIS IS WHERE ACTUALLY THE ERROR IS HAPPENING

When the code above finish the error is raised. Oddly enough that code is fine and running correctly after every enter frame event until I click in an image (which triggers the listener “changePage”). The frameButton object is fine, so green and variation variables. The error occurs right after the end of the changeFrameColor function. 

Emerson

Ah…damn scrollview…

here is what happened…

The code below was inserted to prevent a memory leak…memory leak that would not happen if the code was correct in first place…instead to load the image every time the user click in a different page it should (and will) load it once and then alternate it…well…anyways…somehow by removing a scrollview child object it was messing with other objects, specifically navButton 1 & 2, so that its parent object reference became nil (mainGroup?), raising the error…at least that’s how it seems to me…

if scrollView.numChildren > 1 then

   scrollView:remove(1)

end

 

Remember kids, don’t mess with scrollViews :slight_smile:

 

Regards, Emerson

I’m experiencing the same issue. With previous builds adding that code to remove specifically the scrollView worked fine, but not when using the 2013.2100 daily build… Anyone solved this? :confused:

EDIT

Already solved! Just wrote…

display.remove(scrollView)

…instead of…

if scrollView.numChildren \> 1 then scrollView.remove(1) end

Even if the scrollView is inside a group and you remove it, you need to remove explicitly your scrollView

I’m experiencing the same issue. With previous builds adding that code to remove specifically the scrollView worked fine, but not when using the 2013.2100 daily build… Anyone solved this? :confused:

EDIT

Already solved! Just wrote…

display.remove(scrollView)

…instead of…

if scrollView.numChildren \> 1 then scrollView.remove(1) end

Even if the scrollView is inside a group and you remove it, you need to remove explicitly your scrollView