Overriding the UNDO command?

This forum is the place to learn about and discuss ADRIFT 5. Feel free to mention any bugs you find here, but please also add these to the Bugs & Enhancements list.

Please also refer to the ADRIFT 5 Wiki for more information.
Post Reply
User avatar
P/o Prune
Site Admin
Posts: 4960
Joined: Mon Jun 24, 2002 9:18 am
Points: 168
Location: Denmark

Overriding the UNDO command?

Post by P/o Prune »

Apparently using the Undo command in a game where an event is currently running (active) will mess up the event.
Rather than having to warn the player against using this command I wonder if there is a way to override it.
I don't know if it is hardcoded into the developer / runner. I have tried to search for it but without success.
Suggestions?
D-Day in progress 86Kb (Slowly drifting)
October 31st: 135Kb (My entry for the parser Comp 2022 :wink: )
User avatar
Lazzah
Moderator
Posts: 2524
Joined: Thu Mar 31, 2011 5:54 am
Points: 100
Location: Clacton-on-Sea, Essex
Contact:

Re: Overriding the UNDO command?

Post by Lazzah »

In this situation you would want to only disable the UNDO command after the player has been "killed". It is easy enough to create a task that disables UNDO but this doesn't work when you want it to!

The issue has been reported on the bugs page: https://www.adrift.co/bug/19196, but any chance of it being resolved by Campbell are practically zero. We also seem to have lost saabie, who was our great hope for the continued development of ADRIFT. :(

Maybe one of the ADRIFT boffins can figure out a way of getting around this, as suggested in the bug report?
Visit "Larry's ADRIFT Text Adventures" at http://LarrysAdriftTextAdventures.co.uk
User avatar
Denk
Posts: 1003
Joined: Mon Feb 22, 2016 6:21 pm
Points: 346
Location: Hjørring, Denmark

Re: Overriding the UNDO command?

Post by Denk »

First, there are many situations UNDO does not break events and walks, but it is of course problematic that it sometimes does.

You can have restrictions that make sure, that you only override UNDO in critical situations. See attached .taf file:

Override Undo.taf
(28.72 KiB) Downloaded 5 times

If I understand Lazzah correctly, it is mainly a problem when you "end game in defeat", because ADRIFT will then ask "*** You have lost *** Would you like to restart, restore, quit or undo?" and you cannot avoid it if the player then types UNDO.

To avoid this problem, you can make a "fake" ending, by moving the player to a location, which behaves as if you had just ended the game in defeat, e.g. by saying "*** You have lost *** Would you like to restart, restore or quit?". In this location, you could override UNDO.
----------------------------------------------------------------------
The Bash Saga:
1. The Dragon Diamond 2. The Way Home 3. Stone of Wisdom
----------------------------------------------------------------------
User avatar
Lazzah
Moderator
Posts: 2524
Joined: Thu Mar 31, 2011 5:54 am
Points: 100
Location: Clacton-on-Sea, Essex
Contact:

Re: Overriding the UNDO command?

Post by Lazzah »

Denk wrote: Fri Jul 23, 2021 11:36 am If I understand Lazzah correctly, it is mainly a problem when you "end game in defeat", because ADRIFT will then ask "*** You have lost *** Would you like to restart, restore, quit or undo?" and you cannot avoid it if the player then types UNDO.

To avoid this problem, you can make a "fake" ending, by moving the player to a location, which behaves as if you had just ended the game in defeat, e.g. by saying "*** You have lost *** Would you like to restart, restore or quit?". In this location, you could override UNDO.
Thanks, Denk, that's a great idea. You would only need this fake location when the game ends in defeat in the situations where there is an event that gets broken.
Visit "Larry's ADRIFT Text Adventures" at http://LarrysAdriftTextAdventures.co.uk
David Whyld
Posts: 7065
Joined: Sat Dec 18, 2004 5:15 pm
Points: 35
Location: United Kingdom

Re: Overriding the UNDO command?

Post by David Whyld »

