Black Screen with only Character?

Help! I am having a error that says"… has more than 60 up values".What does that error means? I place the code in my update function.
And am I going in the right way with this code?:

if isNarrowView == true then local RectTable = {} local BlackRect for i=1, BlackRect do RectTable[i] = display.newRect( 0, 0, screenWidth, screenHeight) RectTable[i]:setFillColor( 0 ) RectTable[i]:setStrokeColor(black) for i =1, BlackRect do effect\_Timer = effect\_Timer + 1 if effect\_Timer \> 100 then effect\_Timer = 0 isNarrowView = false table.remove(RectTable) print("Rect Removed") end end 

It is the for loop that is giving me the error?

I suggest you look deeper into learning the Lua language. You can find more info here: http://www.lua.org/manual/5.1/

You will also find our what upvalues are there.
Your code is only removing the entries from the table, which is fine… But you should be removing them from the screen before doing that.

I am purposely not handing out the code so you learn yourself :wink:

Ya. I appreciate your help.

So the way I wrote my code is correct? but what do you mean by removing them from the screen before doing that?

Removing entries and removing from screen is different? 

It’s different yes. I’m going to point out some of the errors, with solutions. Your logic still looks flawed regardless of my below help. You must ensure that you add the images to the table when needed and remove them all at the end.

There is no need in your case (if i understand it correctly, to loop through a table initially to create them)

First problem:

local RectTable = {}

This should be moved outside of the function, probably. If your calling this function on a timer then move it outside of the function.

Second problem:

Your for loop does nothing. The second argument to the for iterator must be a number. At the time of creating the for loop, “BlackRect” is nil. Currently your for loop evaluates to:

for i = 1, nil do

Which will cause an error.

Third problem, not removing the image.

table.remove( RectTable )

Removes the last element from the rect table. It has nothing to do with the screen.

You could also do the table remove statement like this:

table.remove( RectTable, i ) -- or RectTable[i] = nil

Now… To remove the images from the screen (as you already knew how to so previously) goes like this (in your case, once the logic and other problems are sorted)

display.remove( RectTable[i] ) -- or RectTable[i]:removeSelf()

The difference between both ways is listed on their respective documentation pages.

I would strongly suggest that you take a step back for a bit. Go to the corona university guides (listed on the resources page) and run through them, to get a better grasp of the basics.

Also J.A Whye’s (hope i spelt his second name correctly) video and written tutorials are fantastic for people new to corona and would help you a lot.

Also the previous link i posted is an invaluable resource for explaining the Lua language itself. I cannot stress enough how important it is to have a firm grasp of Lua before getting too far into the deep end.

You will be using tables a lot in Lua, so now is the time to learn them :wink:

Hope this helps.

Thanks for the help!

So… Now I managed to solved the “more than 60 upvalues”(I was missing an “end” at the for loop)

But now I am having trouble with the for loop, I rewrote the code:

local RectTable = {} function Update (event) ... ... ... --Effect function if isNarrowView == true then local BlackRect = display.newRect( 0, 0, screenWidth, screenHeight) BlackRect:setFillColor( 0 ) BlackRect:setStrokeColor( black ) groupcs:insert(BlackRect) table.insert(RectTable,BlackRect) effect\_Timer = effect\_Timer + 1 if effect\_Timer \> 100 then effect\_Timer = 0 for i = 1, #RectTable do isNarrowView = false table.remove( RectTable, i) display.remove( RectTable[i] ) print( "Rect Removed" ) end end end  

Now when the effect timer is up, the black rectangle still does not goes off. Anyone? or anything is wrong the code?

*groupcs is a display group that holds the levels objects etc… I needed it so that when my level is cleard the black rect will be gone. 

We appear to be getting somewhere now. You missed what i said above though, in my previous post. I suggest you look again.

You remove the rect from display then from the table. You have it the wrong way around.

If it doesn’t work after doing that, then i want to know if the effect time ever gets passed 100 and want to know how you are calling that update function.

Hope this helps.

It does not work. Black rectangle still there.

Yes. I am able to print out “Rect Removed”, and It is printing out a lot of times.

Well you are going to have to show us the whole file then. We can’t see the rest of your code to see how it all fits together, so it’s been a guessing game so far

Ohh… Ok

So the code is correct and it should be able to remove the black rect? Am I right?

I’m not saying that. As there are variables there and other things which we would need to see how they are set up, scoped and how these functions get executed and when.

In fact, the advice i have offered so far may even be over the top. As i have given you my advice based on my assumption of guessing (for the most part) what you are doing. But the basic idea of my logic is what you want to take away from this.

Creating an object when something collides and then removing it later is not a hard nor complicated thing to do, so i believe i have helped you as much as i should/need to.

You have more than enough information in this thread to work with, to be able to fix it yourself, seriously you do. I don’t want to keep going back and forth with you for another x amount of days just to hand you out the code. That won’t do you any favours at all. I am also a busy man and have projects of my own to be working on, don’t forget! :slight_smile:

Make a small test example project using shapes that has the only functionality of colliding, creating that black rect, then removing them at the end. Make it is small and simple as possible.

You could even use one of coronas physics samples that comes with the SDK to get you 3/4 of the way there. If you modify one of the corona samples to do this and can’t get it working, post up the modified corona sample code and it will be easier to give you new pointers. All of the code though, not just bits. I don’t mind giving you some more help, provided i see the effort returned on your side to give it a real go yourself :wink:

If you do that I am sure you will find where you are going wrong.

In any case, best of luck!

Hmm…I am interested in how to mask the moving sprite.Any Ideas?

Maybe I can help you with the removal of black screen.

Try something like this:

local function RemoveScreen( obj) display.remove( obj) -- Removes the Rect obj = nil end --Then your isNarrowView function if isNarrowView == true then local ScreenRect = display.newRect(...) .... .... --Timer .... .... --Put this before closing transition.to( ScreenRect, { time = 200, onComplete = RemoveScreen} ) end

So… any idea on masking the character(a sprite) after having the black screen on?