nroutasuo / level13

Incremental browser text adventure
Apache License 2.0
213 stars 71 forks source link

[JS Error] TypeError: Cannot read properties of undefined (reading 'get') #282

Open davidarcher opened 1 year ago

davidarcher commented 1 year ago

Details: Tried turning on autoplay on a fairly new game (one camp, 4 followers, very little explored).

Seed: 7361 Position: 13.0.0 (inCamp: false) Stacktrace: TypeError: Cannot read properties of undefined (reading 'get') at constructor.move (https://nroutasuo.github.io/level13/src/game/systems/AutoPlaySystem.js?v=0.5.1:291:43) at constructor.updateExploring (https://nroutasuo.github.io/level13/src/game/systems/AutoPlaySystem.js?v=0.5.1:159:41) at constructor.update (https://nroutasuo.github.io/level13/src/game/systems/AutoPlaySystem.js?v=0.5.1:111:41) at constructor.update (https://nroutasuo.github.io/level13/lib/ash/ash.min.js?v=0.5.1:14:15165) at constructor.update (https://nroutasuo.github.io/level13/src/game/systems/GameManager.js?v=0.5.1:103:16) at r.execute (https://nroutasuo.github.io/level13/lib/ash/ash.min.js?v=0.5.1:14:4611) at n.Signal.dispatch (https://nroutasuo.github.io/level13/lib/ash/ash.min.js?v=0.5.1:14:6738) at constructor.tick (https://nroutasuo.github.io/level13/lib/brejep/tickprovider.js?v=0.5.1:48:29)

The function where the error originates has a guard clause that looks suspect. It checks to make sure directions is non-null but doesn't check if directions.sector is non-null.

in AutoPlaySystem.js:

move: function () {
    var autoPlayComponent = this.autoPlayNodes.head.autoPlay;
    let directions = GameGlobals.autoPlayHelper.getMoveSector(autoPlayComponent.explorationVO);

    if (!directions || directions.sector)
        return false;

    var playerPosition = GameGlobals.playerActionFunctions.playerPositionNodes.head.position;
    var sectorPosition = directions.sector.get(PositionComponent);
    if (playerPosition.level !== sectorPosition.level || playerPosition.sectorId() !== sectorPosition.sectorId()) {
        this.logStep("move to " + sectorPosition + " (" + directions.type + ")");
        GameGlobals.playerHelper.moveTo(sectorPosition.level, sectorPosition.sectorX, sectorPosition.sectorY, false);
        return true;
    }

    return false;
},
nroutasuo commented 1 year ago

Thanks for the report. AutoPlay is an old testing tool that I haven't updated in awhile, not surprised it doesn't work. How did you even turn it on live?

davidarcher commented 1 year ago

How did you even turn it on live?

Breakpoint in chrome dev tools to override the config.js values at startup:

config.isCheatsEnabled = config.isDebugOutputEnabled = config.isDebugVersion = true

Then console commands to activate autoplay:

window.app.cheat("scavenge") window.app.cheat("autoplay camp 2")

nroutasuo commented 1 year ago

Thank you. I might try to close that loophole one day but for the time being, use at your own risk :)