Jump to content
kocrachon

Passing variable in addaction and changing state?

Recommended Posts

Hey All,


Right now I have a series of variables that are booleans. terminal_1_hacked = false, terminal_2_hacked = false, etc etc. 

 

With that, I am creating a script to addaction. 

 

Quote

laptop1_action = laptop1 addAction ["Hack Terminal", "hack_terminal.sqf", ["1", terminal_1_hacked]] 

 

I want to make it so when the script gets it, it changes it to true, but it doesn't seem to work.

 

Quote

 

_parameters = _this select 3;

_trigger = _parameters select 1;

_trigger = true;

 


However, this doesn't seem to work as intended, and I sort of see why, but I am not sure how to pass the variable to the script, and making sure I only change terminal_1_hacker when passed as a variable, rather than building a series of if statement to see which of the variables it is. 

Share this post


Link to post
Share on other sites

You should write what you intend to do. At this time, your addaction is weird. What is the need to pass as param some global variables like  a string "1" or terminal_1_hacked..??

Then your _trigger is also non understandable.

 

laptop1 addAction ["Hack Terminal", {terminal_1_hacked = true}] ;  should be fine.

Share this post


Link to post
Share on other sites
9 minutes ago, pierremgi said:

You should write what you intend to do. At this time, your addaction is weird. What is the need to pass as param some global variables like  a string "1" or terminal_1_hacked..??

Then your _trigger is also non understandable.

 

laptop1 addAction ["Hack Terminal", {terminal_1_hacked = true}] ;  should be fine.

 

Theres more going on because I want to play animation so I can have a sleep before the termina_1_hacked = true.

 

Here is what I have as a rough draft so far.

Quote

 

_laptop = _this select 0;
_unit = _this select 1;
_action = _this select 2;
_parameters = _this select 3;

 

 

 

_unit playmove "some_animation";

sleep 5;

 

removeAllActions _laptop;


hint format ["Laptop %1 has been hacked", _parameters  select 0]; //test until I change it later

 

_trigger = _parameters select 1;

_trigger = true;

 

 

Essentially, I don't want the trigger variable to switch from FALSE till TRUE until the animation and everything has been completed.

Share this post


Link to post
Share on other sites

been doing it this way for years, don't understand it all these days, don't need to, still works

 

_id1 = _phone1 addAction ["Open Teleport", "[]spawn SQU_Teleport",_posObj, 0, false, false, "" ];

or

_id = _object addAction ["Buy Light Vehicles", "call SQU_BuyCars",[_posObj,_dir], 0, false, false, "" ];//passing [_posObj,_dir] to SQU_BuyCars.sqf

 

passed to SQU_BuyCars.sqf

