Jump to content
doctorbutts

Is there a way to pass/get a local variable into setTriggerActivation?

Recommended Posts

I've created the victim as a local variable in the script and am using the _victim as the triggerAttachVehicle. The script is creating a few different triggers: I want to be able to see if the victim is conscious and not bleeding (and do something if it is) and I've created another trigger to check to see if the victim is unconscious and bleeding (and do something if they are). Both don't work because, as I've read around, you can't pass a local variable into the setTriggerActivation area.

Are there other ways around this? Some of the posts seem to want to push it the Onact into another script but I still need to be able to check a condition before doing anything, so passing it to another script/code doesn't really help.

 

Here's an example of one of the setTriggerActivation statements:

_healed_trig setTriggerStatements ["(this) && !([_victim] call ace_medical_blood_fnc_isBleeding) && ([_victim] call ace_common_fnc_isAwake)", "hint 'victim healed';", ""];

The above code works when I create a regular/global variable, but I may have a number of _victims going at a time- so I'd rather not have the same variable used for all. For the OnAct code, I am going to do some other things (such as deleteVehicle _victim)- but I can't even get past the Cond area with the local variables.

 

Overall, the script is a 'mission' that's called and has things like createTask and that condition being updated as well.

Any suggestions?

Share this post


Link to post
Share on other sites

This (first part of your trigger condition) refers to preset condition like BLUFOR Present  . So what is yours?

In other term, what could be thisList ?

Share this post


Link to post
Share on other sites
Quote
1 hour ago, stanhope said:

 

 

The trigger is also a local variable. I tried it anyway and it doesn't work. Thanks though.

 

1 hour ago, pierremgi said:

This (first part of your trigger condition) refers to preset condition like BLUFOR Present  . So what is yours?

In other term, what could be thisList ?

 

Sure, here's every step of a chunk of code I'm working on just to figure out this part:
 

_randvic = selectRandom civ_unit_array;
_vicgroup = createGroup [independent, true];
_victim = _vicgroup createUnit [_randvic,position player,[],0, "NONE"];
_healed_trig = createTrigger ["EmptyDetector", _victim,true];
_healed_trig setTriggerArea [3, 3, -0, false];
_healed_trig triggerAttachVehicle [_victim];
_healed_trig setTriggerActivation ["VEHICLE","PRESENT", false];
_healed_trig setTriggerTimeout [3, 3, 3, false];
_healed_trig setTriggerStatements ["(this) && !([_victim] call ace_medical_blood_fnc_isBleeding) && ([_victim] call ace_common_fnc_isAwake)", "hint 'victim healed';", ""];


I suppose I could try some sort of 

{
    if(side _x == independent) then
    {
        hint "he fine, doc;
		deletevehicle _x;
    }
} foreach man in thisList;

I doubt that code is correct, but if I went that route I'm afraid I might run into trouble if I ever had to expand the trigger area and I had other 'missions' going on that had units of that same type when the conditions are met.

edit: I guess I could further protect that by closing down the civ_arrays for victims/shooters and other 'missions' and then doing a 'typeof' "civ_man_bobby_bob" check for the thisList, but that would start limiting the randomness.

Then again, I'm probably not understanding your statement correctly:

Quote

In other term, what could be thisList ? 

 

Edited by doctorbutts

Share this post


Link to post
Share on other sites

@doctorbutts, as far as I remember, if an object is attached to a trigger using triggerAttachVehicle command, then the object is accessible through thisList variable, so try to use this code:

_healed_trig setTriggerStatements [
    "this && {
        _victim = thisList select 0;

        !([_victim] call ace_medical_blood_fnc_isBleeding) && { [_victim] call ace_common_fnc_isAwake }
    }",
    "hint 'victim healed';",
    ""
];

Also you can use getVariable and setVariable commands to transfer variables between the trigger and your code:

_healed_trig setTriggerStatements [
    "this && {
        _victim = thisTrigger getVariable 'victim';

        !([_victim] call ace_medical_blood_fnc_isBleeding) && { [_victim] call ace_common_fnc_isAwake }
    }",
    "hint 'victim healed';",
    ""
];

_healed_trig setVariable ["victim", _victim];

 

  • Like 1

Share this post


Link to post
Share on other sites


Since I had trouble finding it on my own (I could have sworn I read through all the Trigger stuff on BISWIKI), do you know the output array/params for a created trigger? I'm looking for something like (triggername1 select 0, triggername1 select 1), if it is even possible.

Share this post


Link to post
Share on other sites

Actually,

It isn't working. It's only evaluating whether 'this' is true. I'm getting an invalid number in expression error every time I tried both methods.

Share this post


Link to post
Share on other sites
1 hour ago, doctorbutts said:

do you know the output array/params for a created trigger? I'm looking for something like (triggername1 select 0, triggername1 select 1), if it is even possible.

There are getTriggerXXX commands.

 

42 minutes ago, doctorbutts said:

Actually,

It isn't working. It's only evaluating whether 'this' is true. I'm getting an invalid number in expression error every time I tried both methods.

Can you provide full error message got from RPT-file?

Share this post


Link to post
Share on other sites

Here's the full code I'm using to check, I have the victim taking damage to confirm whether or not isbleeding or isawake is being evaluated:
 

