Jump to content
Sign in to follow this  
ernave

Setting and reading variables in triggers

Recommended Posts

Let's say that I want to set and read variables in the different parts of a trigger (the condition, the activation, and the deactivation section).

 

Step 1, I give the trigger a name like MyTrigger

Step 2, I set a variable in the activation section:

MyTrigger setvariable ["somevarname",12345];

Step 3, I can read the variable in deactivation:

MyTrigger getvariable ["somevarname",0]

 

My question: can I do this without having to hard code "MyTrigger" in the code?

 

Why do I want to do this? Because I will have many, many copies of this trigger in my mission, and I would prefer not to have to customize the code for all of them. Thanks.

Share this post


Link to post
Share on other sites

thisTrigger is refence to the trigger itself in triggerStatements.  No need to give the trigger a name unless needed for reference elsewhere.

 

If you want the set variable unique to one trigger, give one trigger a name and there use thisTrigger setVariable [ ] and thisTrigger getVariable [ ].  In all the other triggers put <trigger name> getVariable [ ], using reference to that one trigger's name.

 

Or, if you need the set variable unique to each trigger individually, no need to name the triggers.  in each trigger use thisTrigger setVariable [ ] and thisTrigger getVariable [ ].

 

Edited by opusfmspol
clarified

Share this post


Link to post
Share on other sites

Why stick to triggers in the first place?

You can easily define a more abstract function that does what you want and applies what you want on any game object.

 

Cheers

Share this post


Link to post
Share on other sites
2 hours ago, opusfmspol said:

thisTrigger is refence to the trigger itself

 

 

So if I understand you correctly, this statement should work:

 

thisTrigger getVariable["dfsd",0]

 

Share this post


Link to post
Share on other sites

Thank you!

 

I guess I tried "this" but didn't try "thisTrigger"

 

I notice another one of the magic variables is "thisList" - if I wanted to loop through that to see if any human player was still inside the trigger radius, would I do something like:

{
	if (isPlayer _X) {
		// some code here
	}
} foreach thisList

 

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
Sign in to follow this  

×