Jump to content
Asmodeuz

[SOLVED] Looping switch-do, skip a case if true during earlier loop

Recommended Posts

Hello,

 

the short script I've typed below is checking whether a player is inside a marker's area (or not). When the player is (inside the marker's area) an action "Test action" will be added to the player's action menu. Now, since the script is being looped a new action menu entry gets added to the action menu every 5 seconds.

 

Thus far haven't been able to come up with anything meaningfull so: is there a way to stop new action menu entry being added if one has already been added during the earlier loop?

[] spawn {while {alive player} do
 {switch (true) do {
	case (player inArea "marker1"): {testActionID = player addAction ["Test action",{}];};
	
	case !(player inArea "marker1"): {player removeAction testActionID};
		};
	sleep 5;
	};
};

 

Share this post


Link to post
Share on other sites

It's funny sometimes that you've been looking for "days" to come up with something, can't seem to find anything and then you come to forums for help. You post your question and keep scouring the internet while waiting for an answer to the question. And then you happen to find the answer but of course only after coming to forums to type a question about the problem that was bugging you already for some time 😄
 
Answer to my own question is that addAction action includes the param condition where it's possible to declare all kinds of things. The info text for condition states the following:

String - (Optional, default "true") script code that must return true for the action to be shown.

If action is added to player, condition is evaluated all the time.


So for the action menu entry "Test action" to be shown to the player I could simply (eh) use

"player inArea 'marker1'"

in the condition param. When this condition evaluates to true the action is shown to the player, otherwise the action stays hidden.

  • Like 1

Share this post


Link to post
Share on other sites
16 hours ago, Asmodeuz said:

Now, since the script is being looped a new action menu entry gets added to the action menu every 5 seconds.

You set the variable "testActionID" so.. Just check whether it's defined already.

 

[] spawn {while {alive player} do
 {switch (true) do {
	case ((player inArea "marker1") && isNil "testActionID"): {testActionID = player addAction ["Test action",{}];};
	
	case !(player inArea "marker1"): {player removeAction testActionID; testActionID = nil};
		};
	sleep 5;
	};
};

 

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×