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?
(done) Accessing level information
Moderator: Sophia
Forum rules
Please read the Forum rules and policies before posting.
Please read the Forum rules and policies before posting.
- Sophia
- Concise and Honest
- Posts: 4240
- Joined: Thu Sep 12, 2002 9:50 pm
- Location: Nowhere in particular
- Contact:
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
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
- Parallax
- DMwiki contributor
- Posts: 424
- Joined: Mon Aug 28, 2006 7:56 pm
- Location: Back in New Jersey
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 ). 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.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.
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.
- Sophia
- Concise and Honest
- Posts: 4240
- Joined: Thu Sep 12, 2002 9:50 pm
- Location: Nowhere in particular
- Contact:
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.
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.