Jump to content
JackPan

How to get "action" parameters value

Recommended Posts

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?

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
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

Edited by bigWeld33
corrected any instances of the word "event" to "command"

Share this post


Link to post
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?

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


×