Jump to content
Sign in to follow this  
dragonsyr

Variables in list help needed

Recommended Posts

is it possible this?

variables.sqf

_var1= blah blah;
_var2=blah blah;
if (_var1) then {execvm "script.sqf";};
..........

can i use those variables from another script ?

ex: script.sqf

_var3 = true;
if (_var 1 == something) then {blah blah} else
{};

(above example have a call on script.sqf . maybe the private command do the job???)

also this ? the diference here is that the two scripts is n t connected somehow

variables.sqf

_var1= blah blah;
_var2=blah blah;
_var3 = blah blah

can i use those variables from a script ?

ex: script.sqf

if (_var 1 == something) then {blah blah} else
{};

Share this post


Link to post
Share on other sites

No the _ operator means that the variable is local to the .sqf file

You can either make the variables global by removing the _ or pass the variable as argument

EDIT: publicvariable is not needed... This only synchs the variable to all clients in a Multiplayermission

Share this post


Link to post
Share on other sites

Yeah depends what you want really, if your using lots of if and then's then that are relient one thing I'd use public. Other wise just pass:

_var1 = 1

_var2 = 1

[_var1, _var2 ] execvm "script.sqf";

Share this post


Link to post
Share on other sites

1. Public != Global: public means it is synched over the network, global means that a variable is valid on a global (missionwide) scope (what gragonsyr needs)

2. Passing variables with arguments is better readable and often needed

Share this post


Link to post
Share on other sites

thanks for your fast replys.....

i will try the global variable then.....

edit: how can i do that? globalvariable command not in the list ..

i want to make a script that can stand on dedicated server missions

i only found publicVariableServer (run on client) and publicVariableClient (run on server) but i m not sure what is ...

Edited by dragonsyr

Share this post


Link to post
Share on other sites

You can choose 3 ways:

With global Variables (not that good/pretty):

variables.sqf

var1 = 1;
var2 = 2;
var3 = 3;

if (_var1 == 1) then {execvm "script.sqf";};

script.sqf

var2 = var2 + var3;

With arguments (better):

variables.sqf

_var1 = 1;
_var2 = 2;
_var3 = 3;

if (_var1 == 1) then 
{
[_var1, _var2] execvm "script.sqf";
};

script.sqf

_var2 = _this select 0;
_var3 = _this select 1;
_var = _var2 + _var3;

Calling with precompiling/preprocessing (best practice):

init.sqf

TAG_fnc_variables = compile preprocessFilelineNumbers "variables.sqf";
TAG_fnc_script = compile preprocessFilelineNumbers "script.sqf";

call TAG_fnc_variables;

variables.sqf

_var1 = 1;
_var2 = 2;
_var3 = 3;

if (_var1 == 1) then 
{
[_var1, _var2] call TAG_fnc_script;
};

script.sqf

_var2 = _this select 0;
_var3 = _this select 1;
_var = _var2 + _var3;

Edit:

In order to synch the variable over the network you can use:

publicVariable "variablename";

Edited by trnapster

Share this post


Link to post
Share on other sites

i have this code running allways from my mission init and is in mymission\c\ init.sqf.

while {vehicle player isKindOf "Air"} do {if(_vehrole == "driver") then {hint"Radio on";playSound "Safe";_actiondep = _player addAction ["<t color='#ff9900'>ATC Call</t>", "C\dep.sqf", [], -1, false, false, ""];waitUntil {!(vehicle player isKindOf "Air")};} else {hint"no driver";sleep 2;};};

........code continue on more while commands blah blah;
execVM "ATC\Init.sqf";

now on dep.sqf

if , thens whiles blah blah;
player removeAction _actiondep;sleep 3;
	hint "stage end out of target";sleep 1;//debug 
	execVM "C\Init.sqf"; //at the end of the script..............

my problem is that i can delete this adaction from any location.

i need to remove the addaction from the dep.sqf but i want to know how can i remove this addaction and from c\init.sqf

edit : i can delete the addaction only if the while statement is not valid (if player breaks the loop)

like this

while {vehicle player isKindOf "Air"} do {if(_vehrole == "driver") then {hint"Radio on";playSound "Safe";_actiondep = _player addAction ["<t color='#ff9900'>ATC Call</t>", "C\dep.sqf", [], -1, false, false, ""];waitUntil {!(vehicle player isKindOf "Air")};} else {hint"no driver";sleep 2;};};

........code continue on more while commands blah blah;
player removeAction _actiondep;sleep 3;
execVM "ATC\Init.sqf";

but if the player is in the while loop and then the calling script need to delete the addaction i get 2 same actions and the remove is not working

i hope the you understand what i mean.

Edited by dragonsyr

Share this post


Link to post
Share on other sites

Why not just add a check within the addaction instead of using loops? The action will only appear if the player is in an air vehicle and/or whatever condition(s) you want to use. Else it gets hidden. Or maybe I'm not understanding what you're trying to do :p

unit init:

this addAction ["<t color='#ff9900'>ATC Call</t>", "C\dep.sqf", [], -1, false, false, "_vehrole == 'driver' && {vehicle _target isKindOf 'Air'}"];

