{"name":"buttonSetAction","operator":null,"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":[{"game":"ofp","name":"Operation Flashpoint","version":"1.75"},{"game":"ofpe","name":"Operation Flashpoint: Elite","version":"1.00"},{"game":"arma1","name":"Armed Assault","version":"1.00"},{"game":"arma2","name":"Arma 2","version":"1.00"},{"game":"arma2oa","name":"Arma 2: Operation Arrowhead","version":"1.50"},{"game":"tkoh","name":"Take On Helicopters","version":"1.00"},{"game":"arma3","name":"Arma 3","version":"0.50"}],"since":{"game":"ofp","name":"Operation Flashpoint","version":"1.75"},"arma3_since":"0.50","branch":null,"locality":{"argument":"local","effect":"local","server_exec":false},"exec":null,"description":"> [!CAUTION]\n> This information is **obsolete**. 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- CT_BUTTON\n- CT_XBUTTON\n- CT_ACTIVETEXT\n- CT_SHORTCUTBUTTON","syntaxes":[{"syntax":"buttonSetAction [idc, action]","since":null,"effect":null,"exec":null,"params":[{"name":"idc","type":"Number","optional":false,"default":null,"description":"button IDC","types":["Number"],"since":null,"text":"idc: Number - button IDC"},{"name":"action","type":"String","optional":false,"default":null,"description":"**SQS** code body that should be executed when the button/active text is clicked","types":["String"],"since":null,"text":"action: String - **SQS** code body that should be executed when the button/active text is clicked"}],"returns":{"type":"Nothing","types":["Nothing"],"description":null,"text":"Nothing"},"form":"unary","operator":null,"left":null,"right":{"text":"[idc, action]","types":["Array"]}},{"syntax":"control buttonSetAction action","since":null,"effect":null,"exec":null,"params":[{"name":"control","type":"Control","optional":false,"default":null,"description":"button control","types":["Control"],"since":null,"text":"control:  Control - button control"},{"name":"action","type":"String","optional":false,"default":null,"description":"**SQS** code body that should be executed when the button/active text is clicked","types":["String"],"since":null,"text":"action:  String - **SQS** code body that should be executed when the button/active text is clicked"}],"returns":{"type":"Nothing","types":["Nothing"],"description":null,"text":"Nothing"},"form":"binary","operator":null,"left":{"text":"control","types":["Control"]},"right":{"text":"action","types":["String"]}}],"examples":[{"text":"```sqf\nbuttonSetAction [100, \"player exec \"\"reply.sqs\"\"\"];\n```","code":["buttonSetAction [100, \"player exec \"\"reply.sqs\"\"\"];"]},{"text":"```sqf\n_ctrl buttonSetAction \"if (alive bob) then {hint 'alive'} else {hint 'dead'}\"; // SQF but SQS compatible, see SQS\n```","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']\""]}],"multiplayer":null,"problems":null,"aliases":[],"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"}],"categories":["ArmA: Armed Assault: Scripting Commands","Arma 2: Operation Arrowhead: Scripting Commands","Arma 2: Scripting Commands","Arma 3: Scripting Commands","Command Group: GUI Control","Introduced with Operation Flashpoint version 1.75","Operation Flashpoint: Elite: Scripting Commands","Operation Flashpoint: New Scripting Commands","Operation Flashpoint: Scripting Commands","Scripting Commands","Scripting Commands: Local Effect","Take On Helicopters: Scripting Commands"]}