GLBasic forum

Main forum => GLBasic - en => Topic started by: ggindlesperger on 2010-Sep-26

Title: Sleep problem
Post by: ggindlesperger on 2010-Sep-26
Is there any known Sleep command problem when compiling for iPhone? I don't remember having issues with it in the past, but I have not tried using it since I have the latest build of GLBasic. Now it does not seem to work at all on the iPhone/iPod. When I compile and run within the IDE it works just like it should, but when I send it to the iPod there is no pause at all rather I make it Sleep 200 or Sleep 2000.

Any thoughts on this? Been trying different situations and sleep seems to always work in the IDE, but never on the iPhone/iPod anymore.

Thanks Much,
Gary
Title: Re: Sleep problem
Post by: Nobiag on 2010-Sep-26
I have the same problem, but i found it seems to only occur on older ipods/iphones. On my iPhone 4 the sleep command works without any problems, on iPod Touches 8gb/32gb it doesn't work.
Title: Re: Sleep problem
Post by: ggindlesperger on 2010-Sep-26
The ones I am having the problem with are a 3rd gen 8 gig and a 3rd gen 32 gig. Any other way to easily make the program pause without requiring user input to continue?
Title: Re: Sleep problem
Post by: MrTAToad on 2010-Sep-26
For the time being, use GETTIMERALL() and calculate the amount of time you want to wait for, with something like :

Code (glbasic) Select
finishTime%=GETTIMERALL()
WHILE ABS(GETTIMERALL()-finishTime%)<1000
WEND

Title: Re: Sleep problem
Post by: ggindlesperger on 2010-Sep-26
Thanks alot for that piece of code. I will try it out. Looks like that should do the trick.

Gary
Title: Re: Sleep problem
Post by: BlueSteel on 2010-Sep-26
I rtoo have a sleeep problem..

I don't get enough of it.. lol
Title: Re: Sleep problem
Post by: MrTAToad on 2010-Sep-26
Dont we all :)
Title: Re: Sleep problem
Post by: Ian Price on 2010-Sep-26
I'll sleep when I'm dead. Until then I'll code (pausing for the odd cup of cold tea and some pizza) :P
Title: Re: Sleep problem
Post by: MrTAToad on 2010-Sep-26
True - I wonder even if the SLEEP command isn't sleeping per say on the offending machines, it does still relinquish control back to the operating system.
Title: Re: Sleep problem
Post by: ggindlesperger on 2010-Sep-27
More to the mystery...The same app has Sleep commands scattered throughout and they all work but the one section. So I started looking at what the difference is. Here is what I found. All of my Sleep commands that are within a loop such as an IF or WHILE loop work fine. The ones that do not are the ones that are out on their own. Here is basically what I am doing in the section that does not work.

I draw and move a sprite to a certain point. I want the sprite to change to another sprite, sleep, then change back and continue to move. The effect is to produce a face winking. When I run in the IDE it is perfect. When I run it on the iPod there is no pause at all no matter what highly ridiculous number I can put in for Sleep. These sleep commands are not within any kind of loop. That is the only difference I can see between the ones that work and the ones that do not.

Hope this helps,
Gary
Title: Re: Sleep problem
Post by: Scott_AW on 2010-Sep-27
Good thing to know.
Title: Re: Sleep problem
Post by: Kitty Hello on 2010-Sep-27
What OS version is that iPod ignoring sleep?
Title: Re: Sleep problem
Post by: ggindlesperger on 2010-Sep-29
The version is 4.1 . Real weird. I've never had the problem before. Even in the same program. The Sleep commands that were not working were not in a loop. I know most things are in a loop in one way or another, but these commands were used for an intro screen and only execute once. Ran fine in the GLBasic IDE when compilied and ran. Once on the iPod it did not pause at all. Went so fast you never saw the sprite change.

Hope this helps. I used a work around for the time being.

Gary
Title: Re: Sleep problem
Post by: msx on 2011-Jan-05
Is there any solution for this problem?
Title: Re: Sleep problem
Post by: Slydog on 2011-Jan-05
If not, you could create your own temporary function, using the above code.
And to get around the problem of relinquishing control back to the OS, a simple 'SHOWSCREEN' should help I think.

Code (glbasic) Select
FUNCTION Pause%: delay%
  LOCAL time_start% = GETTIMERALL()
  WHILE ABS(GETTIMERALL() - time_start) < delay
    SHOWSCREEN
  WEND
ENDFUNCTION
Title: Re: Sleep problem
Post by: msx on 2011-Jan-06
It  works perfectly without using SHOWSCREEN.

Thank you. ;)
Title: Re: Sleep problem
Post by: Kitty Hello on 2011-Jan-07
please put a SLEEP before that loop to enable some CPU relief where it works:
Code (glbasic) Select

FUNCTION Pause%: delay%
  LOCAL time_start% = GETTIMERALL()
  SLEEP delay%
  WHILE ABS(GETTIMERALL() - time_start) < delay
    // SHOWSCREEN
  WEND
ENDFUNCTION
Title: Re: Sleep problem
Post by: Slydog on 2011-Jan-07
So, would this make sense then:
Code (glbasic) Select
FUNCTION Pause%: delay%
  LOCAL time_start% = GETTIMERALL()
  WHILE ABS(GETTIMERALL() - time_start) < delay
    SLEEP 1     // Sleep 1ms
  WEND
ENDFUNCTION

Whether SLEEP is working properly or not for the platform (iPod or PC), it will act the same, and giving your CPU some relief either way.
Title: Re: Sleep problem
Post by: Moebius on 2011-Jan-07
It does make sense, but Gernot's example works just as well, if not better... (I doubt executing the code for a loop every millisecond would impede performance though)
Title: Re: Sleep problem
Post by: erico on 2011-Jan-07
I believe the best way to use sleep is to make it at least 8h a day... =D
...sorry to bother a serious thread...just could not help as I haven't got sleep the last 3 days for ear infection :sick:
Title: Re: Sleep problem
Post by: DaCarSoft on 2011-Jan-14
Hello!

This is my first post here.

Before of all, I would like to send my congratulations because of the work that makes possible GLBasic and the good answers of this community.

Now, I'm creating my own functions to work with GLBasic, and I also found that Sleep does not work in my iPad (iOS and SDK 4.2) while testing, but for me it does not work if it is inside of a loop.

I can workaround it in many ways, but reading this thread (as a newbie to GLBasic), I'm asking me now if the next code does make sense:

Code (glbasic) Select
FUNCTION Pause%: delay%
  LOCAL time_start% = GETTIMERALL()
  SLEEP delay%
  WHILE ABS(GETTIMERALL() - time_start) < delay
    HIBERNATE
  WEND
ENDFUNCTION


Thanks in advance!