Skip to main content

Array Commands

array_equal()

array_equal(<array-variable>,<array-variable>)

Checks the values of two arrays. True if all values are equal, false if not

Remarks

  • This command does not work with arrays of real numbers.

Examples

on init
	declare %array_1[10]
	declare %array_2[11]
	
	if (array_equal(%array_1,%array_2))
		message($ENGINE_UPTIME)
	end if
	
end on

This script will produce an error message as the two arrays don't have the same size

See Also

sort()

num_elements()

search()

num_elements()

num_elements(<array-variable>) 

Returns the number of elements in an array

Remarks

  • With this function you can, e.g., check how many groups are affected by the current event by using num_elements(%GROUPS_AFFECTED).

Examples

on note
	message(num_elements(%GROUPS_AFFECTED))
end on

Outputs the number of groups playing

See Also

array_equal()

sort()

search()

Events and MIDI: %GROUPS_AFFECTED

search()

search(<array-variable>,<value>)

Searches the specified array for the specified value and returns the index of its first position. If the value is not found, the function returns -1.

Remarks

  • This command does not work with arrays of real numbers.

Examples

on init
	declare ui_table %array[10] (2,2,5)
	declare ui_button $check
	set_text ($check,"Zero present?")
end on

on ui_control ($check)
	if (search(%array,0) = -1)
	 	message ("No")
	 else
	 	message("Yes")
	 end if
	 $check := 0
end on

Checking if a specific value is present

See Also 

array_equal()

num_elements()

sort()

sort()

sort(<array-variable>,<direction>)

Sorts an array in ascending or descending order.

<array-variable>

The array to be sorted

<direction>

With direction = 0, the array is sorted in ascending order

With direction # 0, the array is sorted in descending order

Examples

on init
	declare $count
	declare ui_table %array[128] (3,3,127)
	
	while ($count < 128)
		%array[$count] := $count
		inc($count)
	end while
	declare ui_button $Invert
	
end on

on ui_control ($Invert)
	sort(%array,$Invert)
end on

Quickly inverting a linear curve display

See Also 

array_equal()

num_elements()

sort()