Aren't you just going to annoy players by killing them off then disabling the undo command? No one is going to thank you for doing that kind of thing.
User avatar
Denk
Posts: 1003
Joined: Mon Feb 22, 2016 6:21 pm
Points: 346
Location: Hjørring, Denmark

Re: Overriding the UNDO command?

Post by Denk »

David Whyld wrote: Fri Jul 23, 2021 2:35 pm Aren't you just going to annoy players by killing them off then disabling the undo command? No one is going to thank you for doing that kind of thing.
Here, the purpose is only to disable "undo" in situations where "undo" breaks the game anyway. For instance by saying something like: "Due to a bug in ADRIFT, undo is disabled in this specific situation." (something like that)
----------------------------------------------------------------------
The Bash Saga:
1. The Dragon Diamond 2. The Way Home 3. Stone of Wisdom
----------------------------------------------------------------------
User avatar
Lumin
Posts: 2378
Joined: Fri Aug 06, 2004 6:48 pm
Points: 59

Re: Overriding the UNDO command?

Post by Lumin »

Haven't been able to look at Denk's demo yet, but in Skybreak there's an iron man mode you can enable at any time, so it at least can be done.

I'll let Theo know about this thread to see what method he used.
ralphmerridew
Posts: 2626
Joined: Fri Dec 13, 2002 11:56 pm
Points: 10
Location: Missouri
Contact:

Re: Overriding the UNDO command?

Post by ralphmerridew »

Anybody got a demo that reproduces the bug?
Bloodhounds can make you laugh and cuss in the same breath. They are endearing, faithful, and can sling drool ten feet in any direction. -- Virginia Lanier
User avatar
P/o Prune
Site Admin
Posts: 4960
Joined: Mon Jun 24, 2002 9:18 am
Points: 168
Location: Denmark

Re: Overriding the UNDO command?

Post by P/o Prune »

ralphmerridew wrote: Sat Jul 24, 2021 3:47 am Anybody got a demo that reproduces the bug?
I was testing Lazzah's latest game when I ended up dead. I made a UNDO and found that the event that was supposed to run had been messed up. That's the reason I posted this. I wasn't aware that it was only under certain condition this error occurs.
D-Day in progress 86Kb (Slowly drifting)
October 31st: 135Kb (My entry for the parser Comp 2022 :wink: )
User avatar
Denk
Posts: 1003
Joined: Mon Feb 22, 2016 6:21 pm
Points: 346
Location: Hjørring, Denmark

Re: Overriding the UNDO command?

Post by Denk »

I have made a demo, which demonstrates how ending the game with the action "End game in defeat/victory/without a fuss" can break walks and events if you undo. (I will attach the file to this post soon, from my phone)
UndoBreaksEventsAndWalks.taf
(32.21 KiB) Downloaded 8 times
Here is a transcript with comments:

Code: Select all

> restart   [FIRST ATTEMPT: The action "End game in defeat" breaks walks and events if you undo]
r2
Try to stay in location r2 and type WAIT (or Z) several times. You will see John walking in and out of location r2.

If you now type TEST, you will be game over. Try then to type UNDO. The game continues but John has stopped moving and an event has started running (counting from zero to five).

Note that the task TEST was set to stop the walk and start an event. Still, typing UNDO should bring the game back to the state it was in, before typing TEST. It doesn't, so UNDO breaks the game. It only seems to happen when changes are made to walks and events about the same time the action "End game in defeat/victory/without a fuss" is applied.

As far as I remember, I have tried breaking a walk or event without ending the game, but I am not sure. But is seems as if we can often avoid the problem by making a "fake" game over screen instead of applying an "end game"-action.

Thus try the commands FAKE (fakes an ending - can be improved) and START (starts the event so you can test FAKE and TEST when it is running).

John is here.  Exits are east and west.  John exits to the east.  

> x me
You see nothing interesting about yourself.  John enters from the east.

> i
You are wearing nothing, and are carrying nothing.  John exits to the east.

> x me
You see nothing interesting about yourself.  John enters from the east.

> test
Test activated.

*** You have lost ***
Would you like to restart, restore a saved game, quit or undo the last command?

> undo
Undone.  You see nothing interesting about yourself.  John enters from the east.  

