(done) Accessing level information

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
User avatar
Parallax
DMwiki contributor
Posts: 424
Joined: Mon Aug 28, 2006 7:56 pm
Location: Back in New Jersey

(done) Accessing level information

Post by Parallax »

How would I query DSB for the dimensions of a given level? I cannot seem to find the appropriate dsb_ function in the list. If it doesn't exist, I humbly request the creation of dsb_get_levelsize(level) = xsize, ysize.

On the same general topic, what happens if I query a dungeon location that doesn't exist, like negative (or zero?) coordinates on a given level, for instance, or coordinates that are beyond the level size?
User avatar
Joramun
Mon Master
Posts: 925
Joined: Thu May 25, 2006 7:05 pm
Location: The Universe

Post by Joramun »

It crashes... I'm trying to make a magic map, and I have this particular problem :D
What Is Your Quest ?
User avatar
Sophia
Concise and Honest
Posts: 4240
Joined: Thu Sep 12, 2002 9:50 pm
Location: Nowhere in particular
Contact:

Post by Sophia »

It's not a crash as such, but it's a fatal Lua error... I could make it fail silently, but that introduces its own problems.

A function like that is a pretty good idea, though. I added a bit more info to it while I was at it. DSB 0.21 will have:
dsb_level_getinfo(level) = x_size, y_size, lightlevel, xp_multiplier
User avatar
Parallax
DMwiki contributor
Posts: 424
Joined: Mon Aug 28, 2006 7:56 pm
Location: Back in New Jersey

Post by Parallax »

does that mean that the dsb functions for getting the light level and the xp multiplier, respectively, will be retired or are they still OK to use in custom dungeons?
User avatar
Sophia
Concise and Honest
Posts: 4240
Joined: Thu Sep 12, 2002 9:50 pm
Location: Nowhere in particular
Contact:

Post by Sophia »

No, they're still ok. :)
User avatar
Parallax
DMwiki contributor
Posts: 424
Joined: Mon Aug 28, 2006 7:56 pm
Location: Back in New Jersey

Post by Parallax »

Sophia wrote:It's not a crash as such, but it's a fatal Lua error... I could make it fail silently, but that introduces its own problems.
What about failing with an error message? I noticed DSB has a strong tendency to crash when it encounters lua code it does not like (which, with me, is quite often :P ). Besides, I know I am more inclined to fix problems in my dungeon and try to conform to good programming practices if not doing so means having my dungeon 'polluted' by system errors and the immersion ruined. If actions just fail silently when I'm abusing the system I'm a lot more inclined to just sweep things under the rugs, cut corners and hope for the best. This tends to not end well.

The following functions use dungeon position as input:
# dsb_3dsound
# dsb_level_wallset *
# dsb_alt_wallset
# dsb_level_tint *
# dsb_text2map *^
# dsb_image2map *^
# dsb_party_place
# dsb_spawn
# dsb_move
# dsb_fetch
# dsb_shoot
# dsb_get_cell
# dsb_set_cell
# dsb_get_xp_multiplier *
# dsb_set_xp_multiplier *
*: Only uses level.
^: Unlikely to be called during normal play, only when the dungeon is first created.

Of these, all except dsb_fetch and dsb_get_cell should probably generate an error when querying out-of-bounds position (or an already created level in the case of _text2map and _image2map) as this is likely to be the result of a typo in the coordinates.

dsb_fetch could probably be made to return nil in those cases, as a non-existing tile can be assumed to contain nothing.

dsb_get_cell should return true, indicating that an out-of-bound square is a wall, although you could reasonably argue for the opposite.
User avatar
Sophia
Concise and Honest
Posts: 4240
Joined: Thu Sep 12, 2002 9:50 pm
Location: Nowhere in particular
Contact:

Post by Sophia »

Well, like I said, it's not a crash-- as such. Right now, any time DSB hits some Lua that it can't deal with, it simply exits and tells you what the problem was.

I guess it's not so different in practice, but it's a bug in your code, not mine. ;)

I guess it could continue to run, but what would be the point? The function didn't get a value it was expecting, so it'll have to return garbage. That garbage will probably get passed to other functions, who will in turn get more garbabe and return more garbage. You'll get a cascading series of error messages that might obfuscating debugging.

I do like your rationale for dsb_fetch and dsb_get_cell, though. That's not so much a "silent failure" as an assumption that all cells not within the bounds of the current walls are solid walls containing nothing special-- and that's a pretty good assumption. I'll do that for DSB 0.21.
User avatar
Parallax
DMwiki contributor
Posts: 424
Joined: Mon Aug 28, 2006 7:56 pm
Location: Back in New Jersey

Post by Parallax »

Sorry to reopen a closed discussion, but here's an extra request for DSB 0.23:
Could we also assume that cells that are out of bounds are never visited so that dsb_visited returns either nil or false (preferably nil, though) when querying out of bounds instead of crashing as it does now?
User avatar
Sophia
Concise and Honest
Posts: 4240
Joined: Thu Sep 12, 2002 9:50 pm
Location: Nowhere in particular
Contact:

Post by Sophia »

Ok, done. :)
dsb_visited will return nil if given a value out of range.
Post Reply