Yeranos 11 Posted August 13, 2016 Hello, Im posting here wishing that someone see's or knows what im missing from my code. So my goal is to have a user press 7 on the keyboard which will activate a script for a dialog I made. I then want the script to end or close the dialog when I press 7 again. After some research seems like what im doing is possible by making a switch case (bothemia wiki). I have tried this but I cant get it to work. Hopefully one of you guys can help me. Im trying to get the similar effect like how exile mod opens and closes the XM8 with keypress 6. Your help is appreciated. In my init.sqf _keyActivate = compile preprocessFile "switch.sqf"; _display = findDisplay 46; _display displaySetEventHandler ["KeyDown","_this call _keyActivate"]; In my switch.sqf private['_bool']; _bool = false; switch (_this select 1) do { //7 key case 0x08: { _dialogAct = execVM "script.sqf' //createDialog 'Main_dialog'; _bool = true; }; }; _bool; in script.sqf _handle = createDialog "Main_dialog"; Share this post Link to post Share on other sites
jwllorens 43 Posted August 13, 2016 That isn't really what "switch do" is for. Try using setVariable to set a missionNamespace variable to either 1 or 0. On your keypress, retrieve the variable, then do one of two things. If the variable is 0, then run the script and set the variable to 1. If the variable is 1, then set the variable to 0. In the script itself, I am assuming it is already a loop, so in the loop check the variable as well. If the variable is 0, then abort the script. You could do "if ((missionNamespace getVariable "myToggle") == 0) exitWith {terminate _thisScript;};" Share this post Link to post Share on other sites
Yeranos 11 Posted August 13, 2016 So the reason for the switch is because I plan in the future to make more keypresses that will activate different scripts. What I have above is just so I can have something easy to work with and display. Thanks jwllorens for your input. could you assist me with the write up for that? I agree I need some variable to change after the dialog gets called. I just thought setting it to true of false would be enough. Share this post Link to post Share on other sites
killzone_kid 1330 Posted August 13, 2016 _keyActivate = preprocessFile "switch.sqf"; _display = findDisplay 46; _display displaySetEventHandler ["KeyDown",_keyActivate]; Share this post Link to post Share on other sites
Yeranos 11 Posted August 13, 2016 _keyActivate = preprocessFile "switch.sqf"; _display = findDisplay 46; _display displaySetEventHandler ["KeyDown",_keyActivate]; WOW Im freaking out, its Killzone Kid!!! I used your site countless times and learned a lot. Big thank you man, the stuff you do is great and I appreciate the work you put in. So I made the change you wrote for my init.sqf (removed the compile) and Im not getting any errors, however its not opening the dialog. I put a hint message to debug inside the case statement in my switch.sqf and its not working. Help please. 1 Share this post Link to post Share on other sites
killzone_kid 1330 Posted August 13, 2016 So I made the change you wrote for my init.sqf (removed the compile) and Im not getting any errors, however its not opening the dialog. I put a hint message to debug inside the case statement in my switch.sqf and its not working. Help please. Yeah well, it works for me. The code is now sound. Hint inside switch works too, so no idea what you are doing wrong. _keyActivate = " private['_bool']; _bool = false; switch (_this select 1) do { case 0x08: { hint str time; _bool = true; }; }; _bool; "; _display = findDisplay 46; _display displaySetEventHandler ["KeyDown",_keyActivate]; Share this post Link to post Share on other sites