I have two functions used in hiring soldier procedure: one for finding an equipment set in a virtual storage, and one for "compiling" the soldier.
I've noticed that some of hired soldiers had no ammo, while I was sure the ammo is in storage.
After some test I firured it out: both funtions have the same variable name inside its scope, and these variables are not private.
But shouldn't different functions have different scopes?
Description
Description
Details
Details
- Severity
- None
- Resolution
- Not A Bug
- Reproducibility
- Always
- Operating System
- Windows 7 x64
- Category
- Engine
Steps To Reproduce
fnc_getitems = { _magstoremove = [123]; [_magstoremove] }; fnc_check = { _set = ["",0,[]]; _magstoremove = _set#2; _magstoremove }; call fnc_check;
this one returns [] (empty array);
fnc_getitems = { _magstoremove = [123]; [_magstoremove] }; fnc_check = { _set = ["",0,[]]; _magstoremove = _set#2; call fnc_getitems; _magstoremove }; call fnc_check;
In this case [123] returned.
I suppose it should not happens?
Event Timeline
Comment Actions
Not a bug. Read this:
https://community.bistudio.com/wiki/Variables
TL;DR, prefix your local variable initializations with private to prevent what you describe as "leak" (which is actually a feature in SQF)
fnc_getitems = { private _magstoremove = [123]; [_magstoremove] }; fnc_check = { private _set = ["",0,[]]; private _magstoremove = _set#2; call fnc_getitems; _magstoremove }; call fnc_check;