Page tree
Skip to end of metadata
Go to start of metadata



Introduced in

Version:3.7

Description

Description:

Disables the implicit inheritance of local variables, as defined in the parent scope.

By default, any local variables defined in a parent scope are available to the lower scope code.

Syntax

Syntax:privateAll
Parameters:
Return Value:Nothing

Examples

Examples:
_a = "a"; _b = "b";

_fncPublic = {
  systemChat format["Public: %1, %2",_a,_b]
};
[] call _fncPublic; 

The function returns "Public: a, b", as both variables are accessible inside it.
If privateAll is used in this function, then none of the higher level variables exist anymore:

_a = "a"; _b = "b"; _fncPrivate = { privateAll; systemChat format["Private: %1, %2",_a,_b]; }; [] call _fncPrivate;
The function now returns "Private: any, any", as the higher level variables have been removed from the scope.
If privateAll is declared in a function, but some variables should still be available from the parent scope, then the import commands can be used:

_a = "a"; _b = "b"; _fncSemiPrivate = { privateAll; import ["_b"]; // variable "_b" is imported from the parent scope systemChat format["SemiPrivate: %1, %2",_a,_b]; }; [] call _fncSemiPrivate;
The function now returns "SemiPrivate: any, b", as only the variable "_b" is imported.

Additional Information

See also: private, import
Multiplayer:
Problems:Be aware that if privateAll is used in a for...do loop, that it erases the loop variable, so it has to be imported manually:

for "_i" from 0 to 3 do { privateAll; import "_i"; systemChat str _i; };

Notes