if e.sType == 8 then
playSFX("gertrudeattackSound")
if e ~= nil and e.rotation ~= nil and e.x ~= nil and e.y ~= nil then
e:applyLinearImpulse(Sin((360 - e.rotation)*RadtoDeg) * 3750, Cos((360 - e.rotation)*RadtoDeg)* 3750, e.x, e.y)
end
else
Why do you have so many checks in this if statement?
If all those are really necessary maybe you are not removing your objects correctly, that could explain the wrong call to applyLinearImpulse, I’m just not sure about the castTime.
I’ve added the extra checks to trap this error above - obviously to no avail - and left them in for the screenshot / snippet so you could see nothing in the applyLinearImpulse statement could be nil.
Ordinarily I’d just have the If object ~= nil - in this case the object is e. I use e as a shortening for enemy as it’s typed so often in my game - but yes agree @roaminggamer it’s a poor variable name!! I’m not so bad elsewhere in code - promise!!
Just FYI this object is the players familiar - Gertrude - she’s created at game load and not destroyed at any point. Does this help?
Thanks again for all the feedback and sorry for any confusion,
Nick
PS I’m starting to see init.lua referenced more and more suddenly - in this because the information included in error messages has been increased? I’ve just recently upgraded to version 2020.3609.
Awesome advice - thank you.
I cancel timers on destroyed enemies but now you mention it I think there will be some listeners hanging around!
Might not have time today but I will do as you suggest and let you know how I get on.
With help from you gurus I’m getting there!
Thanks again
PS 4557 is the line in question - the others are lines in AI functions which call the other AI functions.
Only problem here is as mentioned above the object in question is never destroyed…!
I’ve been working on this today.
Still no further forward. I’ve removed listeners from other objects that needed it after your advice above - although I thought I had read somewhere, many moons ago, that sprite listeners were removed with sprites. Still better to be safe than sorry.
This object referenced above however is not removed at any point, and the code is not run through a timer, so I’ve no idea.
The only thing I can think of now is that this error has only started appearing after upgrade to the latest version of Solar 2D…
I’ve sussed it.
I’m now removing the physics body with a timer set to 50ms to stop the “can’t change physics bodies whilst number crunching error”.
Thus when summoning the entity whilst it still exists I’m actually now removing the physics body 50ms after creating it!
Can now resolve no problem.
Thanks so much for the assistance!!!