replaceActorAction and custom code clash

Please bear with me, this one’s difficult to explain since it involves a bunch of custom code.

Years ago, I asked for help making a StopEventList that would throw up one list of results if a specific property was true and another list if it was false. The code ended up looking like this:

modify StopEventList
    altList = []
    getAltState() 
   {
      return altScriptState;
   }
   advanceAltState() 
    {
      if (altScriptState < altList.length())
         ++altScriptState;
    }
   altScriptState = 1
   altDone() 
    {
      advanceAltState();
    }
   doScript() 
    {
      local idx, lst, done;
      if (check()) 
        {
         idx = getScriptState();
         lst = eventList;
         done = &scriptDone;
        }
      else 
        {
         idx = getAltState();
         lst = altList;
         done = &altDone;
        }
      if (idx >= 1 && idx <= lst.length()) {
         doScriptEvent(lst[idx]);
      }
      done();
   } 
   check() 
   {
      return true;
   }
;

Short version: If Check() returns true, the list works as usual. If it’s nil, the altList gets printed.

LATER on, I further complicated things by having the check() result be dependant on whether the list triggers several times in a row or not:

Short version: The standard list gets printed the first time the ResettingStopEventList is triggered. If the player keeps triggering the list, then the altList gets printed instead. If they do ANYTHING ELSE and then later trigger the list again, the standard list gets printed, and then the altList every successive time, and so on and so forth.

This worked. Except now I ran into a problem. This is a sample situation of the issue:

testRoom: Room 'Test Room'
    ""
;

nail: Thing 'nail' 'nail' @testRoom
    "It's a nail."
    dobjFor(Attack)
    {
        action()
        {
            nailHitting.doScript();
        }
    }
;

nailHitting: ResettingStopEventList
    [
        {: "The nail is hit. "}
    ]
    altList =
    [
        {:"Still hitting that nail. "}
    ]
;

There’s a nail, which I can hit. Hitting the nail fires the nailHitting list, which will behave as explained above: first time I hit it, the “The nail is hit” message is displayed. If I keep doing it, the “Still hitting the nail” message gets displayed. If I stop and go do anything else, then hit the nail again, the “The nail is hit” message is displayed and so on and so forth.

So far so good. But there’s also a robot, and I can tell it to hit the nail. No problem: it triggers the list just fine and the behaviour is as expected.

workerDrone: Actor 'worker/drone/robot' 'worker' @testRoom
    "A robot. Has a button. "
    obeyCommand(issuingActor, action)
    {
        if(action.ofKind(AttackAction))
            return true;
        return inherited(issuingActor, action);
    }
;

But HERE’S the problem: the robot has a button, and when I press the button, I want it to react exactly the same as when I told it to hit the nail.

workerDrone: Actor 'worker/drone/robot' 'worker' @testRoom
    "A robot. Has a button. "
    obeyCommand(issuingActor, action)
    {
        if(action.ofKind(AttackAction))
            return true;
        return inherited(issuingActor, action);
    }
;

+ button: Button, Component 'red button' 'button'
    dobjFor(Push)
    {      
        action()
        {
            replaceActorAction(location, Attack, nail);
        }
    }
;

Except it doesn’t. It’d be quicker if you just ran the code yourself to check how it fails, but here’s some problems that happen:

-If I press the button, the “Still hitting the nail” message is printed every time. No matter if I do something else and then try again. It only prints that.
-If I’m hitting the nail myself (successively getting “Still hitting the nail” as intended) or telling it to hit the nail (same result), THEN press the button, for some reason it returns the “The nail is hit” message the first time. Then keeps displaying “Still hitting the nail” every time after that (and never again anything else) as I mentioned above.
-Most bizarrely, if I press the button, THEN tell the robot to hit the nail, I get a “The worker is busy” message every time. “Robot, hit nail” ends up never working again after that.

If I had to guess, I suppose that it’s something having to do with triggering the ResettingStopEventList from the button’s replaceActorAction, but I’ve got no clue what’s happening or how to fix it. Ultimately, all I want is for the ResettingStopEvent list to behave as if all three ways of triggering were indistinguishable.

If you’re using Workbench, I think this is a case where using the Debug commands (F10, etc., in the menu) might be your best bet. That’s what I would have to do. If you’re compiling on the Mac without using Workbench, I’m not sure what to suggest.