Page MenuHomeFeedback Tracker

"push" command is needed for working with arrays in scheduled environment [PICTURE]
Closed, ResolvedPublic

Description

*Syntax*

ARRAY push ANYTHING

Adds ANYTHING to the end of ARRAY.

Does exactly what ARRAY set [count ARRAY, ANYTHING] does, only willo not fail in scheduled environment.

*Problem*

In scheduled environment a script can go into suspension half way through, and and then resume later on while having the same values in variables before the suspension. Because of this, the values of variables may be already too old after suspension.

For example, if I want to add an element to the end of array in one spawned loop while another spawned loop is also set to modify the same array, if 1st loop goes into suspension between

_end = count myArray;

and

myArray set [_end, "something"];

the sexond loop can modify the array and "something will be added not to the end of array but to (end - 1). See repro.

Because ARRAY set [count ARRAY, ANYTHING] is actually 2 commands and not one, there is a chance the script can go into suspension in between.

set command can be modified to take the end of array as index, so it will become push.

{F24202}

Details

Legacy ID
64278661
Severity
None
Resolution
Fixed
Reproducibility
Always
Category
Scripting
Steps To Reproduce

remove comment is run this in debug console. one loop writes false into 1st element of array and checks that it is not true, the other writes true. If the loop that writes false goes into suspension before it can check the element, the "true" loop can overwrite it before the 1st script is finished.

array = [];
l2 = [] spawn {
while {true} do {

		array set [0, true];

};
};
l1 = [] spawn {
player sidechat "START";
for "_j" from 1 to 1000 do {

		for "_i" from 1 to _j do {
			null = _i;
		};
		array set [0, false];
		//--- possible script suspension here ---
		if (array select 0) then {
			player sidechat str ["array select 0 is true!", _j];
		};

};
terminate l2;
player sidechat "FINISH";
};

Event Timeline

Killzone_Kid edited Additional Information. (Show Details)
Killzone_Kid set Category to Scripting.
Killzone_Kid set Reproducibility to Always.
Killzone_Kid set Severity to None.
Killzone_Kid set Resolution to Fixed.
Killzone_Kid set Legacy ID to 64278661.May 7 2016, 6:52 PM

I don't think proposed script command can solve the issue in attached example code, because that script suspension before ("if") check can occur even with that "push" script command. However, the issue of two script commands ("set" and "count") could be solved by using of "+" operator. At least it worked fine for me in all cases. Do you observe similar issues even with the solution attached bellow this text?

ARRAY = ARRAY + [ANYTHING];

The array + array is much slower operation than set and count together, and with large arrays it is very slow. in shcheduled environment when you only have 3ms window before the suspension, any gain in speed of every individual command you can get matters a lot. And yes i dont see why adding to array wouldnt solve this particular problem, but as i said at the cost of performance.

Oh and attached code was to demonstrate suspension that can occur in the middle of the script, real problem is reliable and fast add to the back of array

DEV. 125892 - new command push_back introduced

@japa you are the best! Only why push_back? Can we call it pushBack to keep with naming convention? It is explicit name so I'm fine with it, although array commands I've encountered like in perl etc were push, pop, shift and unshift. pushBack is ok too (if you are planning on adding pushFront ;))

@Druid. I've just run a small test to demonstrate how bad is array + array and why we need fast push command. Try it yourself. It basically iterates 10000 times so you end up with 10000 element array at the end. Note the set variant has 2 command as well, imagine how fast would be dedicated push:

arr = []; ['arr set [count arr, 0]'] call bis_fnc_codePerformance

my result: 0.0046ms

arr = []; ['arr = arr + [0]'] call bis_fnc_codePerformance

My result: 0.1586ms

34 times the difference!

I absolutely agree with Killzone_Kid about this, performance of such basic operations is extremely important especially in code that is being run each frame. A practical example for this is complex icons over player, without using drawIcon3d when you need to have several UI elements above each unit, such task involves tens and tens of array operations each frame, using fastest command possible matters A LOT when trying to maintain good FPS, especially in multiplayer where FPS is usually much lower.

New push command is 60 times faster than array + array! Mission complete!

well pushBack command was successfully implemented and announced in http://dev.arma3.com/post/sitrep-00064 so we can close this task

kudos to you japapatramtara :)

MadDogX added a subscriber: MadDogX.May 7 2016, 6:52 PM

Mass closing tickets marked as resolved more than 1 month ago.

If the issue is in fact not resolved, please create a new ticket referencing this one and ask for it to be re-opened.

Ticket re-opened, because apparently it is not actually resolved.

@MadDogX could you elaborate on reopening?

MadDogX:

I though that pushBack command we successfully implemented and widely used by community. So please can you post additional information about a problem? Simple repro case would be the best

If there is a problem with pushBack command, an explanation and possible repro is needed.

The reopening was as it was not available in stable, so it should have remained resolved but not closed.

Ok, thanks .kju, it is now on 1.26, so going to resolve it.

Mass-closing all resolved issues not updated in the last month.

Please PM me in BI Forums (http://forums.bistudio.com/member.php?55374-Fireball) if you feel your bug was closed in error.