I6: Keeping track of repeated actions

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;

Don’t you need to send a value to DontResetRepetitionsWhen()? Something (untested) like this:

[DontResetRepetitionsWhen r; switch (r) { Examine, Look, Wait: rtrue; default: rfalse; } ];

Maybe I’m not following the logic of what you’re trying to do, but it looks to me as if your function is always going to return the same value … it’s never going to test anything.

[DontResetRepetitionsWhen;
          Examine, Look, Wait: rtrue;
          default: rfalse;
];

Even though this routine is the least of my worries it will test the current action. It’s the same thing as seen in a before or after-routine.

Someone was kind enough to show me an alternative solution which just works flawless. So I’m not in need of any help on this matter anymore.