I'm working in my secret labs to develop a (hopefully) fun script that needs to detect if a level exists, then looks for a specific object on that level. If I use "entitiesAt(level, x, y)" with an invalid level, it crashes the script. How can I tell if a specific level exists and make a decision accordingly? I've searched the docs and forum, but I've not found anything yet.
Thanks Everyone, -Lark
See if a Level Exists from a Script?
Re: See if a Level Exists from a Script?
what the heck? When will you "not know" when a level exists?
Finished Dungeons - complete mods to play
Re: See if a Level Exists from a Script?
The script needs to look for something on the level below where the script is running. My hopes are that this script can be pasted in anywhere it's desired without modifications regardless of the size of the dungeon. Right now, if I paste it verbatim on the last level, it crashes. Obviously, I can easily place a parameter of "lastLevel = 20" into the script once, then use that copy everywhere, but I'm trying to make it totally dynamic for others to use. Does this help? Hopefully I'll post it next week, but it needs more tweaking first!
- Edsploration
- Posts: 104
- Joined: Wed Sep 19, 2012 4:32 pm
Re: See if a Level Exists from a Script?
I tried using the allEntities(level) iterator but don't know if it's possible to catch the error of calling a level that doesn't exist. I suppose it's possible to loop through all the objects and check for a down staircase or pit, but that's a really ugly solution and doesn't capture teleporters.
Open Project -> Community FrankenDungeon: viewtopic.php?f=14&t=4276
Re: See if a Level Exists from a Script?
Check out viewtopic.php?f=14&t=3723 for my Automatic Elevator script. Multiple scripts stack on levels above and below each other to form an elevator. Since the script was to always look above and below itself for another (elevator) script, I was hoping to not have the script crash if it was already on the last level. Looking downward again crashes it. As it turned out, however, I needed several other parameters, so I just included the upper and lower limits of the elevator as parameters too.Komag wrote:what the heck? When will you "not know" when a level exists?
So while the request sounded silly, it really had a use. I'm going to rewrite the stack of scripts as a single script now that I know how, but level checking would still be nice to get the user a nice error message if they configure an elevator beyond the actual levels that exist. It’s not a big deal, of course.
Cheers, -Lark
- djoldgames
- Posts: 107
- Joined: Fri Mar 23, 2012 11:28 pm
- Contact:
Re: See if a Level Exists from a Script?
Simple - build your own array (table) like
and check it in all your functions?
Code: Select all
MyLevels = { 1,2,3,4,5 }[MAP] Interactive Maps of Isle Nex - using Google maps technology
[MOD] Eye of the Beholder: Waterdeep Sewers - recreation for Grimrock
www.oldgames.sk
[MOD] Eye of the Beholder: Waterdeep Sewers - recreation for Grimrock
www.oldgames.sk
- JohnWordsworth
- Posts: 1397
- Joined: Fri Sep 14, 2012 4:19 pm
- Location: Devon, United Kingdom
- Contact:
Re: See if a Level Exists from a Script?
A completely theoretical and untested suggestion...
This assumes that allEntities throws an error if you pass an invalid level (instead of just returning nothing, which would also give you a useful result?). It also assumes that it's a Lua catchable error and that Lua in Grimrock supports pcall!
Edit: Equally, you could use pcall with your original call and then check the status to see if it worked or not!
Code: Select all
local level = 17
local status, err = pcall(allEntities, level)
if status == true
print(level .. " exists")
else
Print("Boo, no more levels.")
end
Edit: Equally, you could use pcall with your original call and then check the status to see if it worked or not!
My Grimrock Projects Page with links to the Grimrock Model Toolkit, GrimFBX, Atlas Toolkit, QuickBar, NoteBook and the Oriental Weapons Pack.
Re: See if a Level Exists from a Script?
This would have been great for this, and many other applications. It does not appear, however, that Grimrock supports pcall as I get attempt to call global pcall (a nil value). Thank you for the suggestion, however. -LarkJohnWordsworth wrote:...that Lua in Grimrock supports pcall!
