OFPEC Forum
Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: Mr.Peanut on 09 Dec 2004, 14:22:34
-
In a function variables are declared as follows:
Private ["_a","_b"]
Are the underscores really necessary since I am using the Private directive?
Can I just use:
Private ["a","b"]
instead to declare variables private to the function? I am translating an algorithm in a different language and the prospect of adding all those underscores is daunting.
-
I've just been trying in vain to debug my code and found it will NOT accept private variables unless they start with an underscore. I guess that answers my question.
-
Conversely, is it necessary to use the private function if you are using _underscores?
-
Instead of digging up almost 5 years old topic you could have started a new one.. :cop:
Anyhoo, using private with functions is mandatory because the function you call in a script shares the same scope with the script so if you have a variable called _var both in the script and in the function they override each other (depending in which it comes last) unless you private it in the function.
(this is true at least in OFP, I haven't tested this in A1/A2)
So if you have a script executed by a soldier unit
_var = _this select 0
#check
~3
_stuff = _var call myfunction
?(alive _var): goto "check"
And the function
_unit = _this
_var = magazines _unit
..codecodecodecode
That would cause you errors/problems because in the script the variable _var would now be the _var from the function and not the unit it was originally set as.
-
Thanks, very much.