localToContent nil issue

Hello,

I’m quite new in corona sdk. I’m doing some test using parts of code from Tiny Penguin. If you are familiar with this demo, it has a method called createHill(). The first time I executed it works fine, but after it finishes the “lap” I want to execute the next want where I remove all and creates again.

The problem is in “onRectEnterFrame” where raises a nil exception in rect:localToContent. It is quite estrange because after hours of debugging all parameter of rect are fine, but just localToContent is nil.

This is the part of code where I have the issue:

local onRectEnterFrame  
 onRectEnterFrame = function(event)  
  
 local rectContentCoordX, notNeeded = rect:localToContent(rect.xPos,0)  
 if(rectContentCoordX \< 0) then   
  
 Runtime:removeEventListener("enterFrame", onRectEnterFrame)  
  
 for key,body in pairs(objects) do  
 body:removeSelf()  
 end  
  
 createHill()  
 end  
 end  

When I want to go to the next level I just remove all eventListeners and create all again.
If you need more info or code, please let me know. I’m stuck in here.

Thanks in advance! [import]uid: 48295 topic_id: 16099 reply_id: 316099[/import]

I think the problem is that you need to call localToContent through the parent group of rect, not through rect itself.

Try:

local rectContentCoordX, notNeeded = mainGroup:localToContent(rect.xPos,0)  

(I didn’t test it) [import]uid: 33608 topic_id: 16099 reply_id: 59876[/import]

First sorry for the delay,

Thanks amirfl7 for your feedback, but I tested and it’s still showing off the same nil exception in localToContent. I’m running out of ideas and I’m not finding a solution here (really frustrating).

If anyone has any clue or idea, please it would be a big help for me!

Thanks in advance! [import]uid: 48295 topic_id: 16099 reply_id: 62957[/import]

After more tests, I found why is getting me that problem. It has been the declaration type of mainGroup. Initially it was local mainGroup, I just remove local and it works. I’m newbie in LUA so I don’t really understand why.

If someone can help me explaining me which are the reason, I would appreciate a lot.

Thanks. [import]uid: 48295 topic_id: 16099 reply_id: 62984[/import]