hi
Does anyone know what might cause Windows game to hang when losing focus...
My game runs okay but if I alt tab away i cant get back in?
Could it be a looping or call subs issue?
My game uses a lot of TYPES and function calls.
rgds
G
If you create a simple project that just displays some image from your game on the screen with a while/wend loop and then try to alt-tab, do you get the same problem?
im have seen that in Greedy Mouse as well, but its does only hanging in few secs. Also even when the game is paused, then you should countinue to use SHOWSCREEN and eventuelly SLEEP. If you dont doing that, then the game might hang because its dosent answear Windwos back again.
Try adding a "SLEEP 5" at the end of your main loop, it may give windows a better chance to talk to you program.
AUTOPAUSE FALSE
???
Thanks Guys
I dont have Autopause false in my code.!!! I'm such a Numpty!
Things is running much smoother now...and I've added a SLEEP 5 in the key press loop.
Cheers...
:good:
My game is still hanging in WHILE loops where no screen activity is processed...any ideas on how I can fix this?
(hangs)
SHOWSCREEN
WHILE TRUE
SLEEP 5
IF KEY() THEN
IF KEY() THEN
WEND
(doesnt hang but this is not ideal for me)
WHILE TRUE
SHOWSCREEN // dont want a showscreen every loop
IF KEY() THEN
IF KEY() THEN
WEND
I´m not the best to help on that issue MR.Plow, but I think SHOWSCREEN does other stuff then only display.
It may be a necessary command call depending on what you are doing on the loops.
But better wait for a more pro answer. :-[
The "normal" GLBasic-way is:
WHILE TRUE
// DO STUFF HERE
IF KEY(28) THEN PRINT "WOHOO does is hang anymore?!", 10,10
SHOWSCREEN
WEND
END
OHHhhhhh.... now i understand!
You can never go out of this WHILE-WEND-LOOP!
If you do NO SHOWSCREEN, the game/program is dead for your OS there are no callbacks anymore!
Looks like I should update all my key press loops with show screens but that also means Adding screen populating to each loop .... Arrgghh
Is this what every one else has to do.? Best practice?
Yep - you have to populate the screen each frame and then SHOWSCREEN (although there are alternatives, you still have to use SHOWSCREEN regularly or the program will hang).
At your use of SHOWSCREEN explains the problems with exiting the game now.
"WHILE TRUE" - Loop for keyevents?!
pls show me your code!
Quote from: Schranz0r on 2013-Aug-31
"WHILE TRUE" - Loop for keyevents?!
pls show me your code!
This is a function for getting my key event...but now i have to use showscreen...
FUNCTION getdir:
WHILE TRUE
SLEEP 5
IF KEY(71)
xm = -16
xy = -16
BREAK
ENDIF
IF KEY(72)
xm = 0
xy = -16
BREAK
ENDIF
IF KEY(73)
xm = +16
xy = -16
BREAK
ENDIF
IF KEY(75)
xm = -16
xy = 0
BREAK
ENDIF
IF KEY(77)
xm = +16
xy = 0
BREAK
ENDIF
IF KEY(79)
xm = -16
xy = +16
BREAK
ENDIF
IF KEY(80)
xm = 0
xy = +16
BREAK
ENDIF
IF KEY(81)
xm = +16
xy = +16
BREAK
ENDIF
WEND
ENDFUNCTION
That routine is quite odd - you'd generally use the WHILE/WEND in the main loop and not in a called function.
If you still wanted a similar function I'd use something like
GLOBAL press, xm, xy
MAIN()
// Main function
FUNCTION MAIN:
WHILE TRUE
// Draw all your graphics etc.
getdir()
IF press>0 THEN DEC press
PRINT xm+" "+xy,20,20
PRINT press,20,40
SHOWSCREEN
WEND
ENDFUNCTION
// Get direction function
FUNCTION getdir:
IF press=0
IF KEY(71)
xm = -16
xy = -16
press=10
ENDIF
IF KEY(72)
xm = 0
xy = -16
press=10
ENDIF
IF KEY(73)
xm = +16
xy = -16
press=10
ENDIF
IF KEY(75)
xm = -16
xy = 0
press=10
ENDIF
IF KEY(77)
xm = +16
xy = 0
press=10
ENDIF
IF KEY(79)
xm = -16
xy = +16
press=10
ENDIF
IF KEY(80)
xm = 0
xy = +16
press=10
ENDIF
IF KEY(81)
xm = +16
xy = +16
press=10
ENDIF
ENDIF
ENDFUNCTION
This will limit the key presses (ie if a key has been pressed within the last 10 frames then don't accept this next key press). It also allows your program to update everything it needs to all within the main loop.
There are ways to make this code more efficient/compact, but you need to understand this first. Obviously you're doing other things right because Viking Raiders is very playable, despite the odd bug :)
Thanks Ian
I have a populate screen function that I run before each show screen and I just pop them into the keypress loops each time ensuring a similar main loop effect like your sample code.
Seems to work well...new version in the beta section of the forum...plays much better now...