Delete text between Sotryboard.

Hey,

In my game I have a text that show a timer that I create with a function. I would like to delete the text when I pass the final level of my game, and when I play it again, show me the text with timer in 0.

I tried using:

function_timer:removeSlef()

function_timer = nil

text:removeSelf()

text = nil

But I have an error that say that text has a nil value.

What Can I do?

PD: I am using Persistent Varibales from this: http://www.coronalabs.com/blog/2012/08/07/managing-state-between-scenes/

Sorry With my Bad English :S

We’ll need to see more of your code to help you.  Show how you are creating the text and where you are trying to remove it.

I am creating the text in the first level, and in 12 level, I would like to delete it. 

The timer is this: http://forums.coronalabs.com/topic/38408-how-can-i-do-a-timer/#entry200081 but that increases.

This function and variables are in the first level. When you pass the last level ( the 12 in my case), I would like to delete the text and stop the function, because I would like to save the time.

How Can I do this?

Anyone knows how to solve my problem?

Anyone knows how to solve my problem?

Anyone knows how to solve my problem?

I think the problem is that you are creating the text locally in one scene, you are not adding it to the scene’s ‘group’, and then you are changing scene.  Is this correct?  Again like I said before we need to see your code.

http://pastebin.com/pKB57qix

I would like to delete the text in the next level, and if I play the first level again, then see the text with the timer.

Thanks for answering :slight_smile:

Someone knows?

I think JonPM is right … line 30 of your code (on pastebin):

 storyboard.state.text = display.newText( textHolder, 100, 100, native.systemFontBold, 32)

You’ve saved a reference to a global object (the output of display.newText) into the storyboard object (not sure that is a good idea to do either, the usual approach seems to be to add it to the storyboard-vew object, sceneGroup in your code).

local screenGroup = self.view textHolder = "Denbora: "..storyboard.state.minuteHandler..":"..storyboard.state.secondHandler..storyboard.state.milliHandler; local textObj = display.newText( textHolder, 100, 100, native.systemFontBold, 32) screenGroup:insert( textObj) -- again, not sure this is a good idea: --storyboard.state.text = textObj -- but try this: screenGroup.textObj = textObj

I delete the text using the screenGroup, but I need to delete my function too. How Can I delete a function from the next level?

Hmm, maybe at line 25, insert something like this:

storyboard.state.func = updateClock timer.performWithDelay(1000, updateClock, -1)

Then you’d have a reference to the function whenever you need to delete it (I assume that’s the function you meant?).  E.g. in exitScene or destroyScene, you could set storyboard.state.func=nil

I’m a newbie when it comes to Lua and especially how Corona builds to the device, but I’m not sure that it will matter if you delete the function.  Since Corona doesn’t allow on-the-fly compilation, I assume even function-objects like yours are pre-compiled pieces of code that will persist even if you delete references to them.

It works, but if I play the level again, the function doen´t work.

I put storyboard.state.func=nil

What Can I do?

Looking at your code a bit more … I’m guessing that you’re using timer.performWithDelay to set up an infinite loop (though I thought the iteration argument should be 0 not -1).  You want that infinite loop to stop when the storyboard scene stops, right?

-- may not really be needed ... could just do this inside enterScene storyboard.state.timerObj = timer.performWithDelay(1000, updateClock, -1) -- then, in enter/exitScene function scene:enterScene( event ) -- same stuff as before if( storyboard.state.timerObj == nil ) then storyboard.state.timerObj = timer.performWithDelay(1000, updateClock, -1) end end function scene:exitScene( event ) local screenGroup = self.view physics.stop() if( storyboard.state.timerObj ~= nil ) then timer.cancel( storyboard.state.timerObj ) storyboard.state.timerObj = nil end end

This way, the timer is created/re-created every time you enterScene; it is removed every time you exitScene.  The updateClock function is available all the time, but it is only in use when you need it – you’re not deleting the function-object, just the timer-object that references that function-object.

Thanks jbp1

You are the best!!!

We’ll need to see more of your code to help you.  Show how you are creating the text and where you are trying to remove it.

I am creating the text in the first level, and in 12 level, I would like to delete it. 

The timer is this: http://forums.coronalabs.com/topic/38408-how-can-i-do-a-timer/#entry200081 but that increases.

This function and variables are in the first level. When you pass the last level ( the 12 in my case), I would like to delete the text and stop the function, because I would like to save the time.

How Can I do this?

Anyone knows how to solve my problem?

Anyone knows how to solve my problem?

Anyone knows how to solve my problem?