Edited by Iceman77

Share this post


Link to post
Share on other sites

i need to remove the addaction from the 2nd script because must removed while the player is still pilot. (other ifs and whiles on the 2nd script. also maybe this remove must happened from 3d, 4th , 5th script in a row)

Edited by dragonsyr

Share this post


Link to post
Share on other sites

You can use global variables or set a variable in the mission namespace.

Global Variable

if (isNil "actiondep") then
{
   actiondep = _player addAction ["<t color='#ff9900'>ATC Call</t>", "C\dep.sqf", [], -1, false, false, ""];
};

or

Mission Namespace

if (isNil {missionNamespace getVariable "actiondep"}) then
{
   _actiondep = _player addAction ["<t color='#ff9900'>ATC Call</t>", "C\dep.sqf", [], -1, false, false, ""];
   missionNamespace setVariable ["actiondep", _actiondep];
};

Then you can execute that code when you want to add the action and it will not add duplicate actions. But when you delete the action make sure to make the variable nil.

player removeAction actiondep;
actiondep = nil;

or

player removeAction (missionNamespace getVariable "actiondep");
missionNamespace setVariable ["actiondep", nil];

Share this post


Link to post
Share on other sites

Mission Namespace

if (isNil {missionNamespace getVariable "actiondep"}) then
{
   _actiondep = _player addAction ["<t color='#ff9900'>ATC Call</t>", "C\dep.sqf", [], -1, false, false, ""];
   missionNamespace setVariable ["actiondep", _actiondep];
};

Then you can execute that code when you want to add the action and it will not add duplicate actions. But when you delete the action make sure to make the variable nil.

player removeAction actiondep;
actiondep = nil;

or

player removeAction (missionNamespace getVariable "actiondep");
missionNamespace setVariable ["actiondep", nil];

where i must put the 1st table code? , in the c/init.sqf , or in the c/start.sqf --in my case, i call from my_mission init.sqf my c\init.sqf and from there i add the addaction for the first time , in a loop with a waituntil command, that on "true" executes the script itself.So, c\init.sqf call many other scripts when some cases triggered. i need to understand how can i remove "things" or use "things" from past scripts as the story goes. i hope that you understand what i mean . Excuse me for my English .....

and my vision need server interaction (dedicated server missions)

Share this post


Link to post
Share on other sites

Both examples that I provided allow you to access a variable from other scripts. The first is using a global variable. If you simple remove the _ from _actiondep it becomes a global variable with global scope. The _ in front of the variable indicates that the variable has local scope, which means it can only be accessed in the current scope, which is usually a single script. Inside your dep.sqf it cannot see the _actiondep variable because that variable is local to the c\init.sqf script. You can, however, see global variables, and so using a global variable will allow you to remove the action.

The second method, which stores the variable in the mission namespace, will allow you to access that variable from anywhere during the execution of the mission.

You can use either method where ever you would like to add or remove an action. The first two examples showed you how you can add an action, and check to see if you already have the action assign so that it wont add it a second time. The last two examples showed you how you can remove the action from anywhere.

Share this post


Link to post
Share on other sites

how can delete an object created from a previous script this way