_posObj=(_this#3#0);

_dir = (_this#3#1);

 

then you might want switch if your send lots of diff stuff instead of if else

 

            switch(_posObj)do

            {

                case "None":{   _index = nil};                      

                case "Any":{    _index = (floor(random (count _Cars)))};

                case "Soft":{   _index = _CarsSoft select(floor(random (count _CarsSoft)))};

                case "AntiTank":{   _index = _CarsArmour select(floor(random (count _CarsArmour)))};

                case "AntiAir":{    _index = _CarsAir select(floor(random (count _CarsAir)))};

                case "Transport":

                {   

                  player sidechat "hope this helps"

                };                      

          };

Share this post


Link to post
Share on other sites

Yeah... I am not really sure whats going on in what you wrote :S 

 

It seems like you execute the script for addaction entirely different?

Share this post


Link to post
Share on other sites
10 minutes ago, kocrachon said:

Yeah... I am not really sure whats going on in what you wrote :S 

 

It seems like you execute the script for addaction entirely different?

On the other hand, it's not like you'd clearly explain what is your purpose... You spoke about a bunch of global variables like terminal_1_hacked which don't need to be passed as 3rd parameter of the addAction. And your two lines:

_trigger = _parameters select 1;

_trigger = true;

are just useless.

Share this post


Link to post
Share on other sites
12 minutes ago, pierremgi said:

On the other hand, it's not like you'd clearly explain what is your purpose... You spoke about a bunch of global variables like terminal_1_hacked which don't need to be passed as 3rd parameter of the addAction. And your two lines:

_trigger = _parameters select 1;

_trigger = true;

are just useless.

 

I attached my entire script and I explained the premise above.

 

I have a boolean variable set to false. 

 

Quote

terminal_1_hacked = false;

 

I then went to pass it, as a variable, into my .sqf script via addaction parameter, to change the boolean value after the rest of the script runs, because I have a total of 3 matching variables, and once all three of them switch from false to true, a trigger will set off.  How else can I have a script execute and run, and then change the global variable from within the script without writing within the script the global variable? Because then I would need to write some if statement "if paramter == hacked_terminal then do this, else do this, else do this"

Share this post


Link to post
Share on other sites

Your weird entire script,... not a problem,  but not your intention through such wrong way.

 

I showed you how to do simply set your variable. Global variables are OK in any script if your mission you are running on your PC.

Share this post


Link to post
Share on other sites

Here is what you set me

 

Quote

laptop1 addAction ["Hack Terminal", {terminal_1_hacked = true}] ;  should be fine.

 

But the problem for me, with this, is it does not run a script for me. I don't want it to go instantly to true. I want it to switch to true at the end of the script because I want a player animation that looks like the player is using the terminal to run before its "hacked". So is there a way for the script to run and then change the variable? And the reason I was passing it as a parameter is so I could use the same script for all 3 terminals the player has to hack. Is there a way around this?

 

This is also used for online, does that change it at all?

Share this post


Link to post
Share on other sites

laptop1_action = laptop1 addAction ["Hack Terminal", "hack_terminal.sqf", ["1", "terminal_1_hacked"]] 
...

_trigger = _parameters select 1;

missionNamespace setVariable [_trigger, true];

Share this post


Link to post
Share on other sites
HackedLaptops = 0;
{
  _x addAction ["Hack Terminal", {
    params ["_target", "_caller", "_Id","_params"];
    _caller playmove "some_animation";
    sleep 5;
    _target removeAction _Id;
    hackedLaptops = hackedLaptops + 1;
    _nbr = _params #0;
    hint ("Laptop "+str(_nbr)+ " has been hacked");
  },[_forEachIndex +1] ];
} forEach [laptop1,laptop2,laptop3];

Just wait for hackedLaptops == 3 in your trigger.

 

Share this post


Link to post
Share on other sites
5 minutes ago, killzone_kid said:

laptop1_action = laptop1 addAction ["Hack Terminal", "hack_terminal.sqf", ["1", "terminal_1_hacked"]] 
...

_trigger = _parameters select 1;

missionNamespace setVariable [_trigger, true];

 

Thank you, I will test this when I get home in a few hours. 

Share this post


Link to post
Share on other sites
5 minutes ago, pierremgi said:

What concerns laptop1 stays with laptop1...

 

laptop1 addAction ["Hack Terminal", {

  params ["_target", "_caller", "_Id"];

  _caller playmove "some_animation";

  sleep 5;

  removeAction _Id;

  hint "Laptop1 has been hacked";

}];

 

Or, with one in all script:
 


{
  _x addAction ["Hack Terminal", {
    params ["_target", "_caller", "_Id","_params"];
    _caller playmove "some_animation";
    sleep 5;
    _target removeAction _Id;
    _nbr = _params #0;
    hint ("Laptop "+str(_nbr)+ " has been hacked");
  },[_forEachIndex +1] ];
} forEach [laptop1,laptop2,laptop3];

 

 

 

Ok, I am still confused. Because this does not change the boolean value of my variable does it? Or am I missing something?


The point of the boolean variable (terminal_1_hacked = false/true) is because I have a trigger places that once all three variables switch from false to true, it triggers a new event. That is why I am trying to figure out how to convert a global variable from false to true, so that it can set off another trigger elsewhere. 

Share this post


Link to post
Share on other sites
Just now, kocrachon said:

 

 

Ok, I am still confused. Because this does not change the boolean value of my variable does it? Or am I missing something?


The point of the boolean variable (terminal_1_hacked = false/true) is because I have a trigger places that once all three variables switch from false to true, it triggers a new event. That is why I am trying to figure out how to convert a global variable from false to true, so that it can set off another trigger elsewhere. 

Modified

Share this post


Link to post
Share on other sites
1 minute ago, pierremgi said:

Modified

 

That method does make a lot more sense. thank you. 

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

×