I've made some custom methods for working with arrays. They're mostly pretty simple, but handy to have in the toolbox. It's nice to share, so here they are! (Code below.)
And finally, here's all the code:
Cheers!
| ArraySplice(InputArray, SpliceIndex, DeleteLength, InsertArray) | ||||||
| Removes and inserts elements in an array and returns a copy of it. | InputArray | Array | The array to be modified | |||
| SpliceIndex | Int | The index of the first element to be deleted and the point to insert new elements | ||||
| DeleteLength | Int | The number of elements to be deleted, including the element at SpliceIndex | ||||
| InsertArray | Array | The array to be inserted (optional) | ||||
| ArraySlice(InputArray, SliceIndex, SliceLength) | ||||||
| Returns a portion of an array. | InputArray | Array | The array to be extracted from | |||
| SpliceIndex | Int | The index of the first element to be returned | ||||
| DeleteLength | Int | The number of elements to be returned, including the element at SliceIndex | ||||
| ArrayConcat(InputArray1, InputArray2) | ||||||
| Returns an array made by joining two arrays together. | InputArray1 | Array | The first array to join | |||
| InputArray2 | Array | The second array to join | ||||
| ArrayReverse(InputArray) | ||||||
| Returns an array that is the input array in reverse order. | InputArray | Array | The array to be reversed | |||
| ArraySort(InputArray, Descending) | ||||||
| Sorts a numeric array and returns a copy of it. | InputArray | Array | The array to sort. Must contain only numbers or integers | |||
| Descending | Boolean | If true, the sort will be from highest to lowest (optional) | ||||
| ObjectArraySort(InputArray, Descending, Renumber) | ||||||
| Sorts an array consisting of objects. | InputArray | Array | The array to sort. Must contain only objects, which must all have a property "Index" | |||
| This was made for a specific purpose. | Descending | Boolean | If true, the sort will be from highest to lowest (optional) | |||
| You may or may not find it useful! | Renumber | Boolean | If true, the objects' "Index" properties will be updated to reflect the new order (optional) | |||
And finally, here's all the code:
Code: WME Script
- method ArraySplice(InputArray,SpliceIndex,DeleteLength,InsertArray)
- {
- var i;
- if(DeleteLength == null) DeleteLength = 0;
- for(i = 0; i < SpliceIndex; i = i + 1)
- {
- }
- if(InsertArray != null)
- {
- {
- }
- }
- {
- }
- return ReturnArray;
- }
- method ArraySlice(InputArray,SliceIndex,SliceLength)
- {
- var i;
- for(i = SliceIndex; i < SliceIndex + SliceLength; i = i + 1)
- {
- }
- return ReturnArray;
- }
- method ArrayConcat(InputArray1,InputArray2)
- {
- var i;
- {
- }
- {
- }
- return ReturnArray;
- }
- method ArrayReverse(InputArray)
- {
- var i;
- {
- }
- return ReturnArray;
- }
- method ArraySort(InputArray,Descending)
- {
- var i;
- var ii;
- var InsertPos;
- var InsertArray;
- {
- InsertPos = -1;
- {
- if(InputArray[i] > ReturnArray[ii])
- {
- InsertPos = ii + 1;
- break;
- }
- }
- if(InsertPos > -1) ReturnArray = ArraySplice(ReturnArray,InsertPos,0,InsertArray);
- else ReturnArray = ArrayConcat(InsertArray,ReturnArray);
- }
- if(Descending) ReturnArray = ArrayReverse(ReturnArray);
- return ReturnArray;
- }
- method ObjectArraySort(InputArray,Descending,Renumber)
- {
- var i;
- var ii;
- var InsertPos;
- var InsertArray;
- var InputObject;
- var ReturnObject;
- {
- InsertPos = -1;
- InputObject = InputArray[i];
- {
- ReturnObject = ReturnArray[ii];
- if(InputObject.Index > ReturnObject.Index)
- {
- InsertPos = ii + 1;
- break;
- }
- }
- if(InsertPos > -1) ReturnArray = ArraySplice(ReturnArray,InsertPos,0,InsertArray);
- else ReturnArray = ArrayConcat(InsertArray,ReturnArray);
- }
- if(Descending) ReturnArray = ArrayReverse(ReturnArray);
- if(Renumber)
- {
- {
- ReturnObject = ReturnArray[i];
- ReturnObject.Index = i;
- ReturnArray[i] = ReturnObject;
- }
- }
- return ReturnArray;
- }
Cheers!






Logged


