Got a question that the wiki doesn't answer? Ask on the forum (preferred), or join us on IRC.

BeastNode

CommandHelper/Staged/API/array push

From EngineHub.org Wiki
Jump to: navigation, search



Vital Info

Name array_push
Returns void
Usages array, value, [value2...]
Throws CastException
Since 3.0.1
Restricted
No
Optimizations None

Description

Pushes the specified value(s) onto the end of the array. Unlike calling array_set(@array, array_size(@array), @value) on a normal array, the size of the array is increased first. This will therefore never cause an IndexOverflowException. The special operator syntax @array[] = 'value' is also supported, as shorthand for array_push().

Usages

array_push(array, value, [value2...])

Examples (How do these work?)

Example 1

Operator syntax. Note the difference between this and the array clone operator is that this occurs on the Left Hand Side (LHS) of the assignment.

Given the following code:

1   array @array = array();
2   @array[] = 'new value';


The output would be:

:{new value}

Example 2

Demonstrates functional usage

Given the following code:

1   array @array = array();
2   msg(@array);
3   array_push(@array, 0);
4   msg(@array);


The output would be:

{}
{0}

Example 3

Demonstrates pushing multiple values (note that it is not possible to use the bracket notation and push multiple values)

Given the following code:

1   array @array = array();
2   msg(@array);
3   array_push(@array, 0, 1, 2);
4   msg(@array);


The output would be:

{}
{0, 1, 2}


See Also

array_set



Navigation menu