Another Array Question

TL;DR: So lately i’ve been updating alot of my Rules for a game i’ve been working on since Workshop Launch. Alot of these rules i was able to condense down &/OR Add To them because of New actions that have been added to the Workshop & my own knowledge of how to scrip has improved. However I run into this problem w/ alot of my Rules, and while it works just fine, I have to image it’s Server intensive to execute, especially when several Rules w/ the same structure can be launched at the same time by various players. SO…

My question is:
Is there a way to modify Specific Indexes OR Elements in an Array, without looping through the array and modifying 1 Index/Element at a time?

For Example, as of right now, I have “these” rules structured like so:
Example 1: Lucio Boop (Boop enemies further based on how close they are to Lucio when Soundwave is triggered (M2))

Rule: Player Delt Damage

Modify Player Variable(Event Player, A, Append To Array, Victim);
Event Player.B = Mapped Array(Event Player.A, Distance Between(Event Player, Current Array Element));
Wait(0.060, Restart When True);
While(Event Player.C < Count Of(Event Player.A));
	Apply Impulse(Event Player.A[Event Player.C], Facing Direction Of(Event Player), 50)
		/ Event Player.B[Event Player.C], To World, Incorporate Contrary Motion);
	Wait(0.016, Ignore Condition);
	Event Player.C += 1;
End;
Event Player.Cooldown[2] = 10;
Wait(2, Ignore Condition);
Event Player.A = Empty Array;
Event Player.C = 0;

I use Var C as the Index I want to select. Apply an Impulse to That player in the selected Index by the distance That player is from Lucio, then Modify var C by 1 (To get to the next index of the array), And Loop if Var C is less then the count of elements in the array. The result is Each player caught in the array is booped a different distance based on how close they are to Lucio.

Example 2: Cooldown Timer (modify Var Indexes by 1 until they reach 0)

conditions
{
	Is True For Any(Event Player.Cooldown, Current Array Element > 1) == True;
}

actions
{
	Wait(1, Ignore Condition);
	Skip If(Event Player.Cooldown[0] == 0, 1);
	Event Player.Cooldown[0] -= 1;
	Skip If(Event Player.Cooldown[1] == 0, 1);
	Event Player.Cooldown[1] -= 1;
	Skip If(Event Player.Cooldown[2] == 0, 1);
	Event Player.Cooldown[2] -= 1;
	Loop If Condition Is True;
	Event Player.Cooldown = Null;
}

}

Since you can’t chase an Index, i simply modify an Index by 1, wait 1sec, then loop IF that Index is greater then 0.

As i said, Both these rules work flawlessly, but because of the looping element in each rules (Specifically the Lucio one & all other’s like that) I have to image they are resource hogs.

Is there a way where can modify the entire array at once, But each index individually based on a condition?

Thanks for looking. Sorry for the long read. Im hoping i gave enough detail to understand what im trying to accomplish.

So, example 2 can be done in one line like this:

Wait ...
Event Player.Cooldown = Mapped Array(Event Player.Cooldown, Current Array Element > 0 ? Current Array Element - 1 : Current Array Element);
Loop ...

x ? y : z is the inline If-Then-Else element, with the syntax meaning

if(x) then y else z

But this rule is entirely obsolete, since you can store the Total Time Elapsed element in the Cooldown array:

Lucio Boop rule ...
Event Player.Cooldown[2] = Total Time Elapsed;

Condition including this line:

Total Time Elapsed - Event Player.Cooldown[2] > 10;

In the first example you will always have to use a looping construct in one way or another. Even actions like mapped/filtered/sorted array are looping internally. And since you want to give the impulse of each player in the array an individual intensity, you cant just put the entire array as “target player” of the rule (this will only work if the intensity and direction are uniform for all players).
But I dont think that the rule would be less resource heavy, since loops in action lists perform quite well usually, because they will only get executed if the rule actually triggers.
Loops in the condition list on the other hand (e.g. “is true for all” or “is true for any” wich are internally loops aswell) will get executed far more often, so they are more resource heavy.

1 Like

Nice to see you around again Shanalotte were you on a long vacation or had longer holidays than usually? :smiley:. And yeah nothing to add especially here from my side. The loop operations within an action list might it be a for/while or any associative loop perform really well, when you have a clear and determined vision of what the outcome might be for your modes, the loops are just fine for a couple of linear interpolation by your own if you wanna modify even multiple values over time/at rate and at one frame/at once, so you don’t need to rely on Chasing Operations for intensity variancy that heavily.

4 Likes

Thx for the replied. I’ll copy/try the Mapped Array version of the timer code you gave me. Experiment a little more with that. CHEERS!

1 Like

Haha, no I just had no time for workshop :wink:

2 Likes

So im having trouble duplicating your example with the cooldown. There isn’t a IF?Then/Else action. Only a condition. So via Overwatch scripts, how would I build that?..Nvm, i figured it out… The IF?thenElse is inside the Value section when setting a variable…Thanks again!

1 Like

It might look like this:

Variables
{
	player:
		0: TemporaryCooldowns
		1: Cooldowns
		2: ElapsedTime
}

actions
{
	Event Player.ElapsedTime = Total Time Elapsed;
	Event Player.TemporaryCooldowns = Mapped Array(Event Player.Cooldowns,
		Current Array Element > 0 ? Current Array Element - Event Player.ElapsedTime : Current Array Element);
}

In Mapped Array the second input tab is called expression, there you search or type in “if” as a keyword, If-Then-Else will occure and displayed, select it, then under that value’s If condition sub tab you express a condition which needs to be evaluated, under the Then input tab you define again any expression that might be an value or returns a single value, you do the same for the Else input tab. When the If Condition of If-Then-Else becomes true, all elements will be set to the value you defined in the Then tab, otherwise they will become the value defined in the Else tab. Be sure the Array you reference under Mapped Array is an Array and not Empty.