UNDO Revisited [Solved]
DavyB
25 Apr 2023, 21:05In discussion with mrangel a few years ago we seem to have 'fixed' known problems with the UNDO operation:
http://textadventures.co.uk/forum/quest/topic/gxxws68qyko6hqwkf9q2ua/unexpected-undo-problem-resolved-again
In a recent case, however, there was a minor issue in undoing room changes where the background colours were different. Here is simple example. The problem is the background colour of the command box is out of step with room changes. Any suggestions for a fix?
<!--Saved by Quest 5.8.6836.13983-->
<asl version="580">
<include ref="English.aslx" />
<include ref="Core.aslx" />
<game name="Undo Background Colours">
<gameid>019c9494-8107-4d61-8e8a-993c91c41621</gameid>
<version>1.0</version>
<firstpublished>2023</firstpublished>
<feature_advancedscripts />
<inituserinterface type="script">
game.restored = GetBoolean (game, "hasacted")
game.hasacted = false
</inituserinterface>
</game>
<turnscript name="clean_up">
<enabled />
<script>
game.hasacted = true
</script>
</turnscript>
<command name="new_undo">
<pattern>undo</pattern>
<isundo />
<script>
game.suppressturnscripts = true
if (not GetBoolean (game, "hasacted")) {
msg ("There is nothing to undo!")
}
else {
undo
game.suppressturnscripts = true
// Restore background colour if necessary
SetBackgroundColour (game.defaultbackground)
JS.updateLocation (CapFirst(GetDisplayName(game.pov.parent)))
}
</script>
</command>
<object name="Blue Room">
<inherit name="editor_room" />
<isroom />
<beforeenter type="script">
SetBackgroundColour ("LightBlue")
</beforeenter>
<object name="player">
<inherit name="editor_object" />
<inherit name="editor_player" />
</object>
<exit alias="south" to="Green Room">
<inherit name="southdirection" />
</exit>
</object>
<object name="Green Room">
<inherit name="editor_room" />
<beforeenter type="script">
SetBackgroundColour ("LightGreen")
</beforeenter>
<exit alias="north" to="Blue Room">
<inherit name="northdirection" />
</exit>
</object>
</asl>
DavyB
27 Apr 2023, 09:27I see that one workaround is to insert msg ("")
after the undo, though that creates an undesirable line feed. Still, it's a step in the right direction.
...displaying the room description after an undo is another possibility! (ShowRoomDescription ()
)
...actually using both together works well, as it is useful to confirm the effect of an undo. Solved!
mrangel
27 Apr 2023, 19:57When you call
msg ("")
the system redirects that down to:OutputText ("")
which calls:OutputTextRaw (ProcessText (""))
which passes your processed text toJS.addText
and then calls the function:ResetCommandBarFormat ()
Which simply does:
JS.setCommandBarStyle(GetCurrentTextFormat("") + ";background:" + game.defaultbackground)
to make sure that the command bar has the correct style for the current attributes.
So you might be able to just call ResetCommandBarFormat ()
after your undo.
DavyB
28 Apr 2023, 10:35That works! Thanks mrangel, that is just what I was looking for.