_randvic = selectRandom civ_unit_array;
_vicgroup = createGroup [independent, true];
_victim = _vicgroup createUnit [_randvic,position player,[],0, "NONE"];
[_victim, 0.8, "Head", "bullet", player] call ace_medical_fnc_addDamageToUnit;
_healed_trig = createTrigger ["EmptyDetector", _victim,true];
_healed_trig setTriggerArea [3, 3, -0, false];
_healed_trig triggerAttachVehicle [_victim];
_healed_trig setTriggerActivation ["VEHICLE","PRESENT", false];
_healed_trig setTriggerTimeout [3, 3, 3, false];
_healed_trig setTriggerStatements ["this && {_victim = thislist select 0;!([_victim] call ace_medical_blood_fnc_isBleeding) && ([_victim] call ace_common_fnc_isAwake)}", "hint 'victim healed';", ""];

Here's the error.rpt

12:04:08 Error in expression <this && {_victim = thislist select 0;!([_victim] call ace_medical_blood_fn>
12:04:08   Error position: <!([_victim] call ace_medical_blood_fn>
12:04:08   Error Invalid number in expression

So I took out the isbleeding part, leaving 'isawake', then got a similar error:
 

12:06:41 Error in expression <this && {_victim = thislist select 0;([_victim] call ace_common_fnc_isAwak>
12:06:41   Error position: <([_victim] call ace_common_fnc_isAwak>
12:06:41   Error Invalid number in expression

Then I took all of that away and just saw if I could just thislist the awake condition:

{_victim = thislist select 0;(alive _victim)}

Got the same errors as the other two:

12:09:48 Error in expression <{_victim = thislist select 0;(alive _victim)}>
12:09:48   Error position: <(alive _victim)}>
12:09:48   Error Invalid number in expression

I get the same errors when I try to set/get Variable method as well. It leads me to believe it still doesn't know what the variable is.
 

Share this post


Link to post
Share on other sites

I can get around it if I just do thislist select 0 for each condition:

_healed_trig setTriggerStatements ["(alive (thislist select 0)) && !([(thislist select 0)] call ace_medical_blood_fnc_isBleeding) && ([(thislist select 0)] call ace_common_fnc_isAwake)", "hint 'victim healed';", ""];

Maybe the 'condition' portion of the trigger doesn't accept that sort of code or it still can't figure out what that variable is?

but if I ever run into a situation where I can't attach the trigger to that item, I might be screwed, such as with a set/get variable. Unless I learn the getTrigger stuff correctly.

Share this post


Link to post
Share on other sites

I don't care and don't test all ACE things, so this part is on your side. But you don't need any trigger for such script:
 

0 = [] spawn {
  _randvic = selectRandom selectRandom civ_unit_array;
  _vicgroup = createGroup [independent, true];
  _victim = _vicgroup createUnit [_randvic,position player,[],0, "NONE"];
  [_victim, 0.8, "Head", "bullet", player] call ace_medical_fnc_addDamageToUnit;
  _victim spawn {
    params ["_victim"];
    while {true} do {
     waitUntil {sleep 3; !([_victim] call ace_medical_blood_fnc_isBleeding) or !([_victim] call ace_common_fnc_isAwake)};
     waitUntil {sleep 3; [_victim] call ace_medical_blood_fnc_isBleeding && ([_victim] call ace_common_fnc_isAwake) };
     hint "victim healed";
    };
  };
};

Not tested due to ACE presence.
As vanilla test :
 

Spoiler

0 = [] spawn {_randvic = selectRandom ["C_Man_casual_6_v2_F","C_Man_casual_6_v2_F"];
_vicgroup = createGroup [independent, true];
_victim = _vicgroup createUnit [_randvic,position player,[],0, "NONE"];
_victim setDamage 0.5;
_victim spawn {
  params ["_victim"];
  while {true} do {
   waitUntil {sleep 3; !(damage _victim in [0,0.25])};
waitUntil {sleep 3 ; damage _victim in [0,0.25]};
hint "victim healed";}
}};

 

Share this post


Link to post
Share on other sites
On 3/18/2021 at 8:15 PM, pierremgi said:

I don't care and don't test all ACE things, so this part is on your side. But you don't need any trigger for such script:
 


0 = [] spawn {
  _randvic = selectRandom selectRandom civ_unit_array;
  _vicgroup = createGroup [independent, true];
  _victim = _vicgroup createUnit [_randvic,position player,[],0, "NONE"];
  [_victim, 0.8, "Head", "bullet", player] call ace_medical_fnc_addDamageToUnit;
  _victim spawn {
    params ["_victim"];
    while {true} do {
     waitUntil {sleep 3; !([_victim] call ace_medical_blood_fnc_isBleeding) or !([_victim] call ace_common_fnc_isAwake)};
     waitUntil {sleep 3; [_victim] call ace_medical_blood_fnc_isBleeding && ([_victim] call ace_common_fnc_isAwake) };
     hint "victim healed";
    };
  };
};

Not tested due to ACE presence.
As vanilla test :
 

  Reveal hidden contents

0 = [] spawn {_randvic = selectRandom ["C_Man_casual_6_v2_F","C_Man_casual_6_v2_F"];
_vicgroup = createGroup [independent, true];
_victim = _vicgroup createUnit [_randvic,position player,[],0, "NONE"];
_victim setDamage 0.5;
_victim spawn {
  params ["_victim"];
  while {true} do {
   waitUntil {sleep 3; !(damage _victim in [0,0.25])};
waitUntil {sleep 3 ; damage _victim in [0,0.25]};
hint "victim healed";}
}};

 

Been a few days: Yea, I ended up going this route as well. I just have one big while going that will check a few things and sleep at 5.

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

×