Generic Mapping Script

All and any discussion and development of the Mudlet Mapper.
User avatar
ulysses
Posts: 52
Joined: Fri Jan 05, 2018 7:43 pm

Re: Generic Mapping Script

Post by ulysses »

Jor'Mox wrote:
Fri May 18, 2018 8:49 pm
The trick is, there shouldn't be any difference between entering the movements manually as compared to sending them via this particular function. What happens if you just spam in directions REALLY fast? Also, what if you have some other bit of code inputing a number of movement commands for you all at once (say, an alias that walks you along a particular path by sending the commands all at the same time)?

Also, I didn't expect that changing to the code I gave would change anything, it was definitely just a "here is a coding tip" sort of thing.
Chaining the 15 directions together with the semi-colon command binder, allows the tracking to work properly and not get lost. I tried it several times in both directions.

The print statement in the speedwalk function correctly shows the route, and the movement is there to get from A to B (15 moves) but the glowing tracker gets lost.
Wod :mrgreen:
CthulhuMUD
www.cthulhumud.com
A hugely entertaining MUD based on the horror writings of HP Lovecraft.

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

Re: Generic Mapping Script

Post by Jor'Mox »

And what happens if some OTHER function spams out the commands? I'm curious if this is specific to the doSpeedWalk function, or if ANY instance of numerous movement commands being sent via code causes the same problem (which, by all rights it should, since there is nothing special about the doSpeedWalk function as far as I can tell, but then there is nothing special about it as compared to entering commands manually either... so I'm a bit lost with this).

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

Re: Generic Mapping Script

Post by ulysses »

Jor'Mox wrote:
Sat May 19, 2018 10:36 am
And what happens if some OTHER function spams out the commands? I'm curious if this is specific to the doSpeedWalk function, or if ANY instance of numerous movement commands being sent via code causes the same problem (which, by all rights it should, since there is nothing special about the doSpeedWalk function as far as I can tell, but then there is nothing special about it as compared to entering commands manually either... so I'm a bit lost with this).
Are we entering the twighlight zone?! I tried an alias and a function called from an alias and they are both fine:

Code: Select all

function doBA()
  send("n")
  send("n")
  send("n")
  send("n")
  send("n")
  send("n")
  send("n")
  send("n")
  send("n")
  send("n")
  send("w")
  send("w")
  send("w")
  send("w")
  send("w")
end

function doAB()
  send("e")
  send("e")
  send("e")
  send("e")
  send("e")
  send("s")
  send("s")
  send("s")
  send("s")
  send("s")
  send("s")
  send("s")
  send("s")
  send("s")
  send("s")
end
What could it be about the map script which is different?

Thanks,
Wod.
Wod :mrgreen:
CthulhuMUD
www.cthulhumud.com
A hugely entertaining MUD based on the horror writings of HP Lovecraft.

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

Re: Generic Mapping Script

Post by Jor'Mox »

One potential difference is that in the doSpeedWalk function, the actual strings are being supplied via some external source, opening up the possibility that they contain some variation that isn't recognized by the capture_move_cmd function, which obviously isn't a problem when you are manually providing those strings (either as direct commands or via code). Bear in mind that the speedWalkDir table is constructed by Mudlet, not by the script, so attributing blame would be complicated at best. But, we should be able to test for this. In the doSpeedWalk function, before sending a movement command, we can check to see if it is the string we expect because keyed tables only accept exact duplicate strings, so we can use an if statement like this:
Code: [show] | [select all] lua
next_step = function ()
    local step = table.remove(path,1)
    if exitmap[step] then
        send(step)
        if #path > 0 then
            tempTimer(delay, next_step)
        else
            map.find_me()
        end
    else
        print("Error: Direction Mismatch")
        display(step)
        display(path)
    end
end
So, basically this should just work as a debug version of the doSpeedWalk function that we already have. If any strings aren't in the set {'n','s','e','w','ne','nw','se','sw','u','d','in','out'} then it should spit out an error and show the offending string. Granted, I expect the string will LOOK like it belongs regardless. But hopefully we can learn something from running this. If not, then I'm going to have to make some debugging modifications to the capture_move_cmd function itself to see where things are falling apart, and why.

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

Re: Generic Mapping Script

Post by ulysses »

