elevatorsaga icon indicating copy to clipboard operation
elevatorsaga copied to clipboard

Allow users to re-enter elevator that changes indicators without moving.

Open apottere opened this issue 10 years ago • 11 comments

See https://github.com/magwo/elevatorsaga/issues/59

apottere avatar Feb 07 '15 05:02 apottere

I'm afraid this probably can't be done like this.. I think this will cause "sliding users", meaning passengers that are entering the elevator just as it starts moving, making them fly into the elevator between floors sort of. This should be done like the re-arrival behaviour - queueing the floor another time. It's a little messy.

magwo avatar Feb 07 '15 18:02 magwo

Then it sounds like this pull request can be fixed by changing

elevator.trigger("entrance_available");

to

elevator.goToFloor(elevator.currentFloor(), true);

But I think before that line, you must either wrap elevator with asElevatorInterface, or fetch that same elevator from world.elevatorInterfaces, so that goToFloor can be used.

roryokane avatar Feb 07 '15 22:02 roryokane

Yes, basically. I'm thinking of moving the queue logic into the elevator object so that this type of thing can be done without involving the interface object. What do you think about that?

magwo avatar Feb 07 '15 23:02 magwo

Hmm, well, in both uses of the interface in world.js, we don’t need the whole queue logic, just a command to “wait on the current floor until all passengers have entered”. The current way of doing that is putting the current floor at the front of the queue. There might be a cleaner way of doing that, but I can’t think of it.

So yes, moving the queue logic to the elevator object is better than the current organization. It might not be the best design overall, but I can’t think of a better design right now.

roryokane avatar Feb 07 '15 23:02 roryokane

Agree.

magwo avatar Feb 08 '15 00:02 magwo

I did try re-queueing it like it's done below, but that's causes an issue where elevators changing their indicators after they've already been told to goToFloor has passengers load, but they never go to the next floor.

apottere avatar Feb 08 '15 02:02 apottere

@apottere Are you calling goToFloor on the elevator interface, defined in interfaces.js? It sounds like you might be calling goToFloor on the unwrapped elevator, defined in elevator.js, which ignores the queue logic. As I said, you have to “wrap elevator with asElevatorInterface, or fetch that same elevator from world.elevatorInterfaces”.

roryokane avatar Feb 08 '15 10:02 roryokane

I was calling it on the interface, like a few lines below:

world.elevatorInterfaces[elevIndex].goToFloor(floor.level, true);

That would cancel the call I made in my game script, which was essentially:

elevator.goingDownIndicator(true);
elevator.goToFloor(floor);

apottere avatar Feb 08 '15 13:02 apottere

I updated to use the interface - I'm not sure what I thought was broken last time I tried that, but I'm certainly not seeing it now. With that change, the code below works on challenge #1, and the goToFloor call doesn't get canceled:

{
    init: function(elevators, floors) {
        var elevator = elevators[0];
        var floor = floors[0];

        elevator.goingDownIndicator(false);
        elevator.goingUpIndicator(false);

        floor.on('up_button_pressed', function() {
            elevator.goingUpIndicator(true);
            elevator.goToFloor(2);
        });

    },
    update: function() {}
}

apottere avatar Feb 12 '15 16:02 apottere

This has come up in our play of the game. Hope it gets fixed!

jcoveney avatar Feb 13 '15 16:02 jcoveney

Any updates on this?

Rybadour avatar Sep 12 '16 01:09 Rybadour