Kolmain 6 Posted January 30, 2012 I'm trying to wait ~2 seconds in the script, but it seems to not like sleeps :( I'm getting a generic expression error in this, so I tried spawn {} and also a seperate function, both of which give me the same thing. Any ideas? init.sqf keyPressed = compile preprocessFile "ocg_civ_im\pKeyPressed.sqf"; _display = findDisplay 46; _display displaySetEventHandler ["KeyDown","_this call keyPressed"]; keyPressed.sqf private['_handled']; _handled = false; switch (_this select 1) do { //T key case 30: { hint "Yell!"; variable = false; _handled = true; sleep 2; variable = true; }; }; _handled any ideas? Share this post Link to post Share on other sites
.kju 3245 Posted January 30, 2012 private['_handled']; _handled = false; switch (_this select 1) do { //T key case 30: { hint "Yell!"; variable = false; _handled = true; [] spawn { sleep 2; variable = true; }; }; }; _handled Note that you need a more clever design depending on what you are trying to achieve. Share this post Link to post Share on other sites
Kolmain 6 Posted January 30, 2012 spawn wasnt working either... Share this post Link to post Share on other sites
demonized 20 Posted January 30, 2012 maybe you need a default in the switch cases for when wrong key is pressed like in example 3: http://community.bistudio.com/wiki/switch Share this post Link to post Share on other sites
Kolmain 6 Posted January 30, 2012 Doesnt work with default either... :( Share this post Link to post Share on other sites
f2k sel 164 Posted January 31, 2012 It's probably something to do with the compile. You could do it another way but this may not be what your after sleep 1; (findDisplay 46) displayAddEventHandler ["KeyDown","null=[_this select 1] execvm 'keyPressed.sqf'"]; private['_handled']; _handled = false; switch (_this select 0) do { //T key case 30: { hint "Yell!"; variable = false; _handled = true; sleep 2; variable = true; }; }; _handled Share this post Link to post Share on other sites
Kolmain 6 Posted January 31, 2012 That fixed it thanks! Share this post Link to post Share on other sites