Jor'Mox wrote:
Sat May 19, 2018 5:32 pm
One potential difference is that in the doSpeedWalk function, the actual strings are being supplied via some external source, opening up the possibility that they contain some variation that isn't recognized by the capture_move_cmd function, which obviously isn't a problem when you are manually providing those strings (either as direct commands or via code). Bear in mind that the speedWalkDir table is constructed by Mudlet, not by the script, so attributing blame would be complicated at best. But, we should be able to test for this. In the doSpeedWalk function, before sending a movement command, we can check to see if it is the string we expect because keyed tables only accept exact duplicate strings, so we can use an if statement like this:
Code: [show] | [select all] lua
next_step = function ()
    local step = table.remove(path,1)
    if exitmap[step] then
        send(step)
        if #path > 0 then
            tempTimer(delay, next_step)
        else
            map.find_me()
        end
    else
        print("Error: Direction Mismatch")
        display(step)
        display(path)
    end
end
So, basically this should just work as a debug version of the doSpeedWalk function that we already have. If any strings aren't in the set {'n','s','e','w','ne','nw','se','sw','u','d','in','out'} then it should spit out an error and show the offending string. Granted, I expect the string will LOOK like it belongs regardless. But hopefully we can learn something from running this. If not, then I'm going to have to make some debugging modifications to the capture_move_cmd function itself to see where things are falling apart, and why.
Thanks! Sadly, that doesn't reveal the problem. I tried it on various routes and the directions issued are all OK. I would expect this actually, since the walk actually does work - it's the tracking on the map which gets lost.

Hmmm
Wod
Wod :mrgreen:
CthulhuMUD
www.cthulhumud.com
A hugely entertaining MUD based on the horror writings of HP Lovecraft.

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

Re: Generic Mapping Script

Post by Jor'Mox »

Okay, time to see if something is inexplicably failing inside the script. The plan is to make some debugging type modifications to two functions capture_move_dir and capture_room_info, so we can see if things are being properly captured or not. These functions are located together, starting around line 550. Here is a modified version of those functions that I think should help add some visibility:
Code: [show] | [select all] lua
local function capture_move_cmd(dir,priority)
    -- captures valid movement commands
    dir = string.lower(dir)
    if dir == "/" then dir = "recall" end
    if table.contains(exitmap,dir) or string.starts(dir,"enter ") or dir == "recall" then
        if priority then
            table.insert(move_queue,1,exitmap[dir] or dir)
            print("Priority move: " .. (exitmap[dir] or dir)) -- debug
        else
            table.insert(move_queue,exitmap[dir] or dir)
            print("Move: " .. (exitmap[dir] or dir)) -- debug
        end
        if not (exitmap[dir] or dir) then print("Invalid Direction") end -- debug
    elseif currentRoom then
        local special = getSpecialExitsSwap(currentRoom) or {}
        if special[dir] then
            if priority then
                table.insert(move_queue,1,dir)
                print("Priority special move: " .. dir) -- debug
            else
                table.insert(move_queue,dir)
                print("Special move: " .. dir) -- debug
            end
            if not (exitmap[dir] or dir) then print("Invalid Direction") end -- debug
        end
    end
end

local function capture_room_info(name, exits)
    -- captures room info, and tries to move map to match
    if (not vision_fail) and name and exits then
        prevName = currentName
        prevExits = currentExits
        name = string.trim(name)
        currentName = name
        exits = string.gsub(string.lower(exits)," and "," ")
        currentExits = (exits ~= "" and string.split(exits,"[, ]+")) or {}
        print("Room Info: " .. currentName) -- debug
        display(currentExits) -- debug
        move_map()
    elseif vision_fail then
        move_map()
    end
end
This should show exactly what movement commands are captured as well as what room info is captured. Hopefully that will show some discrepancy that at least points to where things are falling apart. All added code has been marked so it can be removed later more easily.

Edit: Fixed the code so the invalid direction message shouldn't show up improperly.
Last edited by Jor'Mox on Mon May 21, 2018 10:52 pm, edited 2 times in total.

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

Re: Generic Mapping Script

Post by ulysses »

