Jump to content
Sign in to follow this  
KrazySwede

Defining local variable with "setTriggerStatements"

Recommended Posts

Is it possible to define a local variable in "setTriggerStatements"? I can define a global variable with

_mytrigger setTriggerStatements["this","varname = true", ""];

But I have not been able to figure out a way to set it up with a local variable.

Can it be done, and if so, how would I do it? I have a feeling the answer to my first question is no, since the trigger wouldn't know where to define the variable. With a global variable scope is not a problem, but it would be if the variable was to be local to the SQF script I am creating the trigger with.

Thanks,

Marcus

Edited by KrazySwede

Share this post


Link to post
Share on other sites

You can't directly assign a local variable to a trigger statement, simply for the fact as such a variable doesn't exist outside it's script. And although the trigger was created in this script, the statements has to refer to global accessible variables.

If this works for you, just create a global variable for this purpose:

myGlobalVar = _myLocalVar;

Share this post


Link to post
Share on other sites

Thanks for the explanation, it is as I feared then. I'm using the trigger in conjunction with a "waitUntil" in a script run on a number of objects. WHat I was hoping to achieve was to hold up the script for a particular object until this trigger had been activated.

With the trigger defining a global variable, the "waitUntil" checks out for all the objects. I tried using waitUntil and the name of the trigger but to no avail, ie

waitUntil{_mytrigger};

Thinking it would return true when activated.

I'll have to tinker with it some more later. Looking at createTrigger I see that its return value is an object so I might be able to use that to my advantage.

Back to the drawing board, hehe. In any case, thanks for the input :).

Share this post


Link to post
Share on other sites

I'm not sure if i got it right what you try to achieve so please forgive me if i talk nonsense.

How about defining the global variable as false right at mission start (init.sqf) and then use it as waituntil condition which is switched by the trigger?

init.sqf

myVar = false;

trigger creating

_mytrigger setTriggerStatements["this","myVar = true", ""];

waituntil

waituntil {myVar};

Share this post


Link to post
Share on other sites

That the way I had it set up at first, however, this script is running on multiple objects. So I have objects A, B and C lets say, and I have executed my script on each. A trigger is created on each object and I only want to execute the code after the waitUntil at a single object when its trigger is activated.

If I make that variable global, the code is executed on all three objects since they're all waiting for that one variable which has global scope.

I can't include my code as part of the setTriggerStatements activation parameter because I want the code to execute not only if the trigger is activated, but also if the object is damaged. So the waitUntil actually looks something like this:

waitUntil{_varname OR (damage _theobject) > 0};

I have a couple of other methods to try as well, like assigning my object's name to that global variable and then checking for the name in the waitUntil, or even calling another script which is the way I used to do it before I decided to (ironically) "simplify" this project.

I'm still learning the ins and outs of ARMA scripting (PHP is my cup of tea, hehe) so I appreciate the help :).

Edited by KrazySwede

Share this post


Link to post
Share on other sites

UPDATE: For practical purpose my problem is solved by using the workaround I mentioned in my last post.

This is part of an IED script I had previously made, but it was using two scripts to run so I wanted to simplify the project and combine the two into one. The resulting issue of having ALL IEDs go off when any one is triggered is obviously a problem. Sure, IEDs are unsafe and unpredictable, but I don't want to have that much fun, hehe.

(I changed my variable names a bit.)

I have the object (the IED) name stored in _targetname and I changed my setTriggerStatements to look like this:

_trigname setTriggerStatements["this",format["activeied = '%1'",_targetname], ""]

And then my waitUntil looks like this:

waitUntil{activeied == _targetname OR (damage _makeied) > 0};

_makeied is the object acting as my IED, on which the script is executed.

So, instead of having a local boolean variable that triggers the IED by being true, there's a global variable that triggers an IED when it stores that IED's name. So all my IEDs are waiting for their names to be called, so to speak.

Barring any unforeseen multiplayer problems, I should be good to go :D.

EDIT: Works without a hitch in multiplayer as well.

Edited by KrazySwede
Status update

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  

×