Jump to content
Sign in to follow this  
Kolmain

Sleep not working in switch

Recommended Posts

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

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

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

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×