private variableName

From Bohemia Interactive Community

Jump to: navigation, search
Editors, please check Policy: Scripting Command Page Syntax.
Introduced in Operation Flashpoint version 1.00

Click on the images for descriptions

Introduced in

Game:
Operation Flashpoint
Version:
1.00

Description

Description:
Sets a variable to the innermost scope. The variable has to be local.

Syntax

Syntax:
private String
Return Value:
Nothing

Examples

Example 1:
private "_varname";

Additional Information

Multiplayer:
Behaviour unknown.
See also:
private for more than one variable

Notes

Notes

+ Add Note

Only post proven facts here. Use the talk page or the forums for discussions.

Notes



ColonelSandersLite

The example provided is fairly worthless without a context.
Using the private command allows you to declare a variable in the current scope, without regards to variables in a higher scope with the same name. Note that if you try to declare a variable without an underscore (meaning it's global) with the private command, it will cause an error. Specifically: "Error Local variable in global space".
Here's a code example with output for your benefit.

_foo = 10;
if (true) then
{
    private ["_foo"];
    _foo = 5;
    player sideChat format ["%1", _foo];
};
player sideChat format ["%1", _foo];


In this example, the first sidechat (innermost) returns 5 while the second sidechat (outermost) returns 10.

if (true) then
{
    private ["_bar"];
    _bar = 5;
    player sideChat format ["%1", _bar];
};


In this example, the private command does nothing and is simply a waste of code, assuming there is no higher level code to interfere with the if statement.


Bottom Section

Personal tools
Buy ArmA now!