Generic Mapping Script

All and any discussion and development of the Mudlet Mapper.
Jor'Mox
Posts: 1142
Joined: Wed Apr 03, 2013 2:19 am

Re: Generic Mapping Script

Post by Jor'Mox »

crl775m wrote:
Wed Jan 24, 2018 3:06 pm
In check_room shouldn't the following:

Code: Select all

    return table.is_empty(t_exits) or check_doors(roomID,t_exits)
actually be:

Code: Select all

    return (not table.is_empty(t_exits)) or check_doors(roomID,t_exits)
Until I made that change it wouldn't backtrack into the previous room, it would just create new ones on every exit.
No, it should not be. That line of code is checking to see if the exits in the just entered room match the exits of an existing room in that position, and it does that by taking the new exits and expected exits, and finding any entries that aren’t in both tables. If there are any exits left, then we need to see if doors can explain the difference, and if not, it is a new room.

The fact that changing that bit of code made things work more smoothly for you isn’t surprising, but it merely means that you aren’t capturing exits properly with the triggers you set up. Making that change will remove an important safeguard that makes sure rooms are really identical, and it would mean that if someone actually captured exits properly, THEN a new room would be created when they tried to go back to an existing room.

User avatar
Vadi
Posts: 5035
Joined: Sat Mar 14, 2009 3:13 pm

Re: Generic Mapping Script

Post by Vadi »

As a sidenote - could it be possible to create some sort of a "test" script to test that the triggers people add are functioning correctly?

Jor'Mox
Posts: 1142
Joined: Wed Apr 03, 2013 2:19 am

Re: Generic Mapping Script

Post by Jor'Mox »

Sure. I just whipped up this little script to do the job. It doesn't do any of the actual diagnostics, but it captures and displays the relevant info so that someone can see what is actually making it to the script.
Code: [show] | [select all] lua
-- Generic Mapper Trigger Testing Script
-- 1/26/2018

map_test = map_test or {}
local events = {}

if exists("Map Trigger Check Alias","alias") == 0 then
    permAlias("Map Trigger Check Alias","","^check mapper$","map_test.check()")
end

function map_test.check()
    local exits = string.gsub(string.lower(map.prompt.exits)," and "," ")
    exits = string.split(exits,"[, ]+") or {}
    exits = table.concat(exits,", ")
    print(string.format("Room Name: %s\nRoom Exits: %s\nEvents Received: %s", map.prompt.room, exits, table.concat(events,", ")))
    events = {}
end

function map_test.eventHandler(event,...)
    if not table.contains(events,event) then
        table.insert(events,event)
    end
end

registerAnonymousEventHandler("onPrompt", "map_test.eventHandler")
registerAnonymousEventHandler("onMoveFail"," map_test.eventHandler")
registerAnonymousEventHandler("onVisionFail"," map_test.eventHandler")
registerAnonymousEventHandler("onRandomMove"," map_test.eventHandler")
registerAnonymousEventHandler("onForcedMove"," map_test.eventHandler")
registerAnonymousEventHandler("onNewRoom"," map_test.eventHandler")

User avatar
ulysses
Posts: 43
Joined: Fri Jan 05, 2018 7:43 pm

Re: Generic Mapping Script

Post by ulysses »

Hi,

So, after much effort I got this working tonight with some limited success for CthulhuMUD.

THANK YOU JOR'MOX for a very clever script.

Here is a list of the issues I have yet to fix:

1. The mapping window which opens is very small. I found the controls around line 100 to make it larger, but It would be nice to have it open as a separate window, is that possible?
2. If I click zoom button (+) once then the map disappears - is there any way to zoom in more gradually?
3. I used a lua function trigger in combination with the get_desc function to parse the room name. It works in simple cases but I need to strip out the weather/status info. They look like this;

Southern Trade Route (road-raining-puddles)
Temple of Ulthar - Main Hall (inside)

