NumbNutsJunior 67 Posted March 1, 2018 I am trying to return 'true' to the function if the "Attacking Button" is pressed and 'false' if the "Defending Button" is pressed. if (dialog) then {closeDialog 0}; _attackOrDefend = createDialog "AttackOrDefend"; // (findDisplay 997) displayAddEventHandler ["KeyDown", {if ((_this select 1) isEqualTo 1) then { true }}]; // Disable ESC Key _attackingButton = ((findDisplay 997) displayCtrl 1600); // Attacking Button _defendingButton = ((findDisplay 997) displayCtrl 1601); // Defending Button _return = nil; /* Find return code ... */ waitUntil {!(isNil "_return")}; _return; Using functions such as ButtonSetAction do not allow me return true or false as they are not in the scope of the function: _attackingButton buttonSetAction "_return = true"; _defendingButton buttonSetAction "_return = false"; Using the work around that Kronzky provides only allows you to use variables already defined in the script to the action but not from the action to the script: _foo = "foo"; buttonSetAction [100, format["hint '%1 bar'", _foo]]; Please Help! I have destroyed the wiki looking for ways. 1 Share this post Link to post Share on other sites
HazJ 1289 Posted March 1, 2018 Use ButtonClick as it returns control. https://community.bistudio.com/wiki/User_Interface_Event_Handlers#onButtonClick Quote The attached button action is performed. When returned value is true, button's display remains opened. Returns control. (DISPLAY displayCtrl IDC) ctrlAddEventHandler ["ButtonClick", { params ["_button"]; }]; 2 Share this post Link to post Share on other sites
NumbNutsJunior 67 Posted March 2, 2018 11 hours ago, HazJ said: Use ButtonClick as it returns control. https://community.bistudio.com/wiki/User_Interface_Event_Handlers#onButtonClick (DISPLAY displayCtrl IDC) ctrlAddEventHandler ["ButtonClick", { params ["_button"]; }]; I have tried working with the ButtonClick event handler but the event handlers run in their own scope, how am I suppose to get the result of ButtonClick to the function so I can store it in a variable such as _return? Share this post Link to post Share on other sites
Larrow 2826 Posted March 2, 2018 Other than using a global variable you will need to rethink how your script works. Rather than returning a value, you have your script display your dialog, then when a button is pressed have that call a function that does what ever is needed for the desired button pressed. Global variable disableSerialization; if (dialog) then {closeDialog 0}; TAG_attackDefend = nil; _nul = createDialog "AttackOrDefend"; _attackingButton = ((findDisplay 997) displayCtrl 1600); // Attacking Button _attackingButton ctrlAddEventHandler [ "ButtonClick", { TAG_attackDefend = true; }]; _defendingButton = ((findDisplay 997) displayCtrl 1601); // Defending Button _defendingButton ctrlAddEventHandler [ "ButtonClick", { TAG_attackDefend = false; }]; waitUntil {!(isNil "TAG_attackDefend")}; TAG_attackDefend OR Script ReOrder TAG_fnc_openDisplay disableSerialization; if (dialog) then {closeDialog 0}; _nul = createDialog "AttackOrDefend"; _attackingButton = ((findDisplay 997) displayCtrl 1600); // Attacking Button _attackingButton ctrlAddEventHandler [ "ButtonClick", { [ true ] call TAG_fnc_attackDefend; }]; _defendingButton = ((findDisplay 997) displayCtrl 1601); // Defending Button _defendingButton ctrlAddEventHandler [ "ButtonClick", { [ false ] call TAG_fnc_attackDefend; }]; TAG_fnc_attackDefend = { params[ "_isAttacking" ]; //Do what ever }; 2 Share this post Link to post Share on other sites
HazJ 1289 Posted March 2, 2018 @NumbNutsJunior - Just wondering... Why do you need to return it anyway? What exactly for? 1 Share this post Link to post Share on other sites
NumbNutsJunior 67 Posted March 3, 2018 @HazJ I am trying to get a return value of whether the player decided to attack or defend so a dialog is called from the initPlayerLocal ... It is suppose to return a Boolean so that i can decide where to send the player whether he is defending or attacking a location: I am no an expert on scripting so clearly my ways of trying to solve the problem could be bad, but I am trying to not use globals or trashy ways of scripting like calling publicVariables over and over // initPlayerLocal.sqf [_player] spawn Onx_fnc_waitingScreen; waitUntil {dialog}; // Puts all players on waiting screen _coinFlip = call Onx_fnc_coinFlip; // Returns True or False to decide which team gets choice _coinFlip = true; // Testing only, delete after _isWestLeader = player isEqualTo westLeader; _isEastLeader = player isEqualTo eastLeader; if ((_coinFlip) and (_isWestLeader)) then { isAttacking = [_coinFlip] call Onx_fnc_isAttacking; waitUntil {!(isNil "isAttacking")}; ... I currently have solved the issue by using in the action: player setVariable ["isAttacking", true]; Like i said i don't like assigning globals so any other way would be much more clean Share this post Link to post Share on other sites
HazJ 1289 Posted March 3, 2018 @NumbNutsJunior - What is on the dialog? Is it just a button? If so, you could use ctrlSetText depending on whether attacking or defending then use ctrlText to get the result. 1 Share this post Link to post Share on other sites
HazJ 1289 Posted March 3, 2018 @NumbNutsJunior - Okay. What is your IDD and IDCs? List them here with label so I know which is what. 1 Share this post Link to post Share on other sites
NumbNutsJunior 67 Posted March 3, 2018 _attackingButton = ((findDisplay 997) displayCtrl 1600); // Attacking Button _defendingButton = ((findDisplay 997) displayCtrl 1601); // Defending Button @HazJ Share this post Link to post Share on other sites
HazJ 1289 Posted March 3, 2018 Ah, sorry. You use two buttons. Why not use setVariable to apply side/team? After clicking one: player setVariable ["side", "attack", true]; // OR player setVariable ["side", "defence", true]; Then to check it against whatever: if (player getVariable "side" == "attack") then { hintSilent "I am attacking!"; } else { hintSilent "I am defending!"; }; 1 Share this post Link to post Share on other sites
NumbNutsJunior 67 Posted March 3, 2018 That is a good idea, ill give it a test @HazJ Share this post Link to post Share on other sites