• I recently started encountering this error on a private server:

    at parseRoomName (<isolated-vm>:20356:15)
    at toWorldPosition (<isolated-vm>:20408:22)
    at <isolated-vm>:20452:26
    at arrayMap (<isolated-vm>:2645:25)
    at Function.map (<isolated-vm>:7949:14)
    at Object.search (<isolated-vm>:20442:23)
    at Object.search (<isolated-vm>:27254:42)
    

    I simplified the code to the following minimum which still creates the error:

    var _pos_a = new RoomPosition(25, 25, 'W3N7');
    var _pos_b = new RoomPosition(30, 30, 'W3N7');
    
    var _cost_matrix = CostMatrixExit();
    var _path = PathFinder.search(_pos_a, { pos: _pos_b, range: 1 }, { roomCallback: _cost_matrix });
    

    _cost_matrix is a function as follows:

     CostMatrixExit: function ()
    {
        let _cost_matrix = new PathFinder.CostMatrix;
        maxOps = 2000;
        for (var _x = 0; _x < 50; _x++)
            for (var _y = 0; _y < 50; _y++)
            {
                if (_x < 1 || _x > 49 || _y < 1 || _y > 49)
                    _cost_matrix.set(_x, _y, 255);
            }
        return _cost_matrix;
    },
    

    I'm not sure what has gone wrong, it did work before, for a long time.

    If anyone can help me out I would greatly appreciate it πŸ™‚



  • A couple things:

    • In your code, _cost_callback is a CostMatrix, not a function. roomCallback should be a function instead. Try removing the line var _cost_matrix = CostMatrixExit(); and replacing _cost_matrix in the next line with CostMatrixExit (no parentheses).
    • Your line that says maxOps = 2000; doesn’t actually do anything. To change the maximum number of operations for the pathfinder, you need to move it into the options object, like this: PathFinder.search(_pos_a, { pos: _pos_b, range: 1 }, { roomCallback: CostMatrixExit, maxOps: 2000 });

    Try those changes and let me know if it still breaks.



  • this is an example in game, where i stored _pos_a to the memory, you can see it's filled in correctly, with the right room name, i circled in red where _pos_a square is located

    0_1559918957621_Capture.PNG



  • @jbyoshi Thanks for the help; I'm kinda ashamed, seems like the error wasn't caused by _pos_a, but by _pos_b, in my actual code I use the variable "_closest" to find a RoomPosition which i pass to PathFinder.search, i also recently added another variable with the same name wich calculated distance, so in this case _pos_a was correct, but _pos_b was a integral value.

    I'm dumb, I stayed up too long, programmers need sleep too I guess.

    Thanks for your help πŸ™‚

    it works again πŸ™‚