DM2 style sconces

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.
Post Reply
kaypy
Artisan
Posts: 171
Joined: Sun Jan 19, 2014 7:11 am

DM2 style sconces

Post by kaypy »

Hi

Here is a rather hacky prototype for DM2 style lit sconces.

http://en.file-upload.net/download-8626 ... t.zip.html

Is there any way I could hook into party movement somehow rather than polling like crazy?

Of course, I don't really want to make system level changes in an importable arch, either...

edit: now with better message handling and more dramatic examples
Friends don't let friends eat worm round
lenochware
Novice
Posts: 23
Joined: Tue Dec 10, 2013 1:51 pm

Re: DM2 style sconces

Post by lenochware »

Nice. Personally I like torches on the walls. If party is making light by spells and torches, it ends with maximum light everytime and everywhere. If only some places are lit, it is more atmospheric, in my opinion...
Is there any way I could hook into party movement somehow rather than polling like crazy?
I am not sure what are you asking, but there is h_party_move hook, which is called everytime when party moves (as far as I know)
kaypy
Artisan
Posts: 171
Joined: Sun Jan 19, 2014 7:11 am

Re: DM2 style sconces

Post by kaypy »

Thanks, that was exactly what I was asking 8-)

I suppose I should actually read through the base/ files instead of just grepping for a few likely strings...

http://en.file-upload.net/download-8634 ... t.zip.html

OK, this version responds to party movement instead of polling, and gives me a vaguely reasonable excuse to use that terrible, terrible singleton code 8-)
Friends don't let friends eat worm round
User avatar
Gambit37
Should eat more pies
Posts: 13714
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Re: DM2 style sconces

Post by Gambit37 »

I've been looking at this code and I can't get it to work in DSB 0.69.

There are two errors. The first is with the definition of the archetype "sconce_light_manager". DSB complains that the arch is not a string, and it's because of the embedded function assigned to the "get_instance" method. I can fix that by simplifying the archetype definition and adding the function separately:

Code: Select all

obj.sconce_light_manager = {
	type="FLOORFLAT",
	class="MECHANISM",
	init_manager=light_manager_init,
	do_update=light_manager_update,
	add_flame=light_manager_add_flame,
	remove_flame=light_manager_remove_flame
}

function obj.sconce_light_manager:get_instance(self)
	-- check existing instance is real
	if (self.instance ~= nil
		and dsb_valid_inst(self.instance)
		and dsb_find_arch(self.instance) == self) then
		return self.instance
	end
	-- else try to find one
	for id in dsb_insts() do
		local arch = dsb_find_arch(id)
		if (arch == self) then
			self.instance = id
			return id
		end
	end
	-- else create one
	self.instance = dsb_spawn(self,LIMBO,0,0,0)
	self:init_manager(self.instance)
	return self.instance
end
However, with that change I now get a second error with the rest of the code, because I think self is no longer referencing anything (I think)? DSB complains with:

Code: Select all

FATAL LUA ERROR: Lua Function sys_party_move: dsb69\kaypy\sconcelight/sconce_flame.lua:187: attempt to index local 'self' (a nil value)
I don't understand the self thing enough to know how to fix this. Any ideas?
User avatar
Sophia
Concise and Honest
Posts: 4239
Joined: Thu Sep 12, 2002 9:50 pm
Location: Nowhere in particular
Contact:

Re: DM2 style sconces

Post by Sophia »

There are actually two issues here. The first one is that if you're specifying a function definition with a colon instead of a dot, you don't need to actually have a self parameter, because Lua will automatically do so. So you can write

Code: Select all

function obj.sconce_light_manager:get_instance()
Actually you could also do

Code: Select all

function obj.sconce_light_manager.get_instance(self)
Anyway, the second problem is a change sometime in the last 4+ years. When kaypy's code was originally written, dsb_spawn accepted an archetype table entry as a parameter, but it currently does not, because I found out that led to some pretty obscure bugs if you messed this up. This is what DSB was originally complaining about. You can fix that by changing the "else create one" line to the following:

Code: Select all

self.instance = dsb_spawn(self.ARCH_NAME, LIMBO, 0, 0, 0)
This will grab the arch's name as a string and will work properly.

Or at least crash with a clear error message. :mrgreen:
User avatar
Gambit37
Should eat more pies
Posts: 13714
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Re: DM2 style sconces

Post by Gambit37 »

Thanks for this code. I can now play this test dungeon, but when I press the green button on level 2 which is set to activate the torches, DSB crashes again:

Code: Select all

LUA ERROR: dsb69\kaypy\sconcelight/sconce_flame.lua:104: Archetypes must be specified as strings
FATAL LUA ERROR: Lua Function sconce_full.msg_handler[100002]: base/util.lua:188: table index is nil
Since I'm not entirely sure what's going on here and I don't expect you to fix all this Sophia, I'll wait for Kaypy to update it :D
kaypy
Artisan
Posts: 171
Joined: Sun Jan 19, 2014 7:11 am

Re: DM2 style sconces

Post by kaypy »

If it hasn't fallen off the internet again, there should be an up-to-date version in with the probably solvable libraries
Friends don't let friends eat worm round
kaypy
Artisan
Posts: 171
Joined: Sun Jan 19, 2014 7:11 am

Re: DM2 style sconces

Post by kaypy »

Lets see if this lasts a bit longer:
https://www.megaupload.us/4m4/sconcelight.zip
Friends don't let friends eat worm round
User avatar
Gambit37
Should eat more pies
Posts: 13714
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Re: DM2 style sconces

Post by Gambit37 »

Wow, awesome, thank you. Yep, that version works fine (although I had to remove the relative path and put it all in the same folder as that didn't work for me).

I really like this lighting effect. Would it be OK to use it in one of my projects?

Oh, by the way, the Probably Solvable links are all dead too... :?

EDIT: I grabbed the scone file from your first link. You've since moved it to MegaUpload but that link doesn't work either.
Post Reply