{"name":"buttonSetAction","title":"buttonSetAction","type":"command","url":"https://community.bistudio.com/wiki/buttonSetAction","revid":364179,"updated":"2024-05-05T10:46:46Z","groups":["GUI Control"],"status":"deprecated","replaced_by":["ctrlAddEventHandler"],"games":{"ofp":"1.75","ofpe":"1.00","arma1":"1.00","arma2":"1.00","arma2oa":"1.50","tkoh":"1.00","arma3":"0.50"},"since":"ofp 1.75","arma3_since":"0.50","locality":{"argument":"local","effect":"local"},"description":"> [!CAUTION]\n> This information is **obsolete**. Reason: Use ctrlAddEventHandler instead.\n\nSet 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:\n\n- CT_BUTTON\n- CT_XBUTTON\n- CT_ACTIVETEXT\n- CT_SHORTCUTBUTTON","syntaxes":[{"syntax":"buttonSetAction [idc, action]","params":[{"name":"idc","type":"Number","description":"button IDC","type_expr":"Number"},{"name":"action","type":"String","description":"**SQS** code body that should be executed when the button/active text is clicked","type_expr":"String"}],"returns":{"type":"Nothing","type_expr":"Nothing"},"form":"unary","right":{"text":"[idc, action]"}},{"syntax":"control buttonSetAction action","params":[{"name":"control","type":"Control","description":"button control","type_expr":"Control"},{"name":"action","type":"String","description":"**SQS** code body that should be executed when the button/active text is clicked","type_expr":"String"}],"returns":{"type":"Nothing","type_expr":"Nothing"},"form":"binary","left":{"text":"control"},"right":{"text":"action"}}],"examples":[{"code":["buttonSetAction [100, \"player exec \"\"reply.sqs\"\"\"];"]},{"code":["_ctrl buttonSetAction \"if (alive bob) then {hint 'alive'} else {hint 'dead'}\"; // SQF but SQS compatible, see SQS"]},{"text":"Script is SQS:\n\n```sqs\n_control buttonSetAction \"hint format ['Is SQS: %1', !isNil '_time']\"\n```","code":["_control buttonSetAction \"hint format ['Is SQS: %1', !isNil '_time']\""]}],"see_also":["buttonAction"],"notes":[{"user":"Kungtotte","date":"2009-10-05T16:23:00Z","text":"When using buttonSetAction for an ActiveText control from a script, you cannot use any variables local to the script in it.\n\n```sqf\n/* This will print 'any bar' in the hint box,\n since _foo has no value according to buttonSetAction */\n\n_foo = \"foo\";\nbuttonSetAction [100, \"hint format [\"\"%1 bar\"\", _foo];\"];\n```"},{"user":"Molaron","date":"2016-02-15T10:15:00Z","text":"This command does not overwrite the button's action that was set via \"action\" in the `.hpp` of the dialog."},{"user":"Nomisum","date":"2016-06-11T19:24:00Z","text":"To use variables local to the defining script, a syntax like the one below needs to be used:\n\n```sqf\n_foo = \"foo\";\nbuttonSetAction [100, format [\"hint '%1 bar'\", _foo]];\n```\n\nworks! thanks to Kronzky for commenting this workaround in the VBS wiki"}]}