---
name: "buttonSetAction"
type: command
status: deprecated
replaced_by: ["ctrlAddEventHandler"]
groups: ["GUI Control"]
arma3_since: "0.50"
locality: {"argument": "local", "effect": "local", "server_exec": false}
source: https://community.bistudio.com/wiki/buttonSetAction
revid: 364179
updated: 2024-05-05T10:46:46Z
---

# buttonSetAction

*Command · GUI Control · Arma 3 v0.50 · introduced in Operation Flashpoint v1.75*

> [!WARNING]
> This command is deprecated. Use [ctrlAddEventHandler](../commands/ctrlAddEventHandler.md) instead.

Locality: arguments **local** · effect **local**

## Description

> [!CAUTION]
> This information is **obsolete**. Use [ctrlAddEventHandler](../commands/ctrlAddEventHandler.md) instead.

Set the action of a control of the currently active user dialog. The script statement is executed on button release and `_this` is available, but contains ""; See Arma: GUI Configuration for more information about user dialogs. Works with:
- CT_BUTTON
- CT_XBUTTON
- CT_ACTIVETEXT
- CT_SHORTCUTBUTTON

## Syntax

### Syntax 1

```sqf
buttonSetAction [idc, action]
```

**Parameters:**

- `idc`: [Number](../topics/Number.md) - button IDC
- `action`: [String](../topics/String.md) - **SQS** code body that should be executed when the button/active text is clicked

**Returns:** [Nothing](../topics/Nothing.md)

### Syntax 2

```sqf
control buttonSetAction action
```

**Parameters:**

- `control`:  [Control](../topics/Control.md) - button control
- `action`:  [String](../topics/String.md) - **SQS** code body that should be executed when the button/active text is clicked

**Returns:** [Nothing](../topics/Nothing.md)

## Examples

### Example 1

```sqf
buttonSetAction [100, "player exec ""reply.sqs"""];
```

### Example 2

```sqf
_ctrl buttonSetAction "if (alive bob) then {hint 'alive'} else {hint 'dead'}"; // SQF but SQS compatible, see SQS
```

### Example 3

Script is SQS:

```sqs
_control buttonSetAction "hint format ['Is SQS: %1', !isNil '_time']"
```

## See also

[buttonAction](../commands/buttonAction.md)

## Community notes

**Kungtotte** — 2009-10-05

When using buttonSetAction for an ActiveText control from a script, you cannot use any variables local to the script in it.

```sqf
/* This will print 'any bar' in the hint box,
 since _foo has no value according to buttonSetAction */

_foo = "foo";
buttonSetAction [100, "hint format [""%1 bar"", _foo];"];
```

---

**Molaron** — 2016-02-15

This command does not overwrite the button's action that was set via "action" in the `.hpp` of the dialog.

---

**Nomisum** — 2016-06-11

To use variables local to the defining script, a syntax like the one below needs to be used:

```sqf
_foo = "foo";
buttonSetAction [100, format ["hint '%1 bar'", _foo]];
```

works! thanks to Kronzky for commenting this workaround in the VBS wiki

<sub>Source: [BI Community Wiki — buttonSetAction](https://community.bistudio.com/wiki/buttonSetAction) (revision 364179).</sub>
