Hi!
I’m trying to make an extension that will handle repeated actions.
I want it to trap the successful actions only, and having the option to bypass certain actions defined in an external routine.
I’m thinking I’ve overcomplicated this… if anyone has any other suggestions I would be happy to hear it.
This is what I’ve gotten so far… but it doesn’t stop correctly when there’s a failed action;
Please help!
! TODO : Make it so that it won't reset the repetition variable when a failed new command is parsed.
Global SUCCESSFUL_ACTION = false;
[DontResetRepetitionWhen;
Examine,Look,Wait: rtrue;
default: rfalse;
];
Object History
with
lastActor 0,
lastAction 0,
lastNoun 0,
lastSecond 0,
repetitions 0,
found_in[; rtrue; ],
react_before[;
if(self has general)
{
give self ~general;
!print "^ The last command had a successful result.";
if (actor == self.lastActor
&& action == self.lastAction
&& noun == self.lastNoun
&& second == self.lastSecond)
{
self.repetitions++;
!print " same command -- increase repetitions: ", self.repetitions, "^";
}
else
{
#IfDef DontResetRepetitionWhen;
if(DontResetRepetitionWhen())
{
!print "not the same command, but an exception -- no reset.";
rfalse;
}
#EndIf;
give self switchable;
}
}
],
each_turn[;
!print "history.each_turn()";
if(SUCCESSFUL_ACTION)
{
if (actor == self.lastActor
&& action == self.lastAction
&& noun == self.lastNoun
&& second == self.lastSecond)
{
!print "same as before";
give self general;
rfalse;
}
!print "New successful command ";
if(self has switchable)
{
give self ~switchable;
self.repetitions = 0;
!print " -- reset repetitions: ", self.repetitions, "^";
rfalse;
}
!print " -- working all the way!";
give self general;
self.lastActor = actor;
self.lastAction = action;
self.lastNoun = noun;
self.lastSecond = second;
}
else
{
!print "New failed command ";
give self ~general;
rfalse;
}
SUCCESSFUL_ACTION = false;
],
has scenery;