JackPan Posted May 19, 2017 Share Posted May 19, 2017 I created an "action" which name is "time" in "config/actions" and added a parameter: "second" with RANGED_INTEGER, How to get parameter "second " value when I pressed the "time" button? Link to comment Share on other sites More sharing options...
Axxess Industries Support Posted June 1, 2017 Share Posted June 1, 2017 Hello JackPan, When you execute an action that you have defined in the config/actions portion of the XML script, it will call the function ExecuteCommand( strCommand, tParams ) in your lua script. The ExecuteCommand function gives you the Command String and the Table of Parameters as arguments to the function. If your command is named "time", and your parameter is named "second", then the strCommand argument will be given the value "time", and the parameter table will have an entry with the index "second", and the element at that table index will hold the value that the user entered into the command in the C4 Programming area. Here is an example as to how you would get the "second" parameter value in your lua script: function ExecuteCommand( strCommand, tParams ) if strCommand == "time" then --If the Command String/Name is equal to "time" local secondVal = tParams[ "second" ] --Get "second" parameter from Parameter Table end end The same goes for any other parameters you decide to add to the command you defined in the XML script. Hopefully this was helpful! Cheers, Alex Link to comment Share on other sites More sharing options...
JackPan Posted June 2, 2017 Author Share Posted June 2, 2017 Thank you very much! Link to comment Share on other sites More sharing options...
RyanE Posted June 3, 2017 Share Posted June 3, 2017 In case of actions, the initial command is 'LUA_ACTION', and the parameter name is 'ACTION'. So if your action is called 'time', you would do this: function ExecuteCommand(strCommand, tParams) if (strCommand == "LUA_ACTION") then local action = tParams["ACTION"] or "" if (action == "time") then -- Do the time action... end end end RyanE Link to comment Share on other sites More sharing options...
emaxedon Posted September 18, 2017 Share Posted September 18, 2017 On 6/3/2017 at 5:09 AM, RyanE said: In case of actions, the initial command is 'LUA_ACTION', and the parameter name is 'ACTION'. So if your action is called 'time', you would do this: function ExecuteCommand(strCommand, tParams) if (strCommand == "LUA_ACTION") then local action = tParams["ACTION"] or "" if (action == "time") then -- Do the time action... end end end RyanE How would we get the "second" parameter value from a LUA_ACTION? Link to comment Share on other sites More sharing options...
Axxess Industries Support Posted September 18, 2017 Share Posted September 18, 2017 2 hours ago, emaxedon said: How would we get the "second" parameter value from a LUA_ACTION? The "Actions" that are referred to are the actions defined in the XML portion of the driver like so: <actions> <action> <name>Request Radio Version</name> <command>Request Radio Version</command> </action> </actions> That definition will create a button in the 'Actions' tab of your driver: When you click that action button, it will call the ExecuteCommand() function in your driver with the parameters RyanE mentioned, and that's all. Since it is an action button with no other parameters to modify, there is only one parameter, tParams["ACTION"], which contains the name of the action as defined in the XML. So, if ExecuteCommand() is called because the user pressed an Action button in the Actions tab, strCommand will be "LUA_ACTION" and the only parameter will be tParams[ "ACTION" ]. If ExecuteCommand() is called because a pre-defined command was fired, then strCommand will be the name of the command that was fired, and the tParams table will contain all the parameters that you defined for that command, as described in my first reply. It's important to know the differences between Action Buttons and Commands, and try not to be confused by the fact that they both use the same callback function. Hope that helps! Cheers, Alex Link to comment Share on other sites More sharing options...
RyanE Posted September 18, 2017 Share Posted September 18, 2017 What Alex is calling 'events', are really 'commands'. Events are something entirely different. RyanE Link to comment Share on other sites More sharing options...
Axxess Industries Support Posted September 18, 2017 Share Posted September 18, 2017 Thanks for the clarification, Ryan. My bad on that one. I edited my response to avoid confusion. Link to comment Share on other sites More sharing options...
emaxedon Posted September 19, 2017 Share Posted September 19, 2017 Are there different kind of user input elements we can create under the "Actions" tab? For instance, something similar to a HTML form element, where there is a submit button with textfields we can pass as arguments. Or are Actions limited to only buttons? Link to comment Share on other sites More sharing options...
msgreenf Posted September 19, 2017 Share Posted September 19, 2017 2 minutes ago, emaxedon said: Are there different kind of user input elements we can create under the "Actions" tab? For instance, something similar to a HTML form element, where there is a submit button with textfields we can pass as arguments. Or are Actions limited to only buttons? buttons only Link to comment Share on other sites More sharing options...
Axxess Industries Support Posted September 19, 2017 Share Posted September 19, 2017 You could do something similar by making a Property field that holds whatever text you want to pass, and when the Action button is pressed just grab the value in the Property field instead of expecting an argument to be passed in the tParams table. Not as elegant as it would be to have a text box in the Actions tab but there is almost always a workaround to accomplish what you want with C4 drivers. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.