I extracted the necessary Glulx code from Hypothetical Questions, removing the output buffering. Now I have the best of both:
[spoiler][code]Version 1 of Hypothetical Object Response Tests by Mike Ciul begins here.
“Tests objects just like Juhana Leinonen’s extension, but does an UNDO after each test.”
Include Object Response Tests by Juhana Leinonen
Book 1 - Triggering Undo From I7
save-restore status is a kind of value. failure to save, successful save, and successful restore are save-restore statuses.
To decide which save-restore status is result of saving undo state: (- Save_Undo_State() -).
To decide whether successfully saved undo state: Decide on whether or not the result of saving undo state is successful save.
To restore undo state: (- Restore_Undo_State(); -).
Include (-
Constant FAILURE_TO_SAVE = 1;
Constant SUCCESSFUL_SAVE = 2;
Constant SUCCESSFUL_RESTORE = 3;
! returns 1 when entering the hypothetical universe, 2 when returning to reality, 0 if entering failed in the first place
[
Save_Undo_State rv;
! Not sure if any of these settings are necessary…
! do { @random 0 seed; } until (seed ~= 0);
!@getstringtbl strtbl;
! @getiosys iosys iorock;
@saveundo rv;
!@setrandom seed;
!@setstringtbl strtbl;
!@setiosys iosys iorock;
switch (rv) {
0: return SUCCESSFUL_SAVE;
1: print "[This game requires an interpreter with undo support.]^"; return FAILURE_TO_SAVE;
-1: return SUCCESSFUL_RESTORE;
}
];
! consider a rule, protect its result, and restore the state saved by Hypo_Start
[ Restore_Undo_State rv;
@restoreundo rv; ! never returns if successful
print “[What happened to my undo state? --hypo]^”;
];
-)
Book 3 - Actions - Not for release (in place of Book 3 - Actions - Not for release in Object Response Tests by Juhana Leinonen)
Object-analyzing is an action applying to one visible thing.
Understand “analyze [something]” as object-analyzing.
Understand “analyse [something]” as object-analyzing.
Carry out object-analyzing (this is the go through all analyzing rules rule):
repeat with x running from 1 to the number of rows in the table of analyzing actions:
if successfully saved undo state:
follow the testing rule in row x of the table of analyzing actions;
restore undo state;
[if the result of saving undo state is:
-- successful save: follow the testing rule in row x of the table of analyzing actions;
-- successful restore: next;
-- failure to save: stop the action;]
All-encompassing analyzing is an action applying to nothing.
Carry out all-encompassing analyzing (this is the analyze everything in the location rule):
repeat with x running through things enclosed by the location of the test-actor:
if the test-actor can see x:
try object-analyzing x.
Understand “analyze all” as all-encompassing analyzing.
Test-verb-trying is an action applying to one topic.
Understand “try [text]” as test-verb-trying.
Check test-verb-trying (this is the unknown verb test label rule):
if the topic understood is not a topic listed in the Table of analyzing actions:
say “Unknown verb test.” instead.
Carry out test-verb-trying (this is the repeat an action with all objects rule):
if the topic understood is a topic listed in the Table of analyzing actions:
repeat with x running through things enclosed by the location of the test-actor:
if the test-actor can see x:
change the noun to x;
if successfully saved undo state:
follow the testing rule entry;
restore undo state;
Test-actor changing is an action out of world applying to one visible thing.
Understand “actor is [any person]” as test-actor changing.
Carry out test-actor changing (this is the change testing actor rule):
change test-actor to the noun;
say “Object Response Tests now uses [the noun] as the actor.”
Hypothetical Object Response Tests ends here.[/code][/spoiler]
I think I’ll create some mode settings to allow the player to choose between ORT’s default behavior, undo for individual action tests, and undo for entire tests. Any suggestions for naming the commands?
Maybe:
autoundo off
autoundo actions
autoundo turns