Page MenuHomeFeedback Tracker

A set command that also returns the array/hashmap it operated on
New, NormalPublic

Description

I'd like to request a version of set command that also returns the array or hashmap it operated on. Such command will be very useful to reduce number of statement and do more one-line statement when operating arrays, vectors would be a perfect use case here.

Personally I suggest calling it either short ret (return set) or setRet as we can't change existing set for backwards compatibility reasons.

Syntax:

ARRAY = ARRAY ret [INDEX, VALUE];
HASHMAP = HASHMAP ret [KEY, VALUE];

Typical usage scenario, instead of writing:

private _pos = getPosWorld player;
_pos set [2, 100];
_object setPos _pos;

you'd be able to do a one-liner of

_object setPos (getPosWorld player ret [2, 100]);

More advanced version of this idea and a better name

Introduce a new scripting command setN that sets any number of elements at once, supports optional insertOnly flag and returns the array or hashmap that it operated:

ARRAY = ARRAY setN [INDEX_1, VALUE_1, ..., INDEX_N, VALUE_N, (BOOL insertOnly)];
HASHMAP = HASHMAP setN [KEY_1, VALUE_1, ..., KEY_N, VALUE_N, (BOOL insertOnly)];
  1. Better name idea - setN as in set N elements, in line with existing set command name
  2. Setting several elements in one go for performance gains
  3. No backwards compatibility issues, returns the array or hashmap that it operated

insertOnly should behave the same way as it does with current HASHMAP set behavior, optional and false by default, maybe also have it for arrays.

Details

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

Event Timeline

SaMatra created this task.Sat, Feb 3, 4:04 AM
SaMatra updated the task description. (Show Details)Sat, Feb 3, 12:26 PM