Prevent switch reset with Thing_Activate until specified?

Fri Sep 17, 2021 1:03 pm

(mostly ZScript related, so not in mapping section)

Uhh, this one is a little hard to explain. The super simple version is that I have a linedef calling Thing_Activate which kicks a ZScript based object to do some stuff. But I can immediately re-activate the switch upon doing that, which I have to check for in the activate function of the object, and also the switch texture toggles each time you press it, and it's a bit of a mess.

So my question is: Is it possible to make something behave more akin to ACS_Execute in that the switch "sticks" until the script is finished? Or in my case, until some condition is met, or even manually by way of manipulating the linedef's flags in ZScript, etc...

I'm not sure what, if any, solution there might be. Would be nice to be able to do it all in pure ZScript... I suppose since I have already done some source mods to my project I could create a custom line special for this, but I would really rather avoid doing stuff like that if I can help it.

Best I've gotten so far is assigning the line a tag and resetting that line's special to Thing_Activate once I need it restored (internally a non-repeatable line just wipes its own special when activated). That could be a workable solution, but it would be really nice to be able to automatically get a reference to the line whose special activated the object. I don't know if that's remotely possible though. Maybe something via the player...?

Re: Prevent switch reset with Thing_Activate until specified

Fri Sep 17, 2021 2:16 pm

If the script is being run by ACS_Execute (line type 80) then it can only have one instance running. So, if you know how long your actor takes to do its stuff, you can put a delay into the script at the end so that it lasts as long as the thing is doing whatever it does. The switch will return to its ready appearance in the usual short reset time, but you won't actually be able to use it until the delay in the script has elapsed.

Is that of any use?

Also, there are several wait functions in ACS. Would any of them be of use to you?

https://zdoom.org/wiki/Category:ACS_Wait_functions

Re: Prevent switch reset with Thing_Activate until specified

Fri Sep 17, 2021 2:32 pm

Yeah, I know about the ACS wait and delay things, it's just I was calling thing_activate directly from a linedef rather than an ACS script. If neccessary I guess I could make some ACS glue logic, do something with ScriptCall to keep an eye on an actor's status and run a 1-tic delay in a while loop until the actor's done. That would work, although I guess it'd be nice to cut out the middleman as it were. But I guess that would work as a backup plan...

This all is mostly because I am conducting very sinful experiments with ZScript based level logic and scripting, partially selfishly motivated by me getting annoyed at repeatedly forgetting to compile my ACS + UDB's script editor having an absolute fit on linux. That, and just seeing if I can, because I've been having fun, let's call it "sticking wrenches into gearboxes"

...Honestly, an alternative would be an ANIMDEF for a switch that's just a quick click-click in and out. So even if you press it a bunch of times it just feels like you're mashing the button repeatedly instead of feeling like it's broken.


Edit-

After a bit of playing around I decided to just use the ACS method for now, with LOADACS so all maps can see it. Just a quick little script to talk to the actor via ScriptCall and wait until it reports it's finished. The switch stays stuck until the script is done, which is all I wanted in the first place.

Code:
script 1024 (int tid)
{
   Thing_Activate(tid);
   
   do
   {
      Delay(1);
   }
   while (ScriptCall( [...] );
}