Home Forums Logelloop 6 (English spoken) How to create arrays in macros ? Reply To: How to create arrays in macros ?

#6696
Christophe BChristophe B
Keymaster

Hello, here are some hints to manipulate arrays:
(first, initialize Logelloop’s metronome in order to have a value other than zero in the system variable $metro_bar_beats$)

// Declare a variable as array
Declare int $beats[0]$ = 0

Declare int $n$ = 0

// Initialize
DoRepeat

	$beats[n]$ = { randomBool(0.5) ? 1 : 0 }
	$n$ = { $n$ + 1 }

While { $n$ < $metro_bar_beats$ }
// Display in console
$n$ = 0
DoRepeat

	Post $beats[n]$
	$n$ = { $n$ + 1 }

While { $n$ < $metro_bar_beats$ }
// Access an unitizialized position will return a default value
$n$ = $metro_bar_beats$
Post { "Uninitialized: " + $beats[n]$ }

1- Declare a variable as array with proper data type.
2- Use it. Unitialized cells will have a default value.
3- There is no notion of array length.