Issue with User Properties and IF/ELSE Statements

Peer support for Air Manager desktop users

Moderators: russ, Ralph

Post Reply
Message
Author
JockMunro
Posts: 54
Joined: Sun Dec 02, 2018 2:53 pm

Issue with User Properties and IF/ELSE Statements

#1 Post by JockMunro »

Hi all,

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
In scenario 1 with the 'Test button' field checked I get the following results:
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
In scenario 2 with 'response' set to TRUE I get the following results:
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

User avatar
Sling
Posts: 5237
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

Re: Issue with User Properties and IF/ELSE Statements

#2 Post by Sling »

Hi Jock,

I've come across this before. Probably mentioned on the forum someplace.

This one is an oddity of AM's pre scan of the instrument script. It pre scans the script so it can populate the Properties and Hardware properties tabs. Because the user property has not officially been run at this point the if..else will see response as false. During the actual run the user property is read and the if..else will see correctly whatever the user has selected. The Hardware tab always shows correctly because it is only populated upon actual instrument run and not the pre scan.

@Corjan will have to comment further on a possible fix.

Tony

JockMunro
Posts: 54
Joined: Sun Dec 02, 2018 2:53 pm

Re: Issue with User Properties and IF/ELSE Statements

#3 Post by JockMunro »

Hi Tony,

Thanks for your reply. It doesn't stop anything thankfully, I can just place the configurations directly into the code. More important for code that's going to be released publicly though where we don't want users digging around in the code.

Cheers

Jock

Post Reply