JulesMK2 2 Posted July 29, 2020 Hi there, recently I stumbled across an "Amin Menu" tutorial and sadly the creator dropped it at 3 videos. I am trying to work on the next part he was going to include as a learning experience but I am unable to parse a variable from one function into another. Currently I have a function which gets the selected unit which works absolutely fine. I tried to make the variable global so it could get accessed outside of the scope but I can't parse it in via the .HPP. Is anybody able to shed some light? adminMenu.hpp //User selection class class playerSelectionBtn: RscButton { idc = 1600; onMouseButtonClick = "(lbCurSel 1500) call JC_fnc_playerSelected;"; text = "SELECT"; //--- ToDo: Localize; x = 0.664062 * safezoneW + safezoneX; y = 0.346 * safezoneH + safezoneY; w = 0.091875 * safezoneW; h = 0.028 * safezoneH; }; //Teleport button class class adminTeleport: RscButton { idc = 1601; onMouseButtonClick = "['unit'] call JC_fnc_teleportToPlayer;"; //Here I try to parse unit into the function text = "TELEPORT"; //--- ToDo: Localize; x = 0.250625 * safezoneW + safezoneX; y = 0.22 * safezoneH + safezoneY; w = 0.091875 * safezoneW; h = 0.028 * safezoneH; }; fn_playerSelected.sqf params ["_index"]; unit = (switchableUnits select _index); //Change the variable to global if (!(isNull(unit))) then { unit setDamage 1; hint name unit; } else { hint "No player selected"; }; fn_teleportToPlayer.sqf params ["_unit"]; //Attempt to "fetch" unit inside the params hint format["Teleporting to: %1", _unit]; //Initial test to see if unit was there. Did have ",name _unit" but that returned a generic error player setPos( getPos _unit); Share this post Link to post Share on other sites
gc8 970 Posted July 30, 2020 9 hours ago, JulesMK2 said: onMouseButtonClick = "['unit'] call JC_fnc_teleportToPlayer;"; //Here I try to parse unit into the function take off the single quotation marks from unit, then the unit should be properly passed to the JC_fnc_teleportToPlayer function 1 Share this post Link to post Share on other sites
JulesMK2 2 Posted July 30, 2020 Ok so I have tried what was suggested and it seems like it (fn_teleportToPlayer) still isn't getting access to the variable. I then thought this could be due to it being on an event handler rather than the "action" property buttons can have. So I tried it on "action" and this is my result: adminMenu.hpp class adminTeleport: RscButton { idc = 1601; //onMouseButtonClick = "[unit] call JC_fnc_teleportToPlayer;"; action = "[unit] call JC_fnc_teleportToPlayer;"; text = "TELEPORT"; //--- ToDo: Localize; x = 0.250625 * safezoneW + safezoneX; y = 0.22 * safezoneH + safezoneY; w = 0.091875 * safezoneW; h = 0.028 * safezoneH; }; fn_teleportToPlayer.sqf params ["_unit"]; hint format["Teleporting to: %1", name _unit]; player setPos( getPos _unit); I have tried: unit | _unit in both files. The hint also returns a blank space for _unit but "any" for unit Share this post Link to post Share on other sites
gc8 970 Posted July 30, 2020 I think you need to click the select button first to assign a value to the unit variable 1 Share this post Link to post Share on other sites
JulesMK2 2 Posted July 30, 2020 Of course! The select function is what gets the units index... Thanks 😄 1 Share this post Link to post Share on other sites
Larrow 2794 Posted July 30, 2020 Why use unit from clicking the other button, why not just do exactly the same as the other button lbCurSel and then get the unit from the selected index. 1 Share this post Link to post Share on other sites
JulesMK2 2 Posted July 30, 2020 Yeah I suppose I could and that would keep it all in its own functions. I will have to redo it later. Thanks for the suggestion! Share this post Link to post Share on other sites