Jor'Mox wrote:
Mon May 21, 2018 7:51 pm
Okay, time to see if something is inexplicably failing inside the script. The plan is to make some debugging type modifications to two functions capture_move_dir and capture_room_info, so we can see if things are being properly captured or not. These functions are located together, starting around line 550. Here is a modified version of those functions that I think should help add some visibility:
Code: [show] | [select all] lua
local function capture_move_cmd(dir,priority)
    -- captures valid movement commands
    dir = string.lower(dir)
    if dir == "/" then dir = "recall" end
    if table.contains(exitmap,dir) or string.starts(dir,"enter ") or dir == "recall" then
        if priority then
            table.insert(move_queue,1,exitmap[dir] or dir)
            print("Priority move: " .. (exitmap[dir] or dir)) -- debug
        else
            table.insert(move_queue,exitmap[dir] or dir)
            print("Move: " .. (exitmap[dir] or dir)) -- debug
        end
        if not exitmap[dir] or dir then print("Invalid Direction") end -- debug
    elseif currentRoom then
        local special = getSpecialExitsSwap(currentRoom) or {}
        if special[dir] then
            if priority then
                table.insert(move_queue,1,dir)
                print("Priority special move: " .. dir) -- debug
            else
                table.insert(move_queue,dir)
                print("Special move: " .. dir) -- debug
            end
            if not exitmap[dir] or dir then print("Invalid Direction") end -- debug
        end
    end
end

local function capture_room_info(name, exits)
    -- captures room info, and tries to move map to match
    if (not vision_fail) and name and exits then
        prevName = currentName
        prevExits = currentExits
        name = string.trim(name)
        currentName = name
        exits = string.gsub(string.lower(exits)," and "," ")
        currentExits = (exits ~= "" and string.split(exits,"[, ]+")) or {}
        print("Room Info: " .. currentName) -- debug
        display(currentExits) -- debug
        move_map()
    elseif vision_fail then
        move_map()
    end
end
This should show exactly what movement commands are captured as well as what room info is captured. Hopefully that will show some discrepancy that at least points to where things are falling apart. All added code has been marked so it can be removed later more easily.
Awesome, thanks! I popped those two functions in place of the existing ones and got the following output. I tried a speedwalk which was three 3 east movements and the result was that I moved three times east, but the tracking got lost at the second room, i.e. it was stuck one behind where I was.

Code: Select all

Path to Arkham - Intersection of S. Garrison St. & Church St.: e, e, e    
e
Move: east    
Invalid Direction    
You proceed along Church Street.
Arkham - West Church Street - 300 Block (city-raining-puddles)
  The surrounding area was once a normal urban neighborhood, a mixture of homes
and shops that were owned and operated by local residents.  However, over the
last century and more, it has changed to a strictly commercial area that
caters to the student body at the university.  The campus lies on the southern
side of the street, separated from the sidewalk by a wrought-iron fence, and
several tall buildings form a neat row along the northern side of the street. 
Church Street extends to the east and west.
 
  A small sign hangs on the shop to the north.
 