if (isNil {missionNamespace getVariable "hlight"}) then
{
   _light = _lightType createVehicle [getPos _helitarget select 0, getPos _helitarget select 1,1];
   missionNamespace setVariable ["hlight", _light];

i try with

if (!isNil {missionNamespace getVariable "hlight"}) then{deletevehicle _light;hlight = nil;};

but i get this error on delete "Error Undefined variable in expression: _light"

edit : OK false alarm ..... my mistake in the code...... working perfect......thanks

---------- Post added at 18:57 ---------- Previous post was at 17:59 ----------

another question.

how can i do this

if (isNil {missionNamespace getVariable "hlight"}) then
{_hlight=[
_ang = 0;
_rad = 6.5; //radius
_bcount = 6; //number of lights
_inc = 360/_bcount; 
for "_i" from 0 to _bcount do
{
_a = (_helitarget )+(sin(_ang)*_rad);
_b = (_helitarget )+(cos(_ang)*_rad);

_pos = [_a,_b,_helitarget];
_ang = _ang + _inc;

_light = "Land_runway_edgelight" createVehicle _pos;
_light setPos _pos;
};];};

i need to make a light circle that i can delete after like this

if (!isNil {missionNamespace getVariable "hlight"}) then{deletevehicle _hlight;hlight = nil;};
Edited by dragonsyr

Share this post


Link to post
Share on other sites

if (isNil {missionNamespace getVariable "hlight"}) then
{
 lights=[]; // Array that stores all the created lights
 _ang = 0;
 _rad = 6.5; //radius
 _bcount = 6; //number of lights
 _inc = 360/_bcount; 
 for "_i" from 0 to _bcount do
 {
   _a = (_helitarget )+(sin(_ang)*_rad);
   _b = (_helitarget )+(cos(_ang)*_rad);

   _pos = [_a,_b,_helitarget];
   _ang = _ang + _inc;

   _light = "Land_runway_edgelight" createVehicle _pos;
   _light setPos _pos;

   lights set[_i, _light]; // Adds the object to the end of the array
 };
};  

To delete them:

for "_i" from 0 to count(lights) - 1 do
{
 deleteVehicle (lights select _i);
};

The for var from start to end loop is inclusive. So if _bcount is 6, this loops will iterate 7 times, starting at 0 and going to 6. If you only want 6 lights you can do _bcount - 1. This is why when you delete from the array, you do count(lights) - 1.

Share this post


Link to post
Share on other sites

thank you albert, i ll try that asap

---------- Post added at 12:41 ---------- Previous post was at 12:38 ----------

ps also, do you know who is the blue runway light? because Land_runway_edgelight is the yellow one..

Share this post


Link to post
Share on other sites

with this

if (isNil {missionNamespace getVariable "hlight"}) then
{
 lights=[]; // Array that stores all the created lights
 _ang = 0;
 _rad = 6.5; //radius
 _bcount = 6; //number of lights
 _inc = 360/_bcount; 
 for "_i" from 0 to _bcount do
 {
   _a = (_helitarget )+(sin(_ang)*_rad);
   _b = (_helitarget )+(cos(_ang)*_rad);
   _pos = [_a,_b,_helitarget];
   _ang = _ang + _inc;
   _light = "Land_runway_edgelight" createVehicle _pos;
   _light setPos _pos;
   lights set[_i, _light]; // Adds the object to the end of the array
 };
};

i get this error

Error in expression <om 0 to _bcount do

{

_a = (_helitarget )+(sin(_ang)*_rad);

_b = (_helitarget )+(>

Error position: <+(sin(_ang)*_rad);

_b = (_helitarget )+(>

Error +: Type Object, expected Number,Array,String

Share this post


Link to post
Share on other sites

Is _helitarget an object? I don't even see it defined anywhere in what you've just posted. Do you also get undefined variable error anywhere in your report file? Also, Seems like your doing: (someObject) + (some numbers). Which is causing the type object expected number error. Then again, I just woke up LOL.

Edited by Iceman77

Share this post


Link to post
Share on other sites

it is defined (i post only the line that i have problem)

it is a helipad.

no other variable error,

i tried also with the name of the object but i get the same,

the code is this and working as it is

/* 
  executed by initline of helipads; Original By MH6.
 [h1,6] execVM "scripts\runwaylights.sqf";
*/
if(not local Server) exitWith{};
_target_pos = getPos (_this select 0);
//helipad = "HeliHCivil" createVehicle _target_pos;
//helipad setPos _target_pos;
_ang = 0;
_rad = 6.5; //radius
_bcount = _this select 1; //number of lights
_inc = 360/_bcount; 
for "_i" from 0 to _bcount do
{
_a = (_target_pos select 0)+(sin(_ang)*_rad);
_b = (_target_pos select 1)+(cos(_ang)*_rad);
_pos = [_a,_b,_target_pos select 2];
_ang = _ang + _inc;
_light = "Land_runway_edgelight" createVehicle _pos;
_light setPos _pos;
};
if(true) exitWith{};

how can i do this run within my script as createvehicle ?

---------- Post added at 22:08 ---------- Previous post was at 22:03 ----------

i think that the problem is this

_target_pos = getPos (_this select 0);

i ll try like this _target_pos = getPos (_helitarget);

and the 2 lines as _a = (_target_pos select 0)+(sin(_ang)*_rad);

_b = (_target_pos select 1)+(cos(_ang)*_rad);

i thought that with direct replace with my object would work. wrong guess is think .... i ll try again and post the results....... in a few hours Edited by dragonsyr

Share this post


Link to post
Share on other sites

ok working but i cant delete

light script

if (isNil {missionNamespace getVariable "hlight"}) then
{
_ang = 0;
_rad = 6.5; //radius
_bcount = 6; //number of lights
_inc = 360/_bcount; 
for "_i" from 0 to _bcount do
{
_a = (_target_pos select 0)+(sin(_ang)*_rad);
_b = (_target_pos select 1)+(cos(_ang)*_rad);
_pos = [_a,_b,_target_pos select 2];
_ang = _ang + _inc;
_light = "Land_runway_edgelight" createVehicle _pos;
_light setPos _pos;
// lights set[_i, _light]; //only commented works for spawning
missionNamespace setVariable ["hlight", _light];
};};

the lights spawned and is in place i want

i try to delete with

if (!isNil {missionNamespace getVariable "hlight"}) then {for "_i" from 0 to count(lights) - 1 do{
                       deleteVehicle (lights select _i); // i try also _light , hlight, no luck
                       }; hlight = nil;};

but nothing happened......

and get this error if uncomment the line "lights set"

Error in expression <createVehicle _pos;

_light setPos _pos;

lights set[_i, _light];

missionNamespac>

Error position: <lights set[_i, _light];

missionNamespac>

Error Undefined variable in expression: lights

Edited by dragonsyr

Share this post


Link to post
Share on other sites

i know that, i can make it work without errors (comment the line in my code but i cant delete it .....what is the solution???

for this problem follow this because is out of subject here... sorry my mistake.
is out of subject here .... Edited by dragonsyr
out of subject....sorry

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  

×