Ver: AM 4.0.2
Windows 10 64
I've been writing a script for a button array where the user can choose to use a button array or a conventional pin-per-button hardware configuration. I thought I would be able to use user_prop_add/user_prop_get functions to select the relevant code in an IF/ELSE statement but the functionality does not seem to work as I expect.
I can best explain what is happening with some test examples. (For simplicity I've used hw_button_add which behaves the same way as hw_button_array_add) :
Code: Select all
------Scenario one-------
testbox = user_prop_add_boolean("Test button", false, "Make your choice")
response = user_prop_get(testbox)
print("User choice is " .. tostring(response))
function button_pressed()
print("button pressed")
end
if response == true then
print("True logic triggered: " .. tostring(response))
my_button1 = hw_button_add("Test_Button1", button_pressed)
else
print("False logic triggered: " .. tostring(response))
my_button2 = hw_button_add("Test_Button2", button_pressed)
end
Console: 'User choice is true', 'True logic triggered: true' - CORRECT
Hardware Properties Tab: 'Button: Test_Button2' - INCORRECT (The ELSE code is being parsed)
Hardware Tab: Button - 'Test_Button1' - CORRECT (The IF code is being parsed)
In scenario 1 with the 'Test button' field UNchecked I get the following results:
Console: 'User choice is false', 'False logic triggered: false' - CORRECT
Hardware Properties Tab: 'Button: Test_Button2' - CORRECT
Hardware Tab: Button - 'Test_Button2' - CORRECT
If I don't use the user property functions to make the choice but choose from within the code itself by setting a variable everything works as expected:
Code: Select all
------Scenario Two-------
response = false
function button_pressed()
print("button pressed")
end
if response == true then
print("True logic triggered: " .. tostring(response))
my_button1 = hw_button_add("Test_Button1", button_pressed)
else
print("False logic triggered: " .. tostring(response))
my_button2 = hw_button_add("Test_Button2", button_pressed)
end
Console: 'True logic triggered: true' - CORRECT
Hardware Properties Tab: 'Button: Test_Button1' - CORRECT
Hardware Tab: Button - 'Test_Button1' - CORRECT
In scenario 2 with 'response' set to FALSE I get the following results:
Console: 'False logic triggered: false' - CORRECT
Hardware Properties Tab: 'Button: Test_Button2' - CORRECT
Hardware Tab: Button - 'Test_Button2' - CORRECT
Questions
Is there some restriction within the User Properties fuctionality that I have misunderstood? Or is it a bug? It's not a big deal but I was hoping to keep all user configuration on the Properties tab without users having to edit the code.
Cheers