Page 1 of 1

inventory events

Posted: Fri Feb 07, 2014 12:24 pm
by kaypy
Hi

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 }
	}
})
The results are:
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.

Re: inventory events

Posted: Sat Feb 08, 2014 10:10 pm
by Sophia
The time 0 message firing immediately is just how messages with 0 delay work, so that's fine.

However, you're right, after_from's behavior is not particularly useful in this case, considering the whole point of its existence is to be processed after the object is already in its proper location. I've made it act more reasonably. The unavoidable side effect is that now after_from is actually processed after to, but I don't think anything depended on things working the other way.

Using your test code, I now get the following results:
(put away)
Lua: ON : -3 1 0 0
Lua: TICK 0 : -3 1 0 0
Lua: ONNED
Lua: AFTER : -3 1 10 0
Lua: TICK 1 : -3 1 10 0

(throw)
Lua: ON : -3 1 0 0
Lua: TICK 0 : -3 1 0 0
Lua: ONNED
Lua: AFTER : 0 5 3 3
Lua: TICK 1 : 0 5 3 3

Re: inventory events

Posted: Mon Feb 10, 2014 11:04 am
by kaypy
Thanks.

Hmm. It didn't quite help as much as I thought, though. I'll have to think about this some more...