I don’t understand… What’s wrong?
Corona version: 2018.3326
I don’t understand… What’s wrong?
Corona version: 2018.3326
You are trying to remove a display object that doesn’t exist.
If you just share the error message, then that’s really all the help you can get.
But local variable “hero” exists…
Probably a scoping issue. As XeduR states, you need to post relevant code.
If you were to give your hero object a string parameter name
eg
hero.myName = “Superman”
You could then test if your hero object really does exist easily, directly before removing it.
EG
print("hero name: " … hero.myName )
if the console reports a nil value and an error, then you will prove to yourself that the hero object doesn’t exist which means you need to walk through your code to see where it becomes initiated… chances are it’s not being created when you think it is.
But console reports hero name what I typed in…
It’s probably not enough code to give a definitive answer, but you are declaring “local hero” too many times. Depending on where/when this is executed, you can be referencing a nil object, or a locally declared object.
Declare it 1 time and reuse. If you need it in multiple functions, declare it outside of a function.
local hero = nil local function Attack(event) hero = display.newSprite(AttackAnimationSheet, sequenceData) -- etc, etc end
Taking pictures of your code is a lot of work. Just use code inject tool