Page MenuHomeFeedback Tracker

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

Description

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];

Details

Severity
Feature
Resolution
Open
Reproducibility
N/A
Operating System
Windows 10 x64
Category
General

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"