Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
  • 0
Subatomic

Using ACS, check if script has run already

Question

Let's say I have two linedefs (Linedef A and Linedef B), both of which are set to execute Script 1 on walkover. For this part, not a problem. But here's what I'd like to do more specifically: The player walks over Linedef A first, script 1 executes. Then, the player walks over Linedef B and script 1 does *not* execute. However, if the player walks over Linedef B first, script 1 executes, then they walk over Linedef A and it does *not* execute.

 

Is this possible to do with ACS? If so, how?

Share this post


Link to post

6 answers to this question

Recommended Posts

  • 1

If it's a looping script, this happens automatically; ACS_Execute only allows one instance of each script to run at a time, which is why ACS_ExecuteAlways exists.

 

Otherwise, it's not terribly difficult either. Make a global variable, like, say, bool script1Executed, and set it at the end of script 1. Then, at the start of script 1, either return if script1Executed is set, or put the entirety of script 1's contents into an if statement that only executes if it isn't set.

 

e.g.

 

bool script1Executed;

script 1 ( void ) {
	if( script1Executed ) {
		return;
	}
	
	..
	
	script1Executed = true;
}

 

Share this post


Link to post
  • 1

Give both linedefs the same id (tag) "A".  When either linedef executes your script, use SetLineSpecial in that script to remove the special from any linedefs tagged "A".

Share this post


Link to post
  • 0

Are you sure about it automatically only running once? Right now, if I walk over linedef A, script 1 will spawn an imp. If I then walk over linedef B, another imp spawns -- whether I have it set to be repeatable or not. This is using just Script Execute (action 80), by the way. So you're saying this should already prevent it from running twice? It doesn't seem to work that way, but I'm likely not setting it up properly.

 

I tried using your method but GZDoom Builder gives a compile error at "return;".

Share this post


Link to post
  • 0
9 hours ago, Subatomic said:

Are you sure about it automatically only running once? Right now, if I walk over linedef A, script 1 will spawn an imp. If I then walk over linedef B, another imp spawns -- whether I have it set to be repeatable or not. This is using just Script Execute (action 80), by the way. So you're saying this should already prevent it from running twice? It doesn't seem to work that way, but I'm likely not setting it up properly.

Yes, I'm sure. But note that I said looping script - that's important, because otherwise the script will destroy its instance as soon as it reaches its end. Which will happen in less than a game tick, if there's nothing delaying it.

 

Share this post


Link to post

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×