mrleather 0 Posted May 6, 2018 So I have a mission file where I want a player to be able to select which weapon they want before they go into the round. In the loadout script I have, I have made it so there is a variable called _weapon = ""; and then in a dialog listbox I created I made the choices of MX, MXM and MXSW. In the list box the code I used was: _weapon = "arifle_MXC_F"; I thought this would make it so the weapon would be an MX but it doesn't work, would appreciate some help. Share this post Link to post Share on other sites
Grumpy Old Man 3540 Posted May 6, 2018 3 hours ago, mrleather said: So I have a mission file where I want a player to be able to select which weapon they want before they go into the round. In the loadout script I have, I have made it so there is a variable called _weapon = ""; and then in a dialog listbox I created I made the choices of MX, MXM and MXSW. In the list box the code I used was: _weapon = "arifle_MXC_F"; I thought this would make it so the weapon would be an MX but it doesn't work, would appreciate some help. Without seeing any more info it's a guess and case for the crystal ball to figure out why it doesn't work. To paraphrase your problem: "I bought a car but it doesn't work", isn't really of any help to a mechanic on the other side of the phone line, is it? Try to be as specific as possible, provide script snippets, and for googles sake, use a more descriptive thread title. Cheers 1 Share this post Link to post Share on other sites
Dedmen 2590 Posted May 7, 2018 23 hours ago, mrleather said: So I have a mission file where I want a player to be able to select which weapon they want before they go into the round. In the loadout script I have, I have made it so there is a variable called _weapon = ""; and then in a dialog listbox I created I made the choices of MX, MXM and MXSW. In the list box the code I used was: _weapon = "arifle_MXC_F"; I thought this would make it so the weapon would be an MX but it doesn't work, would appreciate some help. You need to use a global variable. Without the _. As local variables are as the name says local and don't carry over between different scripts. 1 Share this post Link to post Share on other sites
mrleather 0 Posted May 8, 2018 On 07/05/2018 at 12:11 PM, Dedmen said: You need to use a global variable. Without the _. As local variables are as the name says local and don't carry over between different scripts. Quick question, How do I create a global variable as I have the current variable in private Share this post Link to post Share on other sites
HazJ 1288 Posted May 8, 2018 thisIsAGlobalVariable = true; No need to private it. You simply don't. Share this post Link to post Share on other sites
mrleather 0 Posted May 8, 2018 22 minutes ago, HazJ said: thisIsAGlobalVariable = true; No need to private it. You simply don't. I have the variable Scope1 = "optic_Arco_blk_F"; Then in my keybinding script I have this case 22: { if(Scope1 ) then { Scope1= false; Scope1 = "optic_Hamr"; hint "rco"; } else { Scope1 = true; hint "arco"; }; _handled = true; }; In my init I have Scope1 = false; Any ideas, I want to make it so the Scope1 from the selection script changes on the key press I made. Share this post Link to post Share on other sites
HazJ 1288 Posted May 8, 2018 It will change? A bit confused... What is the issue? Share this post Link to post Share on other sites
mrleather 0 Posted May 8, 2018 5 minutes ago, HazJ said: It will change? A bit confused... What is the issue? the scope doesn't change on my keypress I get the error type string, expected bool. it gives the original scope but when I keypress nothing happens Share this post Link to post Share on other sites
HazJ 1288 Posted May 8, 2018 Oh... I see. init.sqf: Scope1 = ""; Then set string to whatever. If you need to check if a certain string is set, you can do: if (Scope1 isEqualTo "arco") then {hintSilent "true!";}; if !(Scope1 isEqualTo "arco") then {hintSilent "false!";}; if (Scope1 isEqualTo "arco") then { hintSilent "true!"; } else { hintSilent "false!"; }; Remove the bool variables, obviously. Share this post Link to post Share on other sites
mrleather 0 Posted May 8, 2018 8 minutes ago, HazJ said: Oh... I see. init.sqf: Scope1 = ""; Then set string to whatever. If you need to check if a certain string is set, you can do: if (Scope1 isEqualTo "arco") then {hintSilent "true!";}; if !(Scope1 isEqualTo "arco") then {hintSilent "false!";}; if (Scope1 isEqualTo "arco") then { hintSilent "true!"; } else { hintSilent "false!"; }; Remove the bool variables, obviously. Not gonna lie im really confused lol So in my init I put this: Scope1 = ""; In my key handler I put this: case 22: { if (Scope1 isEqualTo "arco") then { hintSilent "true!"; Scope1 = "optic_Arco_blk_F"; } else { hintSilent "false!"; Scope1 = "optic_mrco"; }; }; The output I get is straight "false" Share this post Link to post Share on other sites
HazJ 1288 Posted May 8, 2018 Yes because default is set in init.sqf as "" so it outputs: } else { hintSilent "false!"; Scope1 = "optic_mrco"; }; Share this post Link to post Share on other sites
mrleather 0 Posted May 8, 2018 2 minutes ago, HazJ said: Yes because default is set in init.sqf as "" so it outputs: } else { hintSilent "false!"; Scope1 = "optic_mrco"; }; What do I do to make it so when i press the button the scopes change Share this post Link to post Share on other sites
HazJ 1288 Posted May 8, 2018 case DIK_CODE : { Scope1 = "arco"; // or whatever }; // another way case DIK_CODE : { if (Scope1 isEqualTo "arco") then // if "arco" is already set then change to "rco" { Scope1= "rco"; } else { // else set it Scope1 = "arco"; }; }; https://community.bistudio.com/wiki/DIK_KeyCodes Share this post Link to post Share on other sites
mrleather 0 Posted May 8, 2018 12 minutes ago, HazJ said: case DIK_CODE : { Scope1 = "arco"; // or whatever }; // another way case DIK_CODE : { if (Scope1 isEqualTo "arco") then // if "arco" is already set then change to "rco" { Scope1= "rco"; } else { // else set it Scope1 = "arco"; }; }; https://community.bistudio.com/wiki/DIK_KeyCodes Okay so I went back through everything you said trying to understand because im hella confused lol. I still can't get anything to work i'm confused with this "arco" thing. In my init I now have Scope1 = "arco"; and my keyhandler is now case 22: { if (Scope1 isEqualTo "arco") then { Scope1 = "optic_mrco"; hint "scope"; }; }; I'm just a bit confused with the "arco" and "rco" stuff. If for example I set Scope1 = "optic_mrco"; in the init it works fine, but this toggle thing isn't working. Share this post Link to post Share on other sites
HazJ 1288 Posted May 8, 2018 You said "rco" and "arco" lol, not me. You can set the classname there if you wish. Just change "rco" to: "optic_hamr" Change "arco" to: "optic_arco" EDIT: Ah, I got confused, misread. You put "rco" and "arco" in hint, my bad. Share this post Link to post Share on other sites
mrleather 0 Posted May 8, 2018 6 minutes ago, HazJ said: You said "rco" and "arco" lol, not me. You can set the classname there if you wish. Just change "rco" to: "optic_hamr" Change "arco" to: "optic_arco" I don't know why this doesn't work then init: Scope1 = "arco"; key handler: case 22: { if (Scope1 isEqualTo "arco") then // if "arco" is already set then change to "rco" { Scope1= "optic_hamr"; hint "r"; } else { // else set it Scope1 = "optic_mrco"; hint "m"; }; }; Share this post Link to post Share on other sites
HazJ 1288 Posted May 8, 2018 This should output: hint "m"; Does your key handler actually work? Scope1 = "arco"; // change to: Scope1 = "optic_arco"; Or whatever you need, optic wise - classname. Share this post Link to post Share on other sites
mrleather 0 Posted May 8, 2018 2 minutes ago, HazJ said: This should output: hint "m"; Does your key handler actually work? Scope1 = "arco"; // change to: Scope1 = "optic_arco"; Or whatever you need, optic wise - classname. Yeah i changed the init to Scope1 = "optic_arco"; and it gives me the arco the key handler works i get the "m" hint just need to it to toggle between arco and rco Share this post Link to post Share on other sites
HazJ 1288 Posted May 8, 2018 if (Scope1 isEqualTo "optic_hamr") then // IF set to "optic_hamr" which is the RCO optic { // set to "optic_arco" which is ARCO optic Scope1 = "optic_arco"; hintSilent "ARCO"; } else { // set to "optic_hamr" IF NOT set to RCO Scope1 = "optic_hamr"; hintSilent "RCO"; }; Share this post Link to post Share on other sites
mrleather 0 Posted May 8, 2018 6 minutes ago, HazJ said: if (Scope1 isEqualTo "optic_hamr") then // IF set to "optic_hamr" which is the RCO optic { // set to "optic_arco" which is ARCO optic Scope1 = "optic_arco"; hintSilent "ARCO"; } else { // set to "optic_hamr" IF NOT set to RCO Scope1 = "optic_hamr"; hintSilent "RCO"; }; It's like on my key handler script it isn't detecting the Scope1 variable as the only way it works is by doing it in init, or on the loadout script itself. I get the hints the script works just the scope doesnt change Share this post Link to post Share on other sites
HazJ 1288 Posted May 8, 2018 Debug it: if (Scope1 isEqualTo "optic_hamr") then // IF set to "optic_hamr" which is the RCO optic { // set to "optic_arco" which is ARCO optic Scope1 = "optic_arco"; hintSilent format ["Scope1 changed to %1", Scope1]; } else { // set to "optic_hamr" IF NOT set to RCO Scope1 = "optic_hamr"; hintSilent format ["Scope1 changed to %1", Scope1]; }; What does it say? Share this post Link to post Share on other sites
mrleather 0 Posted May 8, 2018 Just now, HazJ said: Debug it: if (Scope1 isEqualTo "optic_hamr") then // IF set to "optic_hamr" which is the RCO optic { // set to "optic_arco" which is ARCO optic Scope1 = "optic_arco"; hintSilent format ["Scope1 changed to %1", Scope1]; } else { // set to "optic_hamr" IF NOT set to RCO Scope1 = "optic_hamr"; hintSilent format ["Scope1 changed to %1", Scope1]; }; What does it say? Just gives the hint Scope1 changed to "optic_hamr" or "optic_arco". Doesn't give anything else Share this post Link to post Share on other sites
HazJ 1288 Posted May 8, 2018 ??? That's what it is supposed to do. What are you trying to do? It won't change the weapon scope for you. You have to do that yourself: (primaryWeapon player) addPrimaryWeaponItem "optic_hamr"; (primaryWeapon player) addPrimaryWeaponItem "optic_arco"; https://community.bistudio.com/wiki/primaryWeapon https://community.bistudio.com/wiki/addPrimaryWeaponItem Remember to check if primary weapon exists. if !(primaryWeapon player isEqualTo "") then { (primaryWeapon player) addPrimaryWeaponItem "optic_arco"; }; If this is what you are trying to do. No need to check Scope1 variable or even use it. if ("optic_hamr" in primaryWeaponItems player) then {}; https://community.bistudio.com/wiki/primaryWeaponItems Share this post Link to post Share on other sites
mrleather 0 Posted May 8, 2018 3 minutes ago, HazJ said: ??? That's what it is supposed to do. What are you trying to do? It won't change the weapon scope for you. You have to do that yourself: (primaryWeapon player) addPrimaryWeaponItem "optic_hamr"; (primaryWeapon player) addPrimaryWeaponItem "optic_arco"; https://community.bistudio.com/wiki/primaryWeapon https://community.bistudio.com/wiki/addPrimaryWeaponItem Remember to check if primary weapon exists. if !(primaryWeapon player isEqualTo "") then { (primaryWeapon player) addPrimaryWeaponItem "optic_arco"; }; If this is what you are trying to do. No need to check Scope1 variable or even use it. if ("optic_hamr" in primaryWeaponItems player) then {}; https://community.bistudio.com/wiki/primaryWeaponItems nah thats not what i'm trying to do. I have a script set up so for example if I put in init Scope1 = "optic_arco"; the arco will go in the players clothing. It just doesn't do it when done in the key handler. Share this post Link to post Share on other sites
HazJ 1288 Posted May 8, 2018 It won't add the scope in the vest for you. Not just by setting variable. https://community.bistudio.com/wiki/addItem https://community.bistudio.com/wiki/addItemToVest Share this post Link to post Share on other sites