Jump to content
C4 Forums | Control4

How to get "action" parameters value


JackPan

Recommended Posts

  • 2 weeks later...

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

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

  • 3 months later...
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

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: 

image.png.1349079fbf1ac6ed658fc88610eeec8b.png

 

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

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.