> x me
You see nothing interesting about yourself.  Zero turns   [John has stopped walking around and an event is now running]

> x me
You see nothing interesting about yourself.  One turn [John still not walking, an event keeps running (turns counted)]

> restart   {SECOND ATTEMPT: Will apply fake ending - no problems occur]
r2
Try to stay in location r2 and type WAIT (or Z) several times. You will see John walking in and out of location r2.

If you now type TEST, you will be game over. Try then to type UNDO. The game continues but John has stopped moving and an event has started running (counting from zero to five).

Note that the task TEST was set to stop the walk and start an event. Still, typing UNDO should bring the game back to the state it was in, before typing TEST. It doesn't, so UNDO breaks the game. It only seems to happen when changes are made to walks and events about the same time the action "End game in defeat/victory/without a fuss" is applied.

As far as I remember, I have tried breaking a walk or event without ending the game, but I am not sure. But is seems as if we can often avoid the problem by making a "fake" game over screen instead of applying an "end game"-action.

Thus try the commands FAKE (fakes an ending - can be improved) and START (starts the event so you can test FAKE and TEST when it is running).

John is here.  Exits are east and west.  John exits to the east.  

> start    [I will start event, to show how the event reacts to the fake ending]
Start event.  John enters from the east.  Zero turns

> x me
You see nothing interesting about yourself.  John exits to the east.  One turn

> i
You are wearing nothing, and are carrying nothing.  John enters from the east.  Two turns

> x me
You see nothing interesting about yourself.  John exits to the west.  Three turns

> fake
Fake activated.

*** You have lost ***
Would you like to restart, restore a saved game, quit or undo the last command?

> undo
Undone.  You see nothing interesting about yourself.  John exits to the west.  Three turns

> i
You are wearing nothing, and are carrying nothing.  John enters from the west.  Four turns   [John keeps moving, event keeps running]

> x me
You see nothing interesting about yourself.  John exits to the west.  Five turns - quit.   [John keeps moving, event keeps running]

As you can see, the problem only occurs with the action "End game in defeat/victory/without fuss", not the fake ending. It may be possible to break walks and events without using an action to end the game, but it is apparently harder. So we can get rid of many of the problems by applying fake endings it seems.
----------------------------------------------------------------------
The Bash Saga:
1. The Dragon Diamond 2. The Way Home 3. Stone of Wisdom
----------------------------------------------------------------------
ralphmerridew
Posts: 2626
Joined: Fri Dec 13, 2002 11:56 pm
Points: 10
Location: Missouri
Contact:

Re: Overriding the UNDO command?

Post by ralphmerridew »

Thanks for the minimal test case. It made tracking down the issue pretty straightforward.

The issue isn't limited to UNDO.

For example, if I did "SAVE, Z, Z, Z, TEST, RESTORE, Z, Z", then the bug triggered.

Issue appears to be a matter of the "NextCommand" property of Events and Walks. The value is not supposed to persist between turns, so it's not set/restored as part of SAVE/RESTORE/UNDO. Ordinarily it is cleared after the event starts. However, because the game ended, Runner skips the part of the turn which would clear it. So the NextCommand remains at "Start" when the player types "Z", and the event gets started.

Possible fixes:
1) Clear NextCommand at extra points. (After a game over, or right before processing a command.)
2) Make NextCommand so it is affected by SAVE/RESTORE/UNDO.

Deeper explanation available on request.
Bloodhounds can make you laugh and cuss in the same breath. They are endearing, faithful, and can sling drool ten feet in any direction. -- Virginia Lanier
User avatar
Denk
Posts: 1003
Joined: Mon Feb 22, 2016 6:21 pm
Points: 346
Location: Hjørring, Denmark

Re: Overriding the UNDO command?

Post by Denk »

ralphmerridew wrote: Sat Jul 24, 2021 9:07 pm The issue isn't limited to UNDO.

