for (int i=0; i<10; i++)
{
CreateIcon(..., VecArr[i], (visible to, position))
}
Problem of this code is Icon position keep tracking VecArr[i] which changes every loop. When I set reevaluation to visible to, I can’t destroy using position.
Vector of every icon is VecArr[9]!
How can I set vector of icon to VecArr[0], VecArr[1], VecArr[2], …?
Reason I do this is I make VecArr (array of vector) of random vectors.
So, How can I connect Icon[1] to VecArr[1]? it looks like map data type.
Is your index of the icon position variable also are variable?
I mean like…
Icon[Variable.A]
not Icon[1]
Yes, I make icons in this code:
for (Global.i, 0, arr_size, 1)
CreateIcon(VecArr[i])
or
for (Global.i, 0, arr_size, 1)
Global.temp = VecArr[i]
CreateIcon(Global.temp)
but this code doesn’t save VecArr[i] in icon, it chases value in variable VecArr[i] or Global.temp. I want to make VecArr[i] as constant valule.
C language support const int a = var[i];
but workshop script seems not support this.
Ah… I see what you mean.
It seem will make all the create function always end the same result.
I scary the ‘For’ function for that case too.
I use ‘While’ instead, cost a little more resource but no more confuse.
Only use ‘For’ when read data.
I’m not a pro, don’t know this is normal or not.
Whenever you create an icon, first add the random position to your position array
Modify Global Variable(IconPositionArray, Append To Array, Vector(0, 0, 0));
And then right after that, create the Icon using the last position of that array and add that icon to your icon array so you can destroy it later
Create Icon(All Players(All Teams), Global.IconPositionArray[Count Of(Global.IconPositionArray) - 1], Circle,
Visible To and Position, White, True);
Modify Global Variable(IconReferenceArray, Append To Array, Last Created Entity);
Now, If you only use these two arrays like this, the icon and its random position will always be at the same index of both arrays and you can easily delete both at the same time.
Modify Global Variable(IconPositionArray, Remove From Array By Index, x);
Destroy Icon(Global.IconReferenceArray[x]);
Modify Global Variable(IconReferenceArray, Remove From Array By Index, x);
Once the PTR hits live you can use “evaluate once” to fix that problem.
Workshop script takes the value of
Global.IconPositionArray[CountOf(Global.IconPositionArray)-1]
as variable, not constant value because CountOf(Global.IconPositionArray) changes when loop increment i++, at last all Icons vector have same vector of
Global.IconPositionArray[9]
After running the code, only one ring appears on the map.
If evaluation is set to “None”, loop seems to work.
variables
{
global:
1: IconPositionArray
2: IconReferenceArray
}
rule("Rule 1")
{
event
{
Ongoing - Each Player;
All;
All;
}
conditions
{
Is Button Held(Event Player, Interact) == True;
}
actions
{
For Global Variable(A, 0, 8, 1);
Modify Global Variable(IconPositionArray, Append To Array, Vector(Random Integer(-5, 5), 2, Random Integer(-5, 5)));
Create Icon(All Players(All Teams), Global.IconPositionArray[Count Of(Global.IconPositionArray) - 1], Diamond, None, White, True);
Modify Global Variable(IconReferenceArray, Append To Array, Last Created Entity);
End;
Wait(2, Ignore Condition);
While(Count Of(Global.IconReferenceArray) > 0);
Modify Global Variable(IconPositionArray, Remove From Array By Index, Count Of(Global.IconPositionArray) - 1);
Destroy Icon(Global.IconReferenceArray[Count Of(Global.IconReferenceArray) - 1]);
Modify Global Variable(IconReferenceArray, Remove From Array By Index, Count Of(Global.IconReferenceArray) - 1);
End;
}
}