Enfusion Script API
Loading...
Searching...
No Matches
Public Member Functions | List of all members
array< Class T > Interface Template Reference
Inheritance diagram for array< Class T >:
[legend]

Public Member Functions

proto native int Count ()
 O(1) complexity.
 
proto native bool IsEmpty ()
 
proto native void Clear ()
 Destroys all elements of the array and sets the Count to 0.
 
proto native void Compact ()
 Frees any underlying memory which is not used.
 
proto void Set (int n, T value)
 Sets n-th element to given value.
 
proto int Find (T value)
 Tries to find the first occurrence of value in the array.
 
proto bool Contains (T value)
 Returns whether value is in array or not.
 
proto T Get (int n)
 
proto int Insert (T value)
 Inserts element at the end of array.
 
proto int InsertAt (T value, int index)
 Inserts element at certain position and moves all elements behind this position by one.
 
void InsertAll (notnull array< T > from)
 Inserts all elements from array.
 
proto native void Remove (int index)
 Removes element from array.
 
proto native void RemoveOrdered (int index)
 Removes element from array, but retains all elements ordered.
 
proto native void Resize (int newSize)
 Resizes the array to given size.
 
proto native void Reserve (int newSize)
 Reserve memory for given number of elements.
 
proto native void Swap (notnull array< T > other)
 Swaps the contents of this and other arrays.
 
proto native void Sort (bool reverse=false)
 Sorts elements of array, depends on underlying type.
 
proto native bool IsIndexValid (int index)
 Returns whether provided element index of array is valid.
 
proto int Copy (notnull array< T > from)
 Copies contents of from array to this array.
 
proto int Init (T init[])
 
proto bool RemoveItem (T value)
 Removes element from array.
 
proto bool RemoveItemOrdered (T value)
 Removes element from array, but retain all elements ordered.
 
void Debug ()
 Print all elements in array.
 
int GetRandomIndex ()
 Returns a random index of array.
 
GetRandomElement ()
 Returns a random element of array.
 
void SwapItems (int item1_index, int item2_index)
 
- Public Member Functions inherited from Managed
proto external ref Managed Clone ()
 Return shallow copy of object, or null if it is not allowed (not public constructor)
 

Member Function Documentation

◆ Clear()

proto native void array< Class T >.Clear ( )

Destroys all elements of the array and sets the Count to 0.

The underlying memory of the array is not freed.

◆ Compact()

proto native void array< Class T >.Compact ( )

Frees any underlying memory which is not used.

For example if the array allocated enough memory for 100 items but only 1 is used (Count() is 1) this frees the memory taken by the remaining 99 items.

Warning
Memory allocation and deallocation are expensive so only use this function if you know you won't be adding new items to the array on frame-by-frame basis or when the memory consumption is of utmost importance.

◆ Contains()

proto bool array< Class T >.Contains ( value)

Returns whether value is in array or not.

Note
This method has complexity O(n).

◆ Copy()

proto int array< Class T >.Copy ( notnull array< T >  from)

Copies contents of from array to this array.

Returns
Number of elements copied.

◆ Count()

proto native int array< Class T >.Count ( )

O(1) complexity.

Returns
Number of elements of the array

◆ Debug()

void array< Class T >.Debug ( )

Print all elements in array.

my_array.Debug();
>> "One"
>> "Two"
>> "Three"

◆ Find()

proto int array< Class T >.Find ( value)

Tries to find the first occurrence of value in the array.

Returns
Index of the first occurrence of value if found, -1 otherwise.
Note
This method has complexity O(n).

◆ Get()

proto T array< Class T >.Get ( int  n)
Returns
Element at the index n.

◆ GetRandomElement()

T array< Class T >.GetRandomElement ( )

Returns a random element of array.

Returns
Random element of array.

Example:

Print( my_array.GetRandomElement() );
>> "Three"
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.

◆ GetRandomIndex()

int array< Class T >.GetRandomIndex ( )

Returns a random index of array.

If Count is 0, returned index is -1.

Returns
Random index of array.

Example:

Print( my_array.GetRandomIndex() );
>> 2

◆ Init()

proto int array< Class T >.Init ( init[])

◆ Insert()

proto int array< Class T >.Insert ( value)

Inserts element at the end of array.

Parameters
valueElement to be inserted.
Returns
Position at which element is inserted.

◆ InsertAll()

void array< Class T >.InsertAll ( notnull array< T >  from)

Inserts all elements from array.

Parameters
fromarray from which all elements will be added.

Example:

arr1.Insert( "Dave" );
arr1.Insert( "Mark" );
arr1.Insert( "John" );
arr2.Insert( "Sarah" );
arr2.Insert( "Cate" );
arr1.InsertAll(arr2);
for ( int i = 0; i < arr1.Count(); i++ )
{
Print( arr1.Get(i) );
}
>> "Dave"
>> "Mark"
>> "John"
>> "Sarah"
>> "Cate"
array< string > TStringArray
Definition: Types.c:380
void InsertAll(notnull array< T > from)
Inserts all elements from array.
Definition: Types.c:245
proto native int Count()
O(1) complexity.
proto T Get(int n)
proto int Insert(T value)
Inserts element at the end of array.

◆ InsertAt()

proto int array< Class T >.InsertAt ( value,
int  index 
)

Inserts element at certain position and moves all elements behind this position by one.

Parameters
valueElement to be inserted.
indexPosition at which element is inserted. Must be less than Count().
Returns
Number of elements after insertion.

◆ IsEmpty()

proto native bool array< Class T >.IsEmpty ( )
Returns
true if the array size is 0, false otherwise.

◆ IsIndexValid()

proto native bool array< Class T >.IsIndexValid ( int  index)

Returns whether provided element index of array is valid.

◆ Remove()

proto native void array< Class T >.Remove ( int  index)

Removes element from array.

The empty position is replaced by last element, so removal is quite fast but does not retain order.

Parameters
indexIndex of element to be removed

◆ RemoveItem()

proto bool array< Class T >.RemoveItem ( value)

Removes element from array.

The empty position is replaced by last element, so removal is quite fast but does not retain order.

Returns
true if item was removed

◆ RemoveItemOrdered()

proto bool array< Class T >.RemoveItemOrdered ( value)

Removes element from array, but retain all elements ordered.

It's slower than RemoveItem().

Returns
true if item was removed

◆ RemoveOrdered()

proto native void array< Class T >.RemoveOrdered ( int  index)

Removes element from array, but retains all elements ordered.

It's slower than Remove().

Parameters
indexIndex of element to be removed.

◆ Reserve()

proto native void array< Class T >.Reserve ( int  newSize)

Reserve memory for given number of elements.

This method is used for optimization purposes when the approximate size is known beforehand.

◆ Resize()

proto native void array< Class T >.Resize ( int  newSize)

Resizes the array to given size.

If the newSize is lower than current Count overflowing objects are destroyed. If the newSize is higher than current Count missing elements are initialized to zero (null).

◆ Set()

proto void array< Class T >.Set ( int  n,
value 
)

Sets n-th element to given value.

◆ Sort()

proto native void array< Class T >.Sort ( bool  reverse = false)

Sorts elements of array, depends on underlying type.

◆ Swap()

proto native void array< Class T >.Swap ( notnull array< T >  other)

Swaps the contents of this and other arrays.

Does not involve copying of the elements.

◆ SwapItems()

void array< Class T >.SwapItems ( int  item1_index,
int  item2_index 
)

The documentation for this interface was generated from the following file: