Display objects can take an optional “group” as the first parameter. Our test for the first parameter apparently calls that display group a proxy instead of a table. “Proxy” is coming from our error message.
Rob
Display objects can take an optional “group” as the first parameter. Our test for the first parameter apparently calls that display group a proxy instead of a table. “Proxy” is coming from our error message.
Rob
You entirely missed my point. The project you uploaded does not run.
I won’t help if I can’t run the project. I want to see the problems in context.
So, try again.
Just zip up the project as it is. Don’t re-arrange it, just zip it up and post the zip.
-Thanks
To everyone reading this and thinking, “Ed aren’t you being kinda harsh or difficult?”
Remember, folks. When you ask for help, you are asking other people to spend their time (equals money for many of us). So, don’t waste that time.
You should spend MORE time writing and preparing the question than it takes for the person helping you to respond.
This means,
I wrote about all this before here: https://forums.coronalabs.com/topic/55780-ask-a-better-question-get-a-better-answer/
I actually do think Ed is a bit harsh, but he has a point.
After looking at your code it looks like it is a scope issue of the sceneGroup. When you use local keyword when creating a variable, it is only available in that scope. Example, look at scene:create, where the sceneGroup is only valid in that particular function.
function scene:create( event ) local sceneGroup = self.view
There are a few places where you need to make sure you have the sceneGroup. For example, in
function fireBullet(source, angle)
you try to use it, but it is not declared.
I downloaded the latest zip file and it does not match your original post.
At least one of the issues you’ve got in your original code is with the composer usage and setup.
I asked you to supply your original code unmodified, and you didn’t. So, I can’t help.
To be absolutely clear. My plan was to:
However, I have burned all the time I can afford following up on this, so I’ll have to let someone else help.
@Yoger Games - is right about your use of sceneGroup out of scope. Also, you’ve got some issues with code formatting that are probably making this hard to debug. You may want to go back and clean up the code a bit then re-review it. Lastly, I think you’ve got a few global functions that don’t need to be global You can solve this through forward declaration.
Sach,
I wil try to help if I can.
First, I think it is better if you do not have so much code within the scene:show function. And I think that is likely where your problem begins.
Second, I think there is maybe 3 or 4 nested functions (the best I can tell, is alot(maybe not all) of the blocks of code in the scene:show are not indented. This makes it really hard for anyone trying to help.
Third, gameLoop particularly, it is such a critical function in most games, it really needs to be outside of the scene:show.
I usually create a section of code above the scene:create function where I place as many functions as I can, rather then embedding them (or nesting them) inside either the scene:create or scene:show.
So, try and break up that scene:show by moving all those functions, and move them above the scene:create. Also, try to indent all of the blocks within any function and also with in every if-else or if-elseif block.
Moving those function outside of the scene:show may create more errors… depending on what you have as local variables etc… but it is best, I believe. so if other errors pop-up once you move those functions, track them down and most you will likely be able to figure out and fix, but it may take some time. That is the life of coding.
As more bugs develop (and they will) this will make it easier to debug the other issues.
Also, I think a common thing to do, is in scene:show do most(if not all) of your ‘addEventListeners’ in scene:show and then remove those listeners in scene:hide. I see where you added several event listeners, but I do not see any removed in scene:hide
Here is 2 lines of your code I noticed you use for your gameLoop:
gameLoopTimer = timer.performWithDelay(500, gameLoop,0)
gameLoop()
Instead of those lines of code, why not use ‘enterFrame’ event for your game loop.
Runtime:addEventListener(“enterFrame”, gameLoop) … put his line in scene:show and then as soon as the scene:shows the gameLoop will run. But, be sure to put your gameLoop code outside of the scene:show … as well as nearly all the other ones you have in scene:show… it is not mandatory to do that, I think (IMHO) better coding practice and in the long run will make code easier to read and debug.
Also, in your original post you note 'line 391; as the error. it is good to also show the actual line of code, in case the line numbers are not shown in the sample code.
Question: is there an extra ‘end’ statement in this block? it seems to me there is , but I can guess it does not flag an error because you have another if-elseif-type block that is not properly matched up. A common problem with lots of nesting and embedded functions. I know because I have made all done this a few times myself. Also, I think (again i have not read all the code) that this function ‘touch’ should be ‘local’
function touch( e ) local angle = angleBetweenPoints( ship, e ) ship.rotation = angle-0 if (e.phase == "began") then elseif (e.phase == "moved") then elseif (e.phase == "ended") then fireBullet(ship, angle) score = score - 1 scoreText.text = "ballsleft: " .. score if score == 0 then print("zero") end end return true end
I know this doesn’t solve you initial question as to the cause and fix for the error you mentioned. But, I can’t figure it out as the code is presently.
I apologize if I miss-read any of the code and jumped to any wrong conclusions, since I only read little parts of it, but I hope there is some bit of help in what I am trying to say.
Coding takes alot of time and involves alot-alot-alot of re-typing and re-doing of the code, until you gain more and more experience.
Keep at it, and best of luck.
Bob
Sach,
Correction on one thing. The comment I made about the extra ‘end’ statement in one block of your code. It was late after a long day when I read that, and did not notice the :
if score == 0 then
so there is ‘not’ an extra end in that block. The way it was formatted, and because I read thru it quickly, I missed that.
I think it’s important to interject a couple of tutorials here.
1. https://coronalabs.com/blog/2015/06/09/tutorial-the-value-of-well-formatted-code/
Formatting code is critical when you want to get help, but its even more critical for your own sanity. Please take the time to read this tutorial and understand the importance of indenting your code properly. It also discusses nesting functions inside of functions which can serve a purpose once you understand “scope” better, but for now it’s best to try and avoid nesting (a function inside a function) because its a way to avoid dealing with scope (what variables/objects/functions can see each other).
2. https://coronalabs.com/blog/2015/06/16/tutorial-scope-for-beginners/
Posts above talk about not doing everything inside of the scene:show() function. The general reason you would put as much as you did inside of scene:show() is to avoid dealing with scope. When you indent your code properly you can visually see how your code creates “blocks”:
local a = 10 local b = 20 if something then -- this is a block local a = 20 local b = b + 100 local c = 200 print( a, b, c ) -- print's 20, 120, 200 end print( a, b, nil ) -- prints 10, 20, nil
Variable ‘a’ inside the “if” statement is a different variable than the ‘a’ above the if statement. And if you consider the “c” variable, it only exists inside the “if” function. Now for “b” it was only declared “local” above the “if” statement, but it’s accessible inside inside the “if” without declaring it local.
For Composer scene, since the scene event functions are event triggered from other actions (composer.gotoScene()) you may want to have access to objects and functions in both scene:create() and scene:show() (as well as scene:hide(), etc.). If you only put the object in scene:create() then you can’t access it in scene:show(). But if you want Composer to actually work for you, you have to create things in scene:create() and start things in scene:show(). The solution: learn scope.
Define the object at the top:
local ball
inside scene:create()
function scene:create( event ) local sceneGroup = self.view ball = display.newCircle( sceneGroup, 100, 100, 20 ) end function scene:show( event ) ball.x = 200 ball.y = 200 end
So you declare the object/function that you need scene wide.
You do the work to create the object in scene:create()
Then manipulate the object in scene:show().
Once the scene starts and is running on the screen (spawning new balls) then that can happen outside of either scene event function, so it might make sense to put the ball spawning code in function outside of the event an then call the function inside scene:create to create the first one. Anyway, spend some effort reading the scope tutorial and trying to grasp the concept.
Between the two, it will go along way to helping you write more manageable code.
Rob