Confused / String Array and Table Parameters

String Array:

I made a parameter like this

defineParameter("beatDiv", nil, 1, {"1/1", "1/2", "1/4", "1/8", "1/16"}, function() beatDivChange() end)

My plan was to use string.sub() and tonumber() to retrieve the denominator for use in calculations. The manual doesn’t say parameter “array” values can be accessed, but I assumed this from reading about table parameters. In this case print(beatDiv[1]) returns an error. Print(beatDiv) does show the current index value though.

My question is, do I use the returned index values from the array parameter to access a second table with values for calculations when beatDivChange() is called.

It seemed clumsy at first, but it looks like the only way.

Table Parameter:

I made this as a test

defineParameter("tabParam", nil, {10, 20, 30}, function() tabParamChange() end)

I tied this to a knob thinking it would give me 10, 20, 30 stepped values, but it didn’t work. The knob is stuck either at min. or max position.

I then tied it to a menu, but this came out.

I added 40, 50, 60 , but still only 2 menu options.

The manual says table parameter values can be accessed via indices, which works, print(tabParam[2]) => 20.
But I don’t see how to do this on a variable basis if the parameter doesn’t return either the table or index value.

I haven’t been able to find an example of table parameter use, so if someone can point me in the right direction I would be extremely grateful.

I’m a cat’s whisker away from completing my first instrument, I just need to figure this out.

Hi AposMus,

the parameter beatDiv is a number and not a table. Try this with your original code:


The table with strings is used for the display. For example, if you connect beatDiv to a text field, HALion will display the strings and not the index.

If you create separate tables for the beat strings and beat lengthes, you can use beatDiv to reference them.

Try this code:

local beatValue = { 4, 2, 1, 0.5, 0.25 }
local beatString = { "1/1", "1/2", "1/4", "1/8", "1/16" }

defineParameter("beatDiv", nil, 1, beatString, function() onBeatDivChanged() end )

function onBeatDivChanged()
	print(beatString[beatDiv].." = "..beatValue[beatDiv])

This is more tidy and more flexible, I think.



[EDIT]: You must execute this code in the Lua Script module, btw.
[EDIT2]: Corrected beat values.

good stuff, guys=)

please forgive my ignorance, but… what are the calculations for decimal values for triplets and dotted?

like 1/16t or 1/8d

thxZZZzzz n good night :stuck_out_tongue:

Triplet = x / 3 * 2 or x * 0.666
Dotted = x / 2 * 3 or x * 1.5

@ Matthias Klag

Thanks for this. It’s roughly what I had in mind. I didn’t think of putting the parameter array outside the function, but I can see why you did it.

I forgot to mention it was connected to a menu controller, which is how the print function was triggered.

Is there any chance you can give us some insight as to how the number table parameter works. As you can see from my screen cap and previous explanation, I couldn’t get it to work and haven’t seen it in use in the provided macros.

Hi AposMus.

As far as I can tell, the table parameters are not for connecting them to a control on the MacroPage. I think, their main use is for storing data directly with the Lua Script module when the program is saved. If you use a normal Lua table to store some data, for example, some MIDI notes you played, this table won’t get stored with the program. If you declare a table parameter with defineParameter, the data of this parameter will get stored with the Lua Script module when you save the program.

Please use the Indexed String Array, if you want to display different values in menus or text fields.



In an earlier post, I gave the following example for beat values and strings:

local beatValue = { 1, 0.5, 0.25, 0.125, 0.0625 }
local beatString = { "1/1", "1/2", "1/4", "1/8", "1/16" }

I made a small error:

“1/1” refers to a whole bar, which equals 4 beats. So, the beat values should be 4 , 2, 1, and so on.

I edited this in my original post.



Thanks for all the great information, this is truly helping a lot.

You’re welcome :slight_smile:

Btw, in another post I read something from you about the controller functions. I think, you wrote that controller functions must be executed in the UI script. But, that’s not the case.

Controller and processor function both can be called in the Lua Script MIDI module. That said, controller functions can be called in the Lua Script MIDI module and the UI script. Only the processor functions cannot be called in the UI script.

The scripts for the Lua Script MIDI module and the UI can be seen as two different worlds. The script in the MIDI module controls what’s happening in the Program. The UI script controls what’s happening on the UI. In our instruments we did the majority of the scripting in the MIDI module. The UI script was only used to control page switching, etc.

I’m not sure if that was clear. That’s why i posted this here…



Yes, I was trying to help with lulu m’s script which didn’t run in Sonic and was thinking of what you said about getElement(), but I wasn’t sure I was right though.

The manual’s thread section talks about “controller” and “processor”, so I thought - UI and module. I ran a few versions of lulu m’s script with initialisation functions to see if it helped and got some errors. I know where I wen’t wrong now. A controller function can run in the Script Module, but not inside a processor function. (unless you use runAsync()).

I didn’t pay attention to the block comment in the first example where this was explained.

In our instruments we did the majority of the scripting in the MIDI module. The UI script was only used to control page switching, etc.

I noticed this after a while when things became less confusing.