[Exits: #north east west]
Seraph flies in.
(08:37) (3019/3019hp 2263/2263mn 2418/2421mv) Level:(155 + 27%) 
e
Move: east    
Invalid Direction    
You proceed along Church Street.
Arkham - West Church Street - 200 Block (city-raining-puddles)
  The campus of Miskatonic University dominates the southern side of the street,
stretching off across several city blocks toward its main entrance to west. 
The lawn that sits at the front of the campus bears a lush layer of green
grass, highlighted with sprawling elm trees and small gardens of bright
flowers.  The sweet aromas of the lawn drift past the wrought-iron fence and
across the street.  Several tall, colonial buildings stand on the northern
side of the road.  Church Street leads off to the east and west.
 
  A small sign stands before the building to the north.
 
[Exits: #north east west]
(Too weak) A stray tom cat stands off to the side, tail swishing back and forth.
Seraph flies in.
(08:38) (3019/3019hp 2263/2263mn 2415/2421mv) Level:(155 + 27%) 
e
Move: east    
Invalid Direction    
You proceed along Church Street.
Arkham - Intersection of S. Garrison St. & Church St. (city-raining-puddles)
  The intersection is one of the most heavily-traveled junctions in all of
Arkham.  Garrison Street, as the largest and longest street in the city,
always has a steady flow of traffic upon it, and Church Street is the location
of the famous Miskatonic University, which stands several blocks to the west. 
The combination of residents, visitors, and college students that pass through
the intersection creates a constant flurry of activity.  Garrison Street leads
to the north and south, while Church Street extends to the east and west.
[Exits: north east south west]
Seraph flies in.
(08:39) (3019/3019hp 2263/2263mn 2412/2421mv) Level:(155 + 27%) 


Hopefully that gives us a clue?
Wod :mrgreen:
CthulhuMUD
www.cthulhumud.com
A hugely entertaining MUD based on the horror writings of HP Lovecraft.

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

Re: Generic Mapping Script

Post by Jor'Mox »

Okay, so, for one, I notice that my code had a bit of an issue, in that the Invalid Direction messages were popping up improperly (obviously I needed some parentheses in the if statements). But, I also notice that there is NO info from the room capture function. At all. That function gets called every time the onPrompt event is raised while the room_detected variable is true, so it should have fired three times in that example, showing the room name and exits each time. That tells me the direction capture is solid, but the room capture is the issue here (though it doesn't tell me WHAT is wrong in that area, just that we need to look at that). What do you get when you just walk that path manually? The same, or do you see the exits and room name for each room after the prompt?

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

Re: Generic Mapping Script

Post by ulysses »

Jor'Mox wrote:
Mon May 21, 2018 10:51 pm
Okay, so, for one, I notice that my code had a bit of an issue, in that the Invalid Direction messages were popping up improperly (obviously I needed some parentheses in the if statements). But, I also notice that there is NO info from the room capture function. At all. That function gets called every time the onPrompt event is raised while the room_detected variable is true, so it should have fired three times in that example, showing the room name and exits each time. That tells me the direction capture is solid, but the room capture is the issue here (though it doesn't tell me WHAT is wrong in that area, just that we need to look at that). What do you get when you just walk that path manually? The same, or do you see the exits and room name for each room after the prompt?
When I walk the path manually, I get the same output, but the tracker follows me successfully. When I was setting the mapper up, I defined a 'cm' (check map) alias which exxecuted map_test.check(). This shows:

Code: Select all

Room Name: Arkham - Intersection of S. Garrison St. & Church St.
Room Exits: north, east, south, west
Events Received: onNewRoom, onPrompt    
So it proves that the map/triggers are working in some sense.

Thanks!
Wod
Wod :mrgreen:
CthulhuMUD
www.cthulhumud.com
A hugely entertaining MUD based on the horror writings of HP Lovecraft.

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

Re: Generic Mapping Script

Post by Jor'Mox »

So, the question is, why are the debug messages not firing. So, here is a further modified version of the capture_room_info function, along with a modified event handler function.
Code: [show] | [select all] lua
local function capture_room_info(name, exits)
    -- captures room info, and tries to move map to match
    print("Capturing Room Info") -- debug
    if (not vision_fail) and name and exits then
        prevName = currentName
        prevExits = currentExits
        name = string.trim(name)
        currentName = name
        exits = string.gsub(string.lower(exits)," and "," ")
        currentExits = (exits ~= "" and string.split(exits,"[, ]+")) or {}
        print("Room Info: " .. currentName) -- debug
        display(currentExits) -- debug
        move_map()
    elseif vision_fail then
        print("Vision Failure") -- debug
        move_map()
    end
end
Code: [show] | [select all] lua
function map.eventHandler(event,...)
    if event == "onPrompt" and room_detected then
        print("Prompt", map.prompt.room, map.prompt.exits)
        room_detected = false
        capture_room_info(map.prompt.room, map.prompt.exits)
    elseif event == "onMoveFail" then
        table.remove(move_queue,1)
    elseif event == "onVisionFail" then
        vision_fail = true
        room_detected = true
    elseif event == "onRandomMove" then
        random_move = true
        move_queue = {}
    elseif event == "onForcedMove" then
        capture_move_cmd(arg[1],arg[2]=="true")
    elseif event == "onNewRoom" then
        room_detected = true
    elseif event == "sysDataSendRequest" then
        capture_move_cmd(arg[1])
    elseif event == "sysDownloadDone" and downloading then
        loadMap(getMudletHomeDir() .. "/map.dat")
        downloading = false
        print("Map File Loaded.")
    elseif event == "sysConnectionEvent" or event == "sysInstall" then
        config()
    end
end
Hopefully we will get more than enough debug info from these versions of things.

Post Reply