Monster Throwing

This forum is for the Lua scriptable clone of DM/CSB called Dungeon Strikes Back by Sophia. Use DSB to build your own highly customised games.

Moderator: Sophia

Forum rules
Please read the Forum rules and policies before posting. You may Image to help finance the hosting costs of this forum.
Post Reply
User avatar
ian_scho
High Lord
Posts: 2807
Joined: Fri Apr 07, 2006 8:30 am
Location: Zaragoza, Spain

Monster Throwing

Post 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!
User avatar
Sophia
Concise and Honest
Posts: 4307
Joined: Thu Sep 12, 2002 9:50 pm
Location: Nowhere in particular
Contact:

Post 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...
User avatar
ian_scho
High Lord
Posts: 2807
Joined: Fri Apr 07, 2006 8:30 am
Location: Zaragoza, Spain

Post 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 :)
User avatar
Sophia
Concise and Honest
Posts: 4307
Joined: Thu Sep 12, 2002 9:50 pm
Location: Nowhere in particular
Contact:

Post by Sophia »

Numbrers are passed by value, and everything else (strings, tables, bitmaps, etc.) are passed by reference.
User avatar
ian_scho
High Lord
Posts: 2807
Joined: Fri Apr 07, 2006 8:30 am
Location: Zaragoza, Spain

Post by ian_scho »

OK, thank you. I destroyed the old and created a new instance as shown in your example, which works now. :lol:
Post Reply