('inside' isn't really a problem, but the weather is as it is non-static). So I tried this:

Code: Select all

map.prompt.room = string.match(desc[#desc], '^(.*?)\(.*\)$')
But that doesn't work. Without the non-greedy modifier ? then the whole line is matched. Over the years I've done a lot of regex matching, but perhaps I'm getting rusty!

I will also need incorporate the first line of the description since some locations are not unique by their room name. This is where it will get rather tricky as there can exist spaces/messages between the room name and the description.

4. The map aliases seem to have a mind of their own - they keep getting (re)created/disabled. I've ended up with like 90 or so aliases this evening, most disabled. I would like those to be static, under one group if possible, so they don't clutter up the alias list (they are getting created in the root alias 'directory'). I can see something about that in the script, but when I click on active ones in the GUI to inspect them, they de-activate themselves. This feels a little buggy/odd. Perhaps there is something more subtle going on?

5. Are in and out recognised as directions? They seem to be ok, but haven't tested thoroughly.

6. In CthulhuMUD closed doors are shown as, for example, #north and locked doors as |#north| (however this doesn't seem to be universally applied).

7. Not sure how to configure triggers to open doors. Some doors are special - e.g. one location requires 'pull rope', another to wait for guard recognition.

8. How to add graphics to the map, if possible.

9. How to save and "connect" different maps from different regions/areas. I see there is one alias in the script:

Code: Select all

 ["Save Map Alias"] = {[[^save map$]], [[saveMap(getMudletHomeDir() .. "/map.dat")]]},
But that seems to use one file. Is that how it works - one file for all map regions?

10. CthulhuMUD has multiple regions, some of which are reached by dream walking around the place - this is like a portal. How to handle that?

11. How to find something in the scripts - for 10 or 20 lines of code this is no issue. For 1000 lines this is more problematic. I could not see a search function

That's quite a list. Any help/pointers appreciated!
Ulysses.
Wod :mrgreen:
CthulhuMUD
www.cthulhumud.com
A hugely entertaining MUD based on the horror writings of HP Lovecraft.

Jor'Mox
Posts: 1142
Joined: Wed Apr 03, 2013 2:19 am

Re: Generic Mapping Script

Post by Jor'Mox »

So, that is a lot of issues, but some are simpler than others. I'll try to address as much as I can in one go, then after that pass, we can go back and address whatever I miss.
ulysses wrote:1. The mapping window which opens is very small. I found the controls around line 100 to make it larger, but It would be nice to have it open as a separate window, is that possible?
In theory the map can be opened in a separate window, however I'm not aware of a way to do so via code. If a map window is NOT created via code, then you can use the "Show Map" option in the Toolbox menu to open a map in a separate window that starts out docked to the main window. However, once a map window is created via code, the "Show Map" option will just toggle that window's visibility, not create an independent window. So, yes, it can be done, but no, I don't know how to do it with this script.
ulysses wrote:2. If I click zoom button (+) once then the map disappears - is there any way to zoom in more gradually?
The + and - buttons move the map view in the z direction (i.e. up and down), they are not zoom buttons. Hence why it suddenly disappears. You can point at the map window and scroll with your mouse to zoom in and out.
ulysses wrote:3. I used a lua function trigger in combination with the get_desc function to parse the room name. It works in simple cases but I need to strip out the weather/status info. They look like this;

Southern Trade Route (road-raining-puddles)
Temple of Ulthar - Main Hall (inside)

('inside' isn't really a problem, but the weather is as it is non-static). So I tried this:

Code: Select all

map.prompt.room = string.match(desc[#desc], '^(.*?)\(.*\)$')
But that doesn't work. Without the non-greedy modifier ? then the whole line is matched. Over the years I've done a lot of regex matching, but perhaps I'm getting rusty!

I will also need incorporate the first line of the description since some locations are not unique by their room name. This is where it will get rather tricky as there can exist spaces/messages between the room name and the description.
So, instead of using string.match, I would use string.gsub to cut out anything between parentheses, like this:

Code: Select all

map.prompt.room = string.gsub(desc[#desc],"%s*%([^%)]+%)","")
Importantly, there is no need for room names to be distinct, as there are plenty of games with whole areas full of rooms with identical room names. There is actually a significant amount of code devoted to tracking down where you are located in case things get mixed up, and you find yourself in rooms without unique names, in which it looks at the room name and exits of the current room, and the previous room, to help narrow down where you could be at. While creating the map itself, it is important to avoid situations where you have one room created, and then loop around to approach it from a distance in which there is a room or rooms between you and the mapped room with the same name and exits, as the script looks in the direction you moved to see if it can find a matching room (with identical name and exits) before deciding to create a new room. So long as you keep that in mind, it shouldn't be a problem.
ulysses wrote:4. The map aliases seem to have a mind of their own - they keep getting (re)created/disabled. I've ended up with like 90 or so aliases this evening, most disabled. I would like those to be static, under one group if possible, so they don't clutter up the alias list (they are getting created in the root alias 'directory'). I can see something about that in the script, but when I click on active ones in the GUI to inspect them, they de-activate themselves. This feels a little buggy/odd. Perhaps there is something more subtle going on?
In my experience, sometimes there suddenly appear copies of all the temporary items, as if they were permanent ones. They are not, and if you close the profile and open it back up, they should disappear. This is what is happening with the aliases for the mapping script. They are created via tempAlias so that they cannot be edited by the user without changing the main script.
ulysses wrote:5. Are in and out recognised as directions? They seem to be ok, but haven't tested thoroughly.
Yes, in and out should work fine.
ulysses wrote:6. In CthulhuMUD closed doors are shown as, for example, #north and locked doors as |#north| (however this doesn't seem to be universally applied).
While it would in theory be possible to automate the adding of doors when exits are created, I have not yet added such a feature to the script (it is on the list of things to do). So, for now I recommend just stripping out the # symbols from your exits so that they are properly recognized by the script. As with the problem with the room names, use string.gsub.
ulysses wrote:7. Not sure how to configure triggers to open doors. Some doors are special - e.g. one location requires 'pull rope', another to wait for guard recognition.
While I could obviously set something up for a generic door opening trigger, I don't know how to handle special cases without keeping some sort of list of exceptions. While the map script doesn't currently expose the roomID, the most sensible strategy would be to access the roomID, and use that as a key in a table of rooms and exits that need special handling, along with the relevant alternative command.
ulysses wrote:8. How to add graphics to the map, if possible.
This is definitely possible, but I haven't done anything with it, so the most I could do is basically just read what is in the wiki, and pass it along to you.
ulysses wrote:9. How to save and "connect" different maps from different regions/areas. I see there is one alias in the script:

Code: Select all

 ["Save Map Alias"] = {[[^save map$]], [[saveMap(getMudletHomeDir() .. "/map.dat")]]},
But that seems to use one file. Is that how it works - one file for all map regions?
The save command is essentially just to create a backup of the map, or to allow you to pass it along to another user (there is a matching load map command that lets you do this). As for creating different areas within the map, that is done with the "set area" command. While mapping, type "set area My Area Name", and it will move the room you are currently standing in into the area with that name, creating that area if necessary. The areas don't visually connect, making essentially a number of separate maps within a single file.
ulysses wrote:10. CthulhuMUD has multiple regions, some of which are reached by dream walking around the place - this is like a portal. How to handle that?
There is an "add portal" command that can be used to accommodate this sort of thing, though at present it only allows for a single command (an arbitrary one though) to "enter" the portal. However, the actual steps needed to pass through from area to area are only truly relevant if trying to speedwalk between the rooms, so if more than one command is needed, you can just use the first such command, then finish the other steps manually, then change the area of the first room you reach in the new region once it has been created.
ulysses wrote:11. How to find something in the scripts - for 10 or 20 lines of code this is no issue. For 1000 lines this is more problematic. I could not see a search function
I copy the script into a text editor, and search there. That is also where I do most of my editing as well when working on scripts, as I have more powerful tools available than inside Mudlet.

User avatar
ulysses
Posts: 43
Joined: Fri Jan 05, 2018 7:43 pm

Re: Generic Mapping Script

Post by ulysses »

Jor'Mox wrote:
Sat Feb 03, 2018 1:59 am
So, that is a lot of issues, but some are simpler than others. I'll try to address as much as I can in one go, then after that pass, we can go back and address whatever I miss.
Thank you very much indeed for your help.
Jor'Mox wrote:
Sat Feb 03, 2018 1:59 am
ulysses wrote:1. The mapping window which opens is very small. I found the controls around line 100 to make it larger, but It would be nice to have it open as a separate window, is that possible?
In theory the map can be opened in a separate window, however I'm not aware of a way to do so via code. If a map window is NOT created via code, then you can use the "Show Map" option in the Toolbox menu to open a map in a separate window that starts out docked to the main window. However, once a map window is created via code, the "Show Map" option will just toggle that window's visibility, not create an independent window. So, yes, it can be done, but no, I don't know how to do it with this script.
I see. However there seems to be a problem preventing the script from opening the map window. Where does it do that? I tried 'stop mapping' and restarting MUDlet but still the small window appears. I don't have an issue with having to click the map button to get the dockable window to appear. In time I can circle back to this issue and see if I can work in out in the code.
Jor'Mox wrote:
Sat Feb 03, 2018 1:59 am
ulysses wrote:2. If I click zoom button (+) once then the map disappears - is there any way to zoom in more gradually?
The + and - buttons move the map view in the z direction (i.e. up and down), they are not zoom buttons. Hence why it suddenly disappears. You can point at the map window and scroll with your mouse to zoom in and out.
I'm using a macbook and have one of those trackpad thingies, I tried various gestures but to no avail. Are there some keyboard equivalents or even an in-code zoom level I could tweak?
Jor'Mox wrote:
Sat Feb 03, 2018 1:59 am
So, instead of using string.match, I would use string.gsub to cut out anything between parentheses, like this:

Code: Select all

map.prompt.room = string.gsub(desc[#desc],"%s*%([^%)]+%)","")
Importantly, there is no need for room names to be distinct, as there are plenty of games with whole areas full of rooms with identical room names. There is actually a significant amount of code devoted to tracking down where you are located in case things get mixed up, and you find yourself in rooms without unique names, in which it looks at the room name and exits of the current room, and the previous room, to help narrow down where you could be at. While creating the map itself, it is important to avoid situations where you have one room created, and then loop around to approach it from a distance in which there is a room or rooms between you and the mapped room with the same name and exits, as the script looks in the direction you moved to see if it can find a matching room (with identical name and exits) before deciding to create a new room. So long as you keep that in mind, it shouldn't be a problem.
Excellent, I will try the gsub out.
Jor'Mox wrote:
Sat Feb 03, 2018 1:59 am
ulysses wrote:4. The map aliases seem to have a mind of their own - they keep getting (re)created/disabled. I've ended up with like 90 or so aliases this evening, most disabled. I would like those to be static, under one group if possible, so they don't clutter up the alias list (they are getting created in the root alias 'directory'). I can see something about that in the script, but when I click on active ones in the GUI to inspect them, they de-activate themselves. This feels a little buggy/odd. Perhaps there is something more subtle going on?
In my experience, sometimes there suddenly appear copies of all the temporary items, as if they were permanent ones. They are not, and if you close the profile and open it back up, they should disappear. This is what is happening with the aliases for the mapping script. They are created via tempAlias so that they cannot be edited by the user without changing the main script.
Ok, but out of curiosity why are the aliases created as temporaries - they could be permanent no? I confirm that restarting the client flushed them out.
Jor'Mox wrote:
Sat Feb 03, 2018 1:59 am
Yes, in and out should work fine.
Ace, thanks.
Jor'Mox wrote:
Sat Feb 03, 2018 1:59 am
While it would in theory be possible to automate the adding of doors when exits are created, I have not yet added such a feature to the script (it is on the list of things to do). So, for now I recommend just stripping out the # symbols from your exits so that they are properly recognized by the script. As with the problem with the room names, use string.gsub.
That's a shame - it's handy for speedwalking - if I get time once I've got the other issues ironed out, I might try a few triggers myself.
Jor'Mox wrote:
Sat Feb 03, 2018 1:59 am
While I could obviously set something up for a generic door opening trigger, I don't know how to handle special cases without keeping some sort of list of exceptions. While the map script doesn't currently expose the roomID, the most sensible strategy would be to access the roomID, and use that as a key in a table of rooms and exits that need special handling, along with the relevant alternative command.
Is that just because the current roomID is local, couldn't it be made global along with any other variables which could be used in triggers? Maybe there is a more elegant way to handle this in script. It may be possible to just set up a trigger special to those locations that intercepts the movement command, then prefixes that with the special commands.
Jor'Mox wrote:
Sat Feb 03, 2018 1:59 am
ulysses wrote:8. How to add graphics to the map, if possible.
This is definitely possible, but I haven't done anything with it, so the most I could do is basically just read what is in the wiki, and pass it along to you.
Ace, I will check it out.
Jor'Mox wrote:
Sat Feb 03, 2018 1:59 am
The save command is essentially just to create a backup of the map, or to allow you to pass it along to another user (there is a matching load map command that lets you do this). As for creating different areas within the map, that is done with the "set area" command. While mapping, type "set area My Area Name", and it will move the room you are currently standing in into the area with that name, creating that area if necessary. The areas don't visually connect, making essentially a number of separate maps within a single file.
Great, so I can use the save command to back the map up in case of some kind of disaster and to share it.
Jor'Mox wrote:
Sat Feb 03, 2018 1:59 am

There is an "add portal" command that can be used to accommodate this sort of thing, though at present it only allows for a single command (an arbitrary one though) to "enter" the portal. However, the actual steps needed to pass through from area to area are only truly relevant if trying to speedwalk between the rooms, so if more than one command is needed, you can just use the first such command, then finish the other steps manually, then change the area of the first room you reach in the new region once it has been created.
Will probably not be ever speed-walking between the waking world and the dreaming one! There are several commands for passing between the two and the results are unpredictable - one can find oneself trapped in a nightmare! So the mapper needs to be a bit smart if things don't go according to plan. I suppose if it gets lost, one could just pull up the correct area then manually set the current location.
Jor'Mox wrote:
Sat Feb 03, 2018 1:59 am
I copy the script into a text editor, and search there. That is also where I do most of my editing as well when working on scripts, as I have more powerful tools available than inside Mudlet.
Thanks, I had feeling that it would be like that.
Wod :mrgreen:
CthulhuMUD
www.cthulhumud.com
A hugely entertaining MUD based on the horror writings of HP Lovecraft.

Jor'Mox
Posts: 1142
Joined: Wed Apr 03, 2013 2:19 am

Re: Generic Mapping Script

Post by Jor'Mox »

So, a few points where I can see extra clarification or info would be useful.

To keep the map window from being created, you want to look in the script for the config function, which should be the second function after the block of help text at the top, and comment out the two lines within it that start with windowManager.

You can set the map zoom level via code, using the setMapZoom function, followed by calling centerview to refresh the window. It would look something like this:

Code: Select all

setMapZoom(10) -- the highest zoom level is 1, with larger numbers zooming further out
centerview()
The aliases are created as temporary ones because this is not my first script package, and in previous instances, people have altered the permanent aliases created, and then it was nearly impossible for me to discover what had gone wrong. Using temporary aliases ensures that they remain unaltered at all times, thereby significantly easing attempts at debugging remotely. You could easily alter the make_aliases function to make permanent ones if you so choose, but that is why I like to use temp aliases and triggers in my code.

While there is nothing in place now to handle automatically adding doors, there IS a system in place to let you add doors, via the "add door" command (syntax: add door <dir> <optional door status: none, open, closed (default), locked> <optional door one way: yes, no (default)>). The only reason you couldn't add such doors within the trigger that captures the exits is that the room wouldn't have been created yet. In theory, you could leave the # characters in the exits until your prompt trigger fired, at which point you could search for them, strip them out, and keep a list of directions with doors, and AFTER the onPrompt event has been raised, execute the relevant commands via expandAlias to create the doors.

The current roomID is a local variable (currentRoom), and it is set within the set_room function. If you wanted to make that value accessible, you could copy that value to a globally accessible variable within that function, presumably right after the line where the currentRoom variable is set. I would of course recommend making it a part of the larger map table (map.roomID perhaps), but that is entirely up to you.

The mapper is quite smart when it comes to tracking you down, as the game for which I originally built it has multiple means of more or less random travel. Usually within just two or three rooms of movement at a new location, it will have figured out where you are at, though if there are large areas with essentially identical rooms, it could remain confused until you reached a more distinctive location. If you room you come out in is distinct though, it will know instantly where you are.

After going back to your code where you tried to remove the weather from the room name, I realized the flaw in what you were doing. You were using proper regex syntax, designating special characters with a \. But the string library uses % symbols for that purpose. It also has a slightly more limited set of regex capabilities than normal regex, which can be important when trying to use it, though what you were trying to do is well within its limits.

I hope this helps clear up things a bit more. Let me know if you run into any snags.

User avatar
ulysses
Posts: 43
Joined: Fri Jan 05, 2018 7:43 pm

Re: Generic Mapping Script

Post by ulysses »

Ace, thanks!!
Jor'Mox wrote:
Sat Feb 03, 2018 9:26 pm
To keep the map window from being created, you want to look in the script for the config function, which should be the second function after the block of help text at the top, and comment out the two lines within it that start with windowManager.
Done. And the dockable window is back!
Jor'Mox wrote:
Sat Feb 03, 2018 9:26 pm
You can set the map zoom level via code, using the setMapZoom function, followed by calling centerview to refresh the window. It would look something like this:

Code: Select all

setMapZoom(10) -- the highest zoom level is 1, with larger numbers zooming further out
centerview()
Ace, I can just set an alias for that taking an argument for the zoom level. Bit clunky but it will do for now. I can circle back later and see if I can do it in the GUI.
Jor'Mox wrote:
Sat Feb 03, 2018 9:26 pm
The aliases are created as temporary ones because this is not my first script package, and in previous instances, people have altered the permanent aliases created, and then it was nearly impossible for me to discover what had gone wrong. Using temporary aliases ensures that they remain unaltered at all times, thereby significantly easing attempts at debugging remotely. You could easily alter the make_aliases function to make permanent ones if you so choose, but that is why I like to use temp aliases and triggers in my code.
Oh I see. Well, I'll just create them permanently in their own group. What's very odd now is that when I fire up the client, ALL the aliases are not showing up, so I can't start the mapper. I can see that they get created in config() but that seems to get only called from a map.eventHandler function. Perhaps I have indadvertedly broken something... I removed the last room in one of the areas and it got a bit upset then. Map screen greyed out and says 'no map or valid position'.
Jor'Mox wrote:
Sat Feb 03, 2018 9:26 pm
While there is nothing in place now to handle automatically adding doors, there IS a system in place to let you add doors, via the "add door" command (syntax: add door <dir> <optional door status: none, open, closed (default), locked> <optional door one way: yes, no (default)>). The only reason you couldn't add such doors within the trigger that captures the exits is that the room wouldn't have been created yet. In theory, you could leave the # characters in the exits until your prompt trigger fired, at which point you could search for them, strip them out, and keep a list of directions with doors, and AFTER the onPrompt event has been raised, execute the relevant commands via expandAlias to create the doors.
This sounds like a PLAN!
Jor'Mox wrote:
Sat Feb 03, 2018 9:26 pm
The current roomID is a local variable (currentRoom), and it is set within the set_room function. If you wanted to make that value accessible, you could copy that value to a globally accessible variable within that function, presumably right after the line where the currentRoom variable is set. I would of course recommend making it a part of the larger map table (map.roomID perhaps), but that is entirely up to you.
Would there be an issue with making the whole map global?
Jor'Mox wrote:
Sat Feb 03, 2018 9:26 pm
The mapper is quite smart when it comes to tracking you down, as the game for which I originally built it has multiple means of more or less random travel. Usually within just two or three rooms of movement at a new location, it will have figured out where you are at, though if there are large areas with essentially identical rooms, it could remain confused until you reached a more distinctive location. If you room you come out in is distinct though, it will know instantly where you are.
That sounds pretty awesome.
Jor'Mox wrote:
Sat Feb 03, 2018 9:26 pm
After going back to your code where you tried to remove the weather from the room name, I realized the flaw in what you were doing. You were using proper regex syntax, designating special characters with a \. But the string library uses % symbols for that purpose. It also has a slightly more limited set of regex capabilities than normal regex, which can be important when trying to use it, though what you were trying to do is well within its limits.
Yup, my background is perl, shell, python and C++ and Lua is a bit new to me. I think your gsub pattern wasn't working so I followed the Lua tutorials and came up with this simpler version which works fine;

Code: Select all

map.prompt.room = string.gsub(desc[#desc],"(%(.*%)","")
Jor'Mox wrote:
Sat Feb 03, 2018 9:26 pm
I hope this helps clear up things a bit more. Let me know if you run into any snags.
The only pressing thing I can think of right now is how to remove/reset parts of the map. I've got a lot of areas called test, test1 etc and ideally would like to scrub the whole thing and start again or selectively remove certain areas - there doesn't seem to be a function for that.
Wod :mrgreen:
CthulhuMUD
www.cthulhumud.com
A hugely entertaining MUD based on the horror writings of HP Lovecraft.

Jor'Mox
Posts: 1142
Joined: Wed Apr 03, 2013 2:19 am

Re: Generic Mapping Script

Post by Jor'Mox »

The aliases are generally only going to fail to work under one of three conditions. One, there is a syntax error in the code somewhere, which prevents it from loading. If there is no such error shown when you click on the script, it could still be a reference to a table index that is made before the table exists, which then is resolved once the script is run by you opening it. Two, there is some error in the config function that occurs before the make_alias function is called. Three, there is an error in the make_alias function. In both cases where there is an error, it should show up in the error pane inside Mudlet when you connect, along with the exact line on which the error shows up.

If you delete the room that the map window is currently centered on, you will get the big gray screen, which is irritating. If, however, you move your character into a room that remains on the map, it will frequently find you right away, and failing that you can use the "find me" command to force it to try to pin down your current location. Note that when you delete a room, all connections leading to it are also deleted, so generally the rooms immediately adjacent to it no longer have all their exits, and therefore don't properly match, so you need to move two rooms away for this to work, and you will need to fix things around the break that has been created by deleting the room (which I typically do by using the "shift" command to move the newly created room on top of the old one, and then "merge rooms" to force them to combine together).

In general, I find it best to keep as many variables local in scope as possible, as global ones can be modified by other scripts, which can then cause problems for the script they originated in. Creating an exposed copy of the relevant variable lets you get to the data without creating any potential problems for the script, as it isn't used anywhere. So even if you change it, no harm is done. Mostly though, I just don't like having to keep track of what variable names all my scripts use, so I keep them either local or contained in an overarching table, as can be seen with all of the global variables in the map script. Obviously this is a style choice, but that is my reasoning for the choice I made.

I'm surprised that the pattern I gave didn't work, as it was working just fine in my test cases, but whatever works.

To delete an area, first select the area in the map window, check the "Info" checkbox, and click on one of the rooms. You should be able to see the area name and area ID number. You can then use the deleteArea function, using the areaID as the argument, to delete the area. You can also use the getAreaTable function to get a table with all the areas in the map, and their corresponding areaIDs, and just run a for loop if you want to clear out everything.

User avatar
ulysses
Posts: 43
Joined: Fri Jan 05, 2018 7:43 pm

Re: Generic Mapping Script

Post by ulysses »

Jor'Mox wrote:
Sat Feb 03, 2018 11:22 pm
The aliases are generally only going to fail to work under one of three conditions. One, there is a syntax error in the code somewhere, which prevents it from loading. If there is no such error shown when you click on the script, it could still be a reference to a table index that is made before the table exists, which then is resolved once the script is run by you opening it. Two, there is some error in the config function that occurs before the make_alias function is called. Three, there is an error in the make_alias function. In both cases where there is an error, it should show up in the error pane inside Mudlet when you connect, along with the exact line on which the error shows up.
Normally the temporary aliases are invisible in the Alias pane, but copy'n'paste of an existing permanent alias, or creation of an alias group then causes a refresh of the list and the temp aliases appear. I was confusing myself (as usual!) - everything was ok but I was typing 'start mapper' not 'start mapping'. So the aliases were all there. Interestingly in my version of the script v1.12, there is this line;

Code: Select all

{[[^set character (.*)$]],[[map.character = matches[2]]},


Which comes out like this as an alias command

Code: Select all

map.character = matches[2 
I fixed that by changing it to this:

Code: Select all

["Set Character Alias"]   = {[[^set character (.*)$]],[[map.character = matches[2] ]]},
I wonder what that does anyway? For the moment, I'm sticking with your temp aliases - I've decided they don't bother me too much!
Jor'Mox wrote:
Sat Feb 03, 2018 11:22 pm
If you delete the room that the map window is currently centered on, you will get the big gray screen, which is irritating. If, however, you move your character into a room that remains on the map, it will frequently find you right away, and failing that you can use the "find me" command to force it to try to pin down your current location. Note that when you delete a room, all connections leading to it are also deleted, so generally the rooms immediately adjacent to it no longer have all their exits, and therefore don't properly match, so you need to move two rooms away for this to work, and you will need to fix things around the break that has been created by deleting the room (which I typically do by using the "shift" command to move the newly created room on top of the old one, and then "merge rooms" to force them to combine together).
I've had a happy afternoon mapping CthulhuMUD and have got about 700 rooms mapped (which is about a 1/10 of the game, reportedly). I quite often run into mapping issues, and I found the best way of sorting them out is to turn off the mapper, backtrack a few rooms to a 'safe' area, delete the branch which has gone wrong, add finally an an unknown exit back out of the last room on the branch. I did try with merge about three times, but I think it only worked once.
Jor'Mox wrote:
Sat Feb 03, 2018 11:22 pm
In general, I find it best to keep as many variables local in scope as possible, as global ones can be modified by other scripts, which can then cause problems for the script they originated in. Creating an exposed copy of the relevant variable lets you get to the data without creating any potential problems for the script, as it isn't used anywhere. So even if you change it, no harm is done. Mostly though, I just don't like having to keep track of what variable names all my scripts use, so I keep them either local or contained in an overarching table, as can be seen with all of the global variables in the map script. Obviously this is a style choice, but that is my reasoning for the choice I made.
Sure, I was wondering if there would be any specific side-effects from exposing your mapping variables.
Jor'Mox wrote:
Sat Feb 03, 2018 11:22 pm
To delete an area, first select the area in the map window, check the "Info" checkbox, and click on one of the rooms. You should be able to see the area name and area ID number. You can then use the deleteArea function, using the areaID as the argument, to delete the area. You can also use the getAreaTable function to get a table with all the areas in the map, and their corresponding areaIDs, and just run a for loop if you want to clear out everything.
Thanks, I confirm that works. I've got another very minor issue now in that I've ended up with empty z-levels (if that is the right terminology), caused by going up and the mapper not finding the room on the upper floor, so it creates a new level with a new room. After removing the room, I'm left with an empty level. Perhaps there is a compress or cleanup function.

Well, you've been super-helpful Jor'Mox. It's great to have a working mapper and one that I can develop. There are a few niggles and I've got quite a lot to learn about the mapper in general, so I'm going off to do that. If I have further map questions I'll post them into a separate thread unless they specifically relate to your general script.
Wod :mrgreen:
CthulhuMUD
www.cthulhumud.com
A hugely entertaining MUD based on the horror writings of HP Lovecraft.

Post Reply