Page MenuHomeFeedback Tracker

[Feature Request] Optional bool flag for getVariable to set the default value
New, NormalPublic


Is it possible to have an optional bool flag for getVariable to set the variable automatically if it doesn't exist?

_obj getVariable ["var", default, setIfDoesntExist]

It would be very useful when working with array references, since you don't have to use setVariable anymore:

_arr = _obj getVariable ["my_array", [0, 0], true];
_arr set [1, _newValue];


Operating System
Windows 10 x64

Event Timeline

Leopard20 created this task.Feb 8 2023, 6:55 PM
MDCCLXXVI added a subscriber: MDCCLXXVI.EditedFeb 11 2023, 8:26 AM

a variable counterpart for "getOrDefaultCall" would be fantastic

_vehicle = createVehicle ['B_MRAP_01_F',[0,0,0]];

_displayname = _vehicle getVariableCall ['displayname',{(getText ((configOf _vehicle) >> 'simulation'))}];

systemchat str _displayname  // "Hunter"
systemchat str (_vehicle getvariable 'displayname')	// 	"Hunter"
SaMatra added a subscriber: SaMatra.Jan 4 2024, 7:18 AM

Here is a suggestion on how getVariableCall can be incorporated into existing command with backwards capability and also address original ticket idea:

getVariable ["var", {123}] // Return {123} code if "var" is not found
getVariable ["var", {123}, false] // Call {123} if "var" is not found and just return it
getVariable ["var", {123}, true] // Call {123} if "var" is not found, write into "var" and return it

Perhaps it can also work with non-code 2nd argument and true 3rd argument. You'll need code returning code if you'll want to default set the code though.

POLPOX added a subscriber: POLPOX.Jan 4 2024, 7:39 AM