import: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
mNo edit summary
m (Text replacement - "↵|version1= 2.18↵↵|branch= dev↵" to " |version1= 2.18 ")
 
(8 intermediate revisions by 4 users not shown)
Line 2: Line 2:


|game1= arma3
|game1= arma3
|version1= 2.16
|version1= 2.18


|arg= local
|gr1= Variables
|eff= global


|gr1= Object Manipulation
|descr= Imports one or multiple local variables from the parent scope, and defines them as [[private]] variables in the current scope. It can bypass [[privateAll]].


|descr= Imports one or multiple local variables from the parent scope, and defines them as [[private]] variables in the current scope. It can bypass [[privateAll]].
{{Feature|informative|For the config keyword, see [[import (Config)]].}}


|s1= [[import]] variableName
|s1= [[import]] variableName


|p1= variableName: [[String]] - variable to import
|p1= variableName: [[String]] or [[Array]] of [[String]]s - variable(s) to import


|r1= [[Nothing]]
|r1= [[Nothing]]
|s2= [[import]] variableNames
|p21= variableNames: [[Array]] of [[String]]s - variables to import
|r2= [[Nothing]]


|x1= <sqf>
|x1= <sqf>
_myVar = 1;
private _myVar = 1;
call
call
{
{
  import "_myVar"; // similar to: private _myVar = _myVar;
import "_myVar"; // similar to: private _myVar = _myVar;
}
};
</sqf>
</sqf>


|x2= <sqf>
|x2= <sqf>
_a = 1;
private _a = 1;
_b = 2;
private _b = 2;
call
call
{
{
  import ["_a", "_b"]; // similar to: [_a, _b] params ["_a", "_b"];
import ["_a", "_b"]; // similar to: [_a, _b] params ["_a", "_b"];
}
};
</sqf>
</sqf>


|seealso= [[privateAll]] [[private]] [[params]]
|seealso= [[privateAll]] [[private]] [[params]]
}}
{{Note
|user= Hypoxic125
|timestamp= 20240303183125
|text= When making local functions, the imported variable does not have to exist until the function is called.
<sqf>
// Local function
private _stringifyNum = {
import "_num";
str _num;
};
private _num = 5;
call _stringifyNum;
// Returns "5"
</sqf>
}}
}}

Latest revision as of 16:08, 8 October 2024

Hover & click on the images for description

Description

Description:
Imports one or multiple local variables from the parent scope, and defines them as private variables in the current scope. It can bypass privateAll.
For the config keyword, see import (Config).
Groups:
Variables

Syntax

Syntax:
import variableName
Parameters:
variableName: String or Array of Strings - variable(s) to import
Return Value:
Nothing

Examples

Example 1:
private _myVar = 1; call { import "_myVar"; // similar to: private _myVar = _myVar; };
Example 2:
private _a = 1; private _b = 2; call { import ["_a", "_b"]; // similar to: [_a, _b] params ["_a", "_b"]; };

Additional Information

See also:
privateAll private params

Notes

Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord or on the Forums.
Only post proven facts here! Add Note
Hypoxic125 - c
Posted on Mar 03, 2024 - 18:31 (UTC)
When making local functions, the imported variable does not have to exist until the function is called.
// Local function private _stringifyNum = { import "_num"; str _num; }; private _num = 5; call _stringifyNum; // Returns "5"