Page 1 of 1

Monster Throwing

Posted: Mon Apr 14, 2008 7:42 pm
by ian_scho
Hi again,

I have an event that a monster will throw a dagger, for example.

Here is a snipped of my dummy code, the bit that isn't working. As you can see I have hard coded the direction and tile position for test purposes.

Code: Select all

		local throw_power = 38
		local damage = 30
		local delta = 8           
		dsb_shoot(id, level, x, y, NORTH, NORTHEAST, throw_power, damage, delta)
		dsb_set_openshot(id)
		local_sound(mon_id, snd.swish)
Thanks!

Posted: Mon Apr 14, 2008 8:12 pm
by Sophia
What doesn't work?

From looking at that code the main problem I see is that you're not defining the variable id anywhere. For dsb_shoot to work properly you need to have something to shoot. So, if you haven't created the dagger, you'd have to do so beforehand.

Code: Select all

local id = dsb_spawn("dagger", LIMBO, 0, 0, 0)
Otherwise, I'd need more information to get to the cause of the error, because that code looks fine...

Posted: Mon Apr 14, 2008 10:59 pm
by ian_scho
Ohhh thanks for that. I think you pointed me in the right direction there.

It was probably to do with id's where I passed an instance to a function, which called dsb_swap(what, "flask"), but I suspect I still had an 'old' reference in the parent function... My ignorance of LUA? Passing parameters by reference, value or by memory reference!

Will play some more :)

Posted: Mon Apr 14, 2008 11:17 pm
by Sophia
Numbrers are passed by value, and everything else (strings, tables, bitmaps, etc.) are passed by reference.

Posted: Tue Apr 15, 2008 9:26 am
by ian_scho
OK, thank you. I destroyed the old and created a new instance as shown in your example, which works now. :lol: