Forum Jump :

Author Message


Posts: 208
Rank:


Level: Member

Country: us
Location: U.S.
Occupation: U.S. Army E-3 PFC MOS:92G
Age: 26
In-game name: BOB

 
#1 Posted at 2009-09-07 16:53        
     
I seen in other scripts that you can save a number and refer to it in another script for example

i have one script like this (not actual just example)

_numb=0
_numb=_numb+4

and when i make a different script i can refer back to _numb and the script would know it = 4?

not sure but i think this has to do with it

private ["_type"];

Played this game as a child, best times of my life.

Author Message

Big  

Armaholic icons master


Posts: 5559
Rank:


Level: Former Staff

Country: es
Location: Who knows
Occupation: Industrial Engineer
Age: 45
In-game name:

 
#2 Posted at 2009-09-07 17:08        
     
_numb is a local variable

local
_myLocalVariable = 0;

global
myGlobalVariable = 0;

http://community.bistudio.com/wiki/Variables


Advertisement


Author Message


Posts: 44
Rank:


Level: Member

Country: us
Location:
Occupation:
Age:
In-game name:

 
#3 Posted at 2009-09-11 14:24        
     
private sets the scope. If you define it private inside a block the variables value doesn not leave that block. It is usefull to define it at the highest scope so it is readable throughout the whole script also. As big stated a global variable is what you need to use. I would recomend avoiding globals as much as possible. It is best practice to scope your variables to lowest scope possible.

You can also pass local variables from one script to another script
[_localvar1,_localvar2,_localvar3] ExecVm "myscript.sqf";

then you access the variable using _this select 0; _this select 1 ect ect the number being the index number of the array of passed variables. sqf is zero based so the first item in the array will always be 0


Author Message


Posts: 26
Rank:


Level: Member

Country: us
Location: Dallas, Tx
Occupation:
Age: 49
In-game name:

 
#4 Posted at 2012-03-16 11:47        
     
This is a common problem that unfortunately, I've just learned the hard way... After digging around
Armaholic, I found the answer, and it's been awesome every since... So let me share it with you...

Every time you change a public variable, you must
broadcast it with the publicvariable command as
shown below.

init.sqs

hasFuel = 0;
;Broadcast this variable across all computers
publicvariable "hasFuel";

;...more statements here

Test.sqs

  ? (hasFuel==0): hint "Out of fuel!";

;...more statements here


Whenever you change the value of hasFuel, remember
to broadcast it with...

Test.sqs

  hasFuel=1;
  publicvariable "hasFuel";

  hint format["The value of hasFuel is %1",hasFuel];


I hope this helps

FullMetal

As many of us do, I as well, come from a Flashpoint, Resistance and Arma background. I was a member of the original DSF clan for about two months, back when Hatcher was in charge, along with Deaddog, Joker, Thatcher, two german dudes, and my callsign was, and still is FullMetal.