RemyR wrote:I guess if someone had a custom door that didn't need a frame, or custom doorframes, this could potentially be a problem. That's a bit troubling now that I think about it. Is there any other reason not to have them that way?
Not that I can think of, of course, those two that you thought of are pretty big issues. There are two solutions, I think.
One idea is to just simply make all the door stuff available in the list of archetypes, and if a designer wants to get fancy, it's all there. It's not the prettiest approach, and old hands at the RTC editor might make more work for themselves than is necessary, but it's simpler than the second option.
The second option, in my opinion more elegant but probably more difficult-- is to make the door "meta-instance" more flexible, and add some stuff to
spawn_door:
Code: Select all
function spawn_door(lev, xc, yc, type, button, frame_type)
if (frame_type == nil) then frame_type = "doorframe" end
if (frame_type ~= false) then
dsb_spawn(frame_type, lev, xc, yc, CENTER)
end
local targ = dsb_spawn(type, lev, xc, yc, CENTER)
if (button) then
if (button == true) then button = "doorbutton" end
local tmp = dsb_spawn(button, lev, xc, yc, CENTER)
exvar[tmp] = { target=targ }
end
return targ
end
Because Lua treats a parameter that isn't given as a
nil, and doesn't type-check parameters that are given, this is actually 100% backward compatible with the simpler version, too.
RemyR wrote:For completeness, I also have another function and a couple of constants in a 'startup.lua' file...
That
spawn_monster function seems useful, but I think that yours will crash DSB if hp is
nil, because it will try to compare a nil with an integer and Lua doesn't like that. So, I've rewritten it (and added it to the base code) as such:
Code: Select all
function spawn_monster(type, lev, xc, yc, pos, hp)
tmp = dsb_spawn(type, lev, xc, yc, pos)
if (hp and hp > 0) then
dsb_set_hp(tmp, hp)
dsb_set_maxhp(tmp, hp)
end
return tmp
end
RemyR wrote:INV_OBJ wasn't really neccesary, but made the containers more consistent.
Oh, this is a good issue. I've probably never actually explained what that -1 is for (it's not just a space-filler), and it might be useful.
If a slot is specified in a spawn, for example:
Code: Select all
dsb_spawn("a_thing", IN_OBJ, container, 5, 0)
it means to put the instance of "a_thing" in slot 5 of the container. If something's already there, it'll shove it out of the way, and everything inside will get jumbled around. It's handy if you really need one specific instance in one specific slot, though. What -1 says to do is to instead put the new instance in the first slot of the container where there's room, and leave everything that's already in there alone.
There's already a constant defined as -1 called VARIABLE, and that's a pretty accurate description, so maybe we should just use that? I've edited the test dungeon accordingly.
As an interesting aside, there's no hard limit on how many instances can be inside a container. The only reason a chest is limited is because the number of objzones created by its subrenderer is limited. Putting an instance directly into slot 10 (or whatever) of a chest will also work, it'll just be invisible.
RemyR wrote:(and by the time I found out C# did it that way, I wasn't about to go back and change all the code).
Search and replace?

Seriously, I'm a little hesitant to add these to the DSB base code just to compensate for something goofy with C# and/or .NET, but on the other hand, to have to have every custom dungeon have a startup.lua just to handle these two constants is kind of ugly, too.
EDIT: Actually, it might be ok to break the rules, here. Normally, it's not a good idea to define constants or add code to dungeon.lua, because none of that is preserved when it gets compiled. However, since these constants will only be used in parsing the file (and get turned right into normal Lua constants), there's no harm done.