try using
display.remove(myLine)
try using
display.remove(myLine)
It’s displaying the line now, but it’s not removing it.
Also the PlayerChar isn’t firing (moving), it didn’t before, either.
Looking more carefully at your code, you’ve got some issues with creating / removing the variable myLine.
In particular, it appears line 80 always removes myLine from the display whenever the user moves. Perhaps you intended myLine to be removed in the ended phase around line 74? In any case, it’s probably the constant removal at line 80 that is causing the error at line 68 (on the next pass through / move phase).
I would recommend you put in a couple of print statements along the lines of print(" – myLine added") or print(" – myLine removed") at or around line 68, 70 and line 80 (all of them, so you can see what is happening as you begin/move/end the process).
Then press and move, and check the print log – I believe you will see extra removes with the current code.
Ok, using “display.remove(myLine)” in place of “myLine.parent:remove( myLine )” shows extra removes and doesn’t throw up an error. What should I do to fix this?
You need to determine where (when in phases) the extra remove() is happening. Vary the print statement at line 80, so it is different than the print statement at line 68 (so you can tell which remove is getting called too often - likely the one at 80).
Then you need to “make it not do that” (a technical phrase ). Perhaps you intended myLine to be removed in the ended phase around line 74 (instead of at line 80)? If you move that removal and put it inside the ended phase, does that behave as you expected?
If not, you’ll have to determine when (as the phases occur) and where in your code to do the proper creation / removal of your display objects. But suffice it to say, removing it right after you create it (which you say the print statements indicate), is probably not going to get the job done.
great
You can change line 68 to myLine:removeSelf() to eliminate the parent == nil issue.
If myLine was somehow removed from the display hierarchy, you could have problems. You can test for that that with
[lua]
if( myLine.removeSelf ~= nil ) then
myLine:removeSelf()
end
[/lua]
Keep in mind the above has nothing to do with whether parent should be part of the object, or if the programming logic is correct in general… It’s just a couple little tactics to do things / test things differently that might help out.
I changed line 68 to myLine:removeSelf(), but now it’s saying “attempt to call method ‘removeSelf’ (a nil value)”
try using
display.remove(myLine)
It’s displaying the line now, but it’s not removing it.
Also the PlayerChar isn’t firing (moving), it didn’t before, either.
Looking more carefully at your code, you’ve got some issues with creating / removing the variable myLine.
In particular, it appears line 80 always removes myLine from the display whenever the user moves. Perhaps you intended myLine to be removed in the ended phase around line 74? In any case, it’s probably the constant removal at line 80 that is causing the error at line 68 (on the next pass through / move phase).
I would recommend you put in a couple of print statements along the lines of print(" – myLine added") or print(" – myLine removed") at or around line 68, 70 and line 80 (all of them, so you can see what is happening as you begin/move/end the process).
Then press and move, and check the print log – I believe you will see extra removes with the current code.
Ok, using “display.remove(myLine)” in place of “myLine.parent:remove( myLine )” shows extra removes and doesn’t throw up an error. What should I do to fix this?
You need to determine where (when in phases) the extra remove() is happening. Vary the print statement at line 80, so it is different than the print statement at line 68 (so you can tell which remove is getting called too often - likely the one at 80).
Then you need to “make it not do that” (a technical phrase ). Perhaps you intended myLine to be removed in the ended phase around line 74 (instead of at line 80)? If you move that removal and put it inside the ended phase, does that behave as you expected?
If not, you’ll have to determine when (as the phases occur) and where in your code to do the proper creation / removal of your display objects. But suffice it to say, removing it right after you create it (which you say the print statements indicate), is probably not going to get the job done.
great