Custom:Variables

From Unified Remote

Jump to: navigation, search

In 2.1.2 variables can be defined in custom remotes. This allows you to create significantly more complex custom remotes.

Contents

Defining

Variables are defined and used with the pre-defined "#set" action:

<ActionRef Name="#set" Target="var" Extra="val" />

The Target attribute specifies the name of the variable to set. The Extra attribute specifies the value to assign to the variable.

Globals

Global variables are created when the "#set" action is called outside of an "Action" tag.

<Actions>
  <ActionRef Name="#set" Target="global" Extra="this is a global" />
</Actions>

Globals can be accessed and changed from any other action.

Locals

Local variables are created when the "#set" action is called inside an "Action" tag.

<Actions>
  <Action Name="action">
    <ActionRef Name="#set" Target="local" Extra="this is a local" />
  </Action>
</Actions>

Locals can only be accessed and changed inside the action it was defined in.

Pre-defined

Some globals are pre-defined by the server:

  • __file__: Filename of the custom remote
  • __dir__ : Directory where the custom remote is
  • __name__: Name of the custom remote file

Using

A variable is referenced using dollar-sign naming (i.e. $var):

<Actions>
  <ActionRef Name="#set" Target="who" Extra="World" />
  <ActionRef Name="#set" Target="msg" Extra="Hello $who!" />
</Actions>

The example above will assign "World" to the $who, and will assign "Hello World!" to $msg.

Variables can also be used in Extras in any other action:

<Actions>
  <Action Name="foo">
    <ActionRef Name="stroke" Target="input" Extra="$msg" />
  </Action>
</Actions>

The example above will send the value of $msg to the "stroke" action.

Note that when referencing variables, if there exists a local and a global with the same name, the local will be used.

Controls

The "#set" action can also be used to change controls in your layout:

<Actions>
  <Action Name="foo">
    <ActionRef Name="#set" Target="myLabel.text" Extra="$msg" />
  </Action>
</Actions>

The example above will assign the value of the $msg variable to the text property of a control with ID "myLabel".

Supported properties: text, checked.

Actions

Some actions may return a result. If so, the value will be assigned to the $res variable.

<Actions>
  <Action Name="foo">
    <ActionRef Name="read" Target="io">
      <Extra Name="file">C:/test.txt</Extra>
    </AciontRef>
    <ActionRef Name="msg" Target="util" Extra="$res" />
  </Action>
</Actions>

The example above will show the contents of the file in a message box.

Extras

Extras passed to an action are automatically assigned to variables. They can be referenced by name or index.

<Actions>
  <Action Name="test">
    <ActionRef Name="msg" Target="util" Extra="First: $0" />
    <ActionRef Name="msg" Target="util" Extra="Second: $1" />
    <ActionRef Name="msg" Target="util" Extra="Second: $number_two" />
  </Action>

  <Action Name="onButtonClicked">
    <ActionRef Name="test">
      <Extra>Not Named</Extra>
      <Extra Name="number_two">Named</Extra>
    </ActionRef>
  </Action>
<Actions>

The example above will run the "test" action when the "onButtonClicked" action is called. It will pass two extras to the "test" action, which are accessed using $0 (index), $1 (index), and $number_two (name). In this case, "test" acts like a function.

Personal tools