I'm getting some odd results while fiddling with inventory events and messages.
A simplified test case- on unequipping the item, you get a debug message from from_ and after_from_ as well as two different tick events.
The item has two actions that will move it in addition to directly unequipping it.
Code: Select all
function dlog(text)
__log(text)
dsb_write(debug_color, text )
end
function test_on_remove(self,id,who)
z,x,y,p = dsb_get_coords(id)
dlog("ON : " .. z .. " " .. x .. " " ..y .. " " ..p)
dsb_msg(0, id, M_NEXTTICK, 0)
dsb_msg(1, id, M_NEXTTICK, 1)
dlog("ONNED")
end
function test_after_remove(self,id,who)
z,x,y,p = dsb_get_coords(id)
dlog("AFTER : " .. z .. " " .. x .. " " ..y .. " " ..p)
end
function test_on_tick(id, data)
z,x,y,p = dsb_get_coords(id)
dlog("TICK " .. data .. " : " .. z .. " " .. x .. " " ..y .. " " ..p)
end
function method_putaway(name, ppos, who, what)
put_object_away(who, what,{},false)
end
obj.testcase=clone_arch(obj.dagger, {
from_r_hand=test_on_remove,
after_from_r_hand=test_after_remove,
msg_handler={[M_NEXTTICK]=test_on_tick},
methods = {
{ "THROW", 0, CLASS_NINJA, method_throw_obj },
{ "PUT AWAY", 0, CLASS_NINJA, method_putaway }
}
})
unequip
Lua: ON : -3 1 0 0
Lua: TICK 0 : -3 1 0 0
Lua: ONNED
Lua: AFTER : -4 0 0 0
Lua: TICK 1 : -4 0 0 0
First thing to note here is that the 0 time message fires immediately, without even finishing the from_ method first.
throwing the item
Lua: ON : -3 1 0 0
Lua: TICK 0 : -3 1 0 0
Lua: ONNED
Lua: AFTER : -3 1 0 0
Lua: TICK 1 : 0 1 4 1
put away method
Lua: ON : -3 1 0 0
Lua: TICK 0 : -3 1 0 0
Lua: ONNED
Lua: AFTER : -3 1 0 0
Lua: TICK 1 : -3 1 10 0
Note that with either of these, the after_from_ method is firing before the item has moved to the new location.
What I am after is some way to react to moving the item. after_from_ is firing too early, a no-delay message is even earlier. A delayed message gets me the right effect, but I want to fire immediately after the current processing is done, not some way down the track.