Room.serializePath returning string with undefined



  • Re: FR: Fix Room.deserializePath()

    I am having the same issue as someone posted 5 years ago, where Room.serializePath() doesn't return the numbers that represent directions properly. Here's a screenshot. 0_1617527896290_8c70bc02-e6ed-453c-9b15-f654e7664e4f-image.png Is this function supposed to be used like this? Or we should write our own?



  • Room.serializePath() accepts the format that Room.findPath() returns, not that PathFinder.search() returns (aka, you can't use an array of roomPositions)

    findPath returns: [ { x: 10, y: 5, dx: 1, dy: 0, direction: RIGHT }, { x: 10, y: 6, dx: 0, dy: 1, direction: BOTTOM }, { x: 9, y: 7, dx: -1, dy: 1, direction: BOTTOM_LEFT }, ... ]

    ^ That is the only format that serializePath will accept. It is quite possible to transform an array of roomPositions into that format, you can see the engine code: https://github.com/screeps/engine/blob/master/src/game/rooms.js#L279 to see how it does it.



  • This post is deleted!


  • @donatzor Oh, thank you very much for pointing this out!

    Looks like the document is not updated then.

    BTW the doc says that Room.serializePath() uses Jump Point Search and PathFinder.search() uses A* written in C++, which is claimed to be faster. Is it real or is it not updated as well?



  • Some one else who was around at the time / is more knowledgeable may want to clarify, but I believe it is a modified JPS by The General. Screeps use to have it optional to use, but its by default now, everything uses PathFinder.search() in some capacity in the background. SerializePath should have it noted in the param it accepts that its findPath, :

    path	array	
    A path array retrieved from Room.findPath.
    
    

    though, could reccomend a diff way / updates via pull requests on the github docs: https://github.com/screeps/docs



  • Oops, I was looking at the parameter description for moveByPath the whole time:

    "A path value as returned from Room.findPath, RoomPosition.findPathTo, or PathFinder.search methods. Both array form and serialized string form are accepted."

    Sorry if I confused anyone.