[Intended] Using P_RemoveMobj on objects from thinkers.iterate("mobj") stops the loop
What I mean is doing something like this:
(Lua script also available as attachment below)
Normally, you'd expect *all* rings to be removed from the map when "luatest" is used in the console, but as it happens this only removes one ring. Why? The loop is halted once the removed object is fed back into the next iteration of the contents, beause it can't continue!
This *could* explain some of the problems a few may have been having with Lua. But I don't know, I've only seen a handful of the scripts being produced.
One *could* work around this bug by making a blank deathstate or so (lasting at least 1 tic) instead of removing the object immediately - that way the loop isn't interfered with and you still get your object removals (although delayed by 1 tic). That works for now at least.
What I mean is doing something like this:
Code:
local function Test(player)
local numremoved = 0
for mobj in thinkers.iterate("mobj")
if mobj.type == MT_RING
P_RemoveMobj(mobj)
numremoved = $ + 1
end
end
print("removed "+numremoved+" objects")
end
COM_AddCommand("luatest", Test)
(Lua script also available as attachment below)
Normally, you'd expect *all* rings to be removed from the map when "luatest" is used in the console, but as it happens this only removes one ring. Why? The loop is halted once the removed object is fed back into the next iteration of the contents, beause it can't continue!
This *could* explain some of the problems a few may have been having with Lua. But I don't know, I've only seen a handful of the scripts being produced.
One *could* work around this bug by making a blank deathstate or so (lasting at least 1 tic) instead of removing the object immediately - that way the loop isn't interfered with and you still get your object removals (although delayed by 1 tic). That works for now at least.
Attachments
Last edited by a moderator: