Home   Help Search Login Register  

Author Topic: USE OF PRIVATE COMMAND  (Read 977 times)

0 Members and 1 Guest are viewing this topic.

Offline ZNorQ

  • Members
  • *
  • ehr... uhm... duh...
USE OF PRIVATE COMMAND
« on: 08 Jul 2004, 10:38:24 »
When is it really necessary to use the "private" command in scripting? I thougth the use of an underscore in all variables reduced their scope to the script only. (ie. _vMyVariable) - even when running the same script several times (I use a script for each enemy group for removing their bodies when they die).

I haven't really testet this out to see if there really is a conflict - but could someone confirm that avoiding the use of PRIVATE and the use of underscore infront of any variable keeps them to the local script only?

Also, I understand that any variables created in scripts without the underscore automatically makes them global - and the publicVariable "universal" (broadcasted to all computers in the network.) Am I right?

ZNorQ

ponq

  • Guest
Re:USE OF PRIVATE COMMAND
« Reply #1 on: 08 Jul 2004, 11:06:18 »
afaik you are.

Offline ZNorQ

  • Members
  • *
  • ehr... uhm... duh...
Re:USE OF PRIVATE COMMAND
« Reply #2 on: 08 Jul 2004, 11:18:35 »
Ehr, sorry but I'm not too familiar with the term "afaik"?  Putting two and two together I guess you say "I'm afraid you have to"...  ;D

Anyway, so what I need to do is to introduce private command even though the script is only ran once?

I really hate that command..  ::)

Thx!

ZNorQ

Offline macguba

  • Former Staff
  • ****
    • macguba's operation flashpoint page
Re:USE OF PRIVATE COMMAND
« Reply #3 on: 08 Jul 2004, 11:42:10 »
As Far As I Know

I don't know anything about MP so I don't know about private and publicvariable.

In SP no underscore makes it a global variable which applies to the whole mission.   _underscore makes it local to that edition of the script in question.   That is to say you can run the same script twice at the same time and the local variables in each will not interfere with each other.
« Last Edit: 08 Jul 2004, 11:43:15 by macguba »
Plenty of reviewed ArmA missions for you to play

Offline ZNorQ

  • Members
  • *
  • ehr... uhm... duh...
Re:USE OF PRIVATE COMMAND
« Reply #4 on: 08 Jul 2004, 11:53:49 »
Rgr, macguba.

Hopefully that goes for MP too..

Thx

ZNorQ

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re:USE OF PRIVATE COMMAND
« Reply #5 on: 08 Jul 2004, 12:53:37 »
Actually, I found out something quite odd/interesting/etc. the other day:

Yes, variable with underscore is local in a script, BUT if you call a function from that script and in that function use same local variable that exists in the .sqs script, it passes to the function if it is not in the private array...

For example:

#loop
~1
? blah in _duh: [_blah] call func
_i = _i + 1
? _i == _blah2: goto "loop"


Then , in the func:

private["_vuf","_dud","_result];
_vuf = _this select 0;

while "_i < count _vuf"
  do
     {
       _dud = _vuf;
     };
_result


You can use the same variable (in this case _i) in the .sqs and in the .sqf which the .sqs calls... It seems that the function the .sqs calls exist in the same scope with that .sqs script...
So, if the variable _i has a value 3 in the .sqs the same variable _i used in the .sqf without adding it to the private array has also the value of 3... And you don't need to pass it to the function separately...

Not fully tested, but seems to be this way...

With this, you can also use other local variables than _x in init fields, triggers etc...
The local variable used in the global space needs to defined as not being private before using it, and afaik can only be used when calling functions...

As for the command private, I've only seen it used in functions and probably just because of the things I explained above...
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.