Moving array elements up one value to insert a new value at the beginning of the array can be a bit tedious to code. If the array has been switched around so that element 0 is the right most element then an extra degree of frustration is added to the issue.
This is how I solved the problem for my current project.
Let’s assume we have a dynamic array of 100 structures elements and the rightmost element is 0.
Code: Select all
struct TestStruct
{
int value1;
double value2;
string value3;
};
TestStruct Test[]
ArrayResize(Test, 100); // Give it a size of 100
ArraySetAsSeries(Test, true); // Turn the array around so the element 0 is the far right one
The easiest way to do this that I have found is as follows.
Code: Select all
// Set the array to read from left to right as a normal array does
ArraySetAsSeries(Test, false);
// Add a new empty element to the end
ArrayResize(Test, 101);
// Set the array to read from right to left similar to the bars on a chart
ArraySetAsSeries(Test, true);
// Now the array has been turned around delete the last element
ArrayResize(Test, 100);
Done