For example, if I did "SAVE, Z, Z, Z, TEST, RESTORE, Z, Z", then the bug triggered.
Yes, I see. Luckily, the "fake" ending also avoids the problem with SAVE/RESTORE, not just UNDO.
ralphmerridew wrote: Sat Jul 24, 2021 9:07 pm Issue appears to be a matter of the "NextCommand" property of Events and Walks. The value is not supposed to persist between turns, so it's not set/restored as part of SAVE/RESTORE/UNDO. Ordinarily it is cleared after the event starts. However, because the game ended, Runner skips the part of the turn which would clear it. So the NextCommand remains at "Start" when the player types "Z", and the event gets started.

Possible fixes:
1) Clear NextCommand at extra points. (After a game over, or right before processing a command.)
2) Make NextCommand so it is affected by SAVE/RESTORE/UNDO.

Deeper explanation available on request.
Thanks. I guess only Campbell can use this information to fix the bug, but hopefully, your effort will make it easier for Campbell to fix the bug. Oh, and perhaps the alternative "Runner" authors (Ardi on Frankendrift and Tim Cowper on Fabularium) may make their own fix instead of waiting for Campbell.

Until then, the bugs in the demo can be avoided with a "fake" ending.
----------------------------------------------------------------------
The Bash Saga:
1. The Dragon Diamond 2. The Way Home 3. Stone of Wisdom
----------------------------------------------------------------------
ardi
Posts: 16
Joined: Mon May 10, 2021 4:23 pm
Points: 10
Location: Germany

Re: Overriding the UNDO command?

Post by ardi »

Denk wrote: Sat Jul 24, 2021 9:59 pm Oh, and perhaps the alternative "Runner" authors (Ardi on Frankendrift and Tim Cowper on Fabularium) may make their own fix instead of waiting for Campbell.
My intention was to keep the original code intact as much as possible, for better or for worse. I don't think I would be comfortable making incompatible changes as long as ADRIFT is still (nominally) maintained.

(Not to mention that I don't really have a good understanding of what the code does "under the hood" -- as I said, I try to stay away from the logic parts as much as possible.)
User avatar
Denk
Posts: 1003
Joined: Mon Feb 22, 2016 6:21 pm
Points: 346
Location: Hjørring, Denmark

Re: Overriding the UNDO command?

Post by Denk »

ardi wrote: Sun Jul 25, 2021 6:08 pmMy intention was to keep the original code intact as much as possible, for better or for worse. I don't think I would be comfortable making incompatible changes as long as ADRIFT is still (nominally) maintained.
Makes sense. Even the very first version of Frankendrift I tried, gave all the right responses. I suppose because it is basically the same code.

It was kind of the opposite with Fabularium. In the beginning, many responses were different than the ADRIFT Runner. There were a lot of bug fixes in the beginning, probably because the developer manually converted the code to (I think) Javascript (or something). It hasn't been updated for a very long time, but I think the end result is pretty good, even though you get a wrong response once in a while. So I always test my games with Fabularium. So far, if Fabularium gives a wrong response, I have managed to find a workaround.
----------------------------------------------------------------------
The Bash Saga:
1. The Dragon Diamond 2. The Way Home 3. Stone of Wisdom
----------------------------------------------------------------------
User avatar
Denk
Posts: 1003
Joined: Mon Feb 22, 2016 6:21 pm
Points: 346
Location: Hjørring, Denmark

Re: Overriding the UNDO command?

Post by Denk »

I think this thread needed a summary, as we found out something along the way:

* The original question was if we can disable undo as it sometimes breaks walks and events.
CONCLUSION:
1. You don't have to. If you replace an end-game action (e.g. End game in defeat) with a "fake" ending, undo will not break the game. The bug only occurs in connection with the end-game actions (as far as I know).
2. Save/restore gives the same problem and can also be avoided with fake endings.
3. Ralphmerridew found the bug in the code, which explains why.

If you don't know how to apply a fake ending, you may like the "fake ending module", which can be imported: https://forum.adrift.co/viewtopic.php?f=14&t=12921
----------------------------------------------------------------------
The Bash Saga:
1. The Dragon Diamond 2. The Way Home 3. Stone of Wisdom
----------------------------------------------------------------------
Post Reply