I have some code that spawns knife bullets that stick to the enemy until their health runs out, then they vanish. Since they behave differently than normal bullets (i.e. they don’t disappear on impact) I had to write some logic that, upon an enemy’s death, polls the last 500 bullets fired to see if they’re attached to the enemy who just died.
Problem: sometimes the knife removal code, for whatever reason, grabs an already removed knife and tries to remove it again, causing an error and making the world nice and weird.
Here’s the code:
[blockcode]if self ~= nil and self.spec == “knife” and self.stuckIn == event.other then
if #bullets > 500 then
endNum = #bullets - 500
else
endNum = 1
end
for i = endNum, #bullets do
if bullets[i] ~= nil then
if bullets[i].stuckIn == event.other then
–bullet remove self
end
end
end[/blockcode]
When the remove code is called, whether it’s a child.parent removal or a removeself() call, an error is generated the says parent is a nil value or removeself is a nil value. What’s the problem? [import]uid: 89724 topic_id: 17039 reply_id: 317039[/import]
[import]uid: 3826 topic_id: 17039 reply_id: 63966[/import]
Hahahaha…