{"name":"private","title":"private","type":"command","url":"https://community.bistudio.com/wiki/private","revid":377850,"updated":"2026-01-03T11:40:32Z","groups":["Variables"],"status":"ok","games":{"ofp":"1.00","ofpe":"1.00","arma1":"1.00","arma2":"1.00","arma2oa":"1.50","tkoh":"1.00","arma3":"0.50"},"since":"ofp 1.00","arma3_since":"0.50","description":"Sets a variable to the innermost scope. See also param and params.\n\n> [!WARNING]\n> - private variables **must** start with an underscore: `private _myVar1 = \"myVar\";` - see Identifier.\n> - **Always** make your local variables **private** (through private or params) in order to avoid overwriting a local variable of the same name.","syntaxes":[{"syntax":"private variableName","params":[{"name":"variableName","type":"String","description":"e.g `\"_myVar\"`","type_expr":"String"}],"returns":{"type":"Nothing","type_expr":"Nothing"},"form":"unary","right":{"text":"variableName"}},{"syntax":"private variableNameList","params":[{"name":"variableNameList","type":"Array of Strings","description":"e.g `[\"_target\", \"_damage\"]`","type_expr":"Array<String>"}],"returns":{"type":"Nothing","type_expr":"Nothing"},"form":"unary","right":{"text":"variableNameList"}},{"syntax":"private _identifier = value","note":"**From Arma 2 v1.00 to Arma 3 v1.52:** see **local**","since":"arma3 1.54","params":[{"name":"_identifier","type":"underscored variable name, for example `_myVar`","types":["Identifier"]},{"name":"value","type":"Anything: value to assign to the variable","type_expr":"Anything"}],"returns":{"type":"Nothing","type_expr":"Nothing"},"form":"unary","right":{"text":"_identifier = value"}}],"examples":[{"code":["private _varname = \"this is my new variable\"; // since Arma 3 v1.54\n\n// identical, but less performant\nprivate \"_varname\";\n_varname = \"this is my new variable\";"]},{"code":["private [\"_varname1\", \"_varname2\"];\n_varname1 = \"variable 1\";\n_varname2 = \"variable 2\";"]},{"code":["_lol = 123; call { hint str [_lol] }; // [123]\n_lol = 123; call { private \"_lol\"; hint str [_lol] }; // [any]"]},{"text":"```sqf\n_myvar = 123;\nsystemChat str [_myvar];        // [123]\ncall {\n    systemChat str [_myvar];    // [123]\n    private \"_myvar\";\n    systemChat str [_myvar];    // [any]\n    _myvar = 345;\n    systemChat str [_myvar];    // [345]\n};\nsystemChat str [_myvar];        // [123]\n```","code":["_myvar = 123;\nsystemChat str [_myvar];\t\t// [123]\ncall {\n\tsystemChat str [_myvar];\t// [123]\n\tprivate \"_myvar\";\n\tsystemChat str [_myvar];\t// [any]\n\t_myvar = 345;\n\tsystemChat str [_myvar];\t// [345]\n};\nsystemChat str [_myvar];\t\t// [123]"]}],"see_also":["param","params","privateAll"],"notes":[{"user":"Faguss","date":"2010-08-04T13:30:00Z","text":"The higher scope is also the script from which the function has been called.\nin **script2.sqf**:\n\n```sqf\n_a = 2;\n```\n\nin **script1.sqf**:\n\n```sqf\n_a = 1;\ncall compile preprocessFileLineNumbers \"script2.sqf\";\nhint format [\"%1\", _a];\n```\n\nGame will display 2.\nInserting `private \"_a\"` in the function prevents the change and so number 1 will be displayed on the screen."},{"user":"DreadedEntity","date":"2015-02-25T17:06:00Z","text":"Recursive loops require the use of private. Without it, your variables will be overwritten."},{"user":"654wak654","date":"2018-01-31T10:37:00Z","text":"This command is *similar* to javascript's [let](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let) keyword.\n**EDIT:** in the way that it scopes the variable to the innermost scope. Otherwise, let and private can behave differently - Lou Montana (talk)"}]}