AaronZockt 0 Posted February 25, 2023 Hello there!I'm trying to pass a vehicle Object to a button action. On vehicles with variable names my current version works perfectly fine, but on vehicles without variable name it isn't... So do you guys have any ideas on how to pass the _vehicle variable to the button? // My current Version buttonSetAction [_idc, format ["player moveInDriver %1;", _vehicle]]; Share this post Link to post Share on other sites
Harzach 2517 Posted February 26, 2023 Where is _vehicle being defined? Share this post Link to post Share on other sites
AaronZockt 0 Posted February 26, 2023 12 minutes ago, Harzach said: Where is _vehicle being defined? In the same SQF File, it is passed via the inGameUISetEventHandler and getInDriver Action, in my case the _target parameter is _vehicle Share this post Link to post Share on other sites
Harzach 2517 Posted February 26, 2023 7 minutes ago, AaronZockt said: In the same SQF File It would make it easier for others to help you if you shared all of your code. 1 Share this post Link to post Share on other sites
AaronZockt 0 Posted February 26, 2023 29 minutes ago, Harzach said: It would make it easier for others to help you if you shared all of your code. private _onVehicleBoarding = ' params ["_vehicle", "", "", "_action", "", "", "", "", "", "", "_event"]; if (_action == "getInDriver") then { if (_event == "Action") then { createDialog "test_dialog"; _idc = 1600; buttonSetAction [_idc, format ["player moveInDriver %1;", _vehicle]]; }; }; true }; '; inGameUISetEventHandler ['Action', _onVehicleBoarding]; Share this post Link to post Share on other sites
Harzach 2517 Posted February 26, 2023 You are using format incorrectly, and the result is creating the string "player moveInDriver _vehicle;". buttonSetAction [_idc, format ["player moveInDriver %1;", _vehicle]]; So: private _onVehicleBoarding = ' params ["_vehicle", "", "", "_action", "", "", "", "", "", "", "_event"]; if (_action == "getInDriver") then { if (_event == "Action") then { createDialog "test_dialog"; _idc = 1600; buttonSetAction [_idc, format ["player moveInDriver %1;", _vehicle]]; }; }; true }; '; inGameUISetEventHandler ['Action', _onVehicleBoarding]; Share this post Link to post Share on other sites
AaronZockt 0 Posted February 26, 2023 I know, corrected it already, it's getting late :S But that doesn't solve my original Problem with vehicles without a variable name^^ Share this post Link to post Share on other sites
Larrow 2820 Posted February 26, 2023 Format of an OBJECT to STRING produces erroneous results like "B Alpha 1-1:1 (Dev)" ( <- this is an example format of a player object ) unless the object has a vehicleVarName where format will return the variable name. So player moveInDriver B SomeRubbish 1-1-:1 makes no sense and results in a error. Use the function BIS_fnc_objectVar to return a vehicleVarName for the OBJECT. If the object already has a vehicle var name it will be returned, if it does not one will be set and returned. buttonSetAction [_idc, format ["player moveInDriver %1;", [ _vehicle ] call BIS_fnc_objectVar]]; 4 Share this post Link to post Share on other sites
AaronZockt 0 Posted February 26, 2023 Thank you very much for your help @Larrow and @Harzach buttonSetAction [_idc, format ["player moveInDriver %1;", [ _vehicle ] call BIS_fnc_objectVar]]; works like a charm and was exactly what I'm looking for. Share this post Link to post Share on other sites
Larrow 2820 Posted February 26, 2023 You can also use NetID to do the same thing. buttonSetAction [_idc, format ["player moveInDriver ( '%1' call BIS_fnc_objectFromNetId );", [ _vehicle ] call BIS_fnc_netId]]; 4 Share this post Link to post Share on other sites
mrcurry 496 Posted February 26, 2023 Good stuff from @Larrow and @Harzach per usual. For posterity's sake here's an another way to pass data into the button click-event using the button's variable space and the ButtonClick eventhandler. Good for passing more complex data or situations where you can't or don't want to rely on the parsing of mission namespace variables. createDialog "test_dialog"; _idc = 1600; private _ctrl = displayCtrl _idc; _ctrl setVariable ["TAG_myVariable", _vehicle]; _ctrl ctrlAddEventHandler [ "ButtonClick", { params ["_ctrl"]; player moveInDriver (_ctrl getVariable "TAG_myVariable"); } ]; 5 Share this post Link to post Share on other sites
pierremgi 4851 Posted February 27, 2023 18 hours ago, mrcurry said: Good stuff from @Larrow and @Harzach per usual. For posterity's sake here's an another way to pass data into the button click-event using the button's variable space and the ButtonClick eventhandler. Good for passing more complex data or situations where you can't or don't want to rely on the parsing of mission namespace variables. Yes. Probably better than inGameUISetEventHandler . Adding an EH on click, rather than setting the UI EH with filter. Share this post Link to post Share on other sites
mrcurry 496 Posted February 27, 2023 2 hours ago, pierremgi said: Yes. Probably better than inGameUISetEventHandler . Adding an EH on click, rather than setting the UI EH with filter. To clarify, my example would be placed inside the inGameUISetEventHandler to get OP's intended effect of interrupting the "get in" action with a dialog. It's merely an example of how to pass data without resorting to globals. 🙂 1 Share this post Link to post Share on other sites