It is currently Sat Mar 25, 2017 12:37 pm



Welcome
Welcome to rfobasic

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. In addition, registered members also see less advertisements. Registration is fast, simple, and absolutely free, so please, join our community today. **You are not required to provide truthful information to any registration questions. Be whomever you wish to be.!


Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Breaking out of a PAUSE
Unread postPosted: Sat Mar 18, 2017 2:13 am 
Offline
User avatar

Joined: Sat Dec 08, 2012 2:14 am
Posts: 1105
Location: UK
Trying:-

Code:
DO
  p = p + 1
  PAUSE 5000
  PRINT "PAUSE 5000 cycle", p
UNTIL 0
END

ONBACKKEY:
PRINT "Back key pressed to exit loop."
END
BACK.RESUME


You can't use ONBACKKEY: to halt your program. Other than it seems to only do so after the PAUSE 10000 has completed a cycle.

Is this programming languages expected behavior?

Obvious work around would be:-

Code:
elapsed = CLOCK()
DO
UNTIL CLOCK() - elapsed > 5000
PRINT "Loop exited naturally after 5 seconds."
END

ONBACKKEY:
PRINT "Back key pressed to exit loop."
END


It's no big deal. But I just expected both code examples to provide an instantaneous exit from the loop?

Mog


Report this post
Top
 Profile  
 
 Post subject: Re: Breaking out of a PAUSE
Unread postPosted: Sat Mar 18, 2017 2:58 am 
Offline
User avatar

Joined: Mon Aug 18, 2014 1:16 pm
Posts: 1288
Hi Mog

When an interrupted is called it waits for the running statement to end
In your case a long pause
Regards Roy


Report this post
Top
 Profile  
 
 Post subject: Re: Breaking out of a PAUSE
Unread postPosted: Sat Mar 18, 2017 3:27 am 
Offline
User avatar

Joined: Sat Dec 08, 2012 2:14 am
Posts: 1105
Location: UK
Thanks Roy,

Oh dear!

Must remember that in future coding, and perhaps to use nothing more than a PAUSE 1 to stop CPU battery fry.

Mog


Report this post
Top
 Profile  
 
 Post subject: Re: Breaking out of a PAUSE
Unread postPosted: Sat Mar 18, 2017 3:46 am 
Offline
User avatar

Joined: Wed Jul 10, 2013 8:11 am
Posts: 279
You can use also a timer.

Code:
TIMER.SET 6000
do
until 0
forward:

onTimer:
Timer.clear
goto forward
timer.resume


/ Gregor

EDIT:
Timer.clear


Report this post
Top
 Profile  
 
 Post subject: Re: Breaking out of a PAUSE
Unread postPosted: Sat Mar 18, 2017 4:27 am 
Offline
User avatar

Joined: Sat Dec 08, 2012 2:14 am
Posts: 1105
Location: UK
Thanks also Gregor,

'TIMER' is more what I remember as a "BASIC-esque" command.

It's good that with BASIC! you are able to as well get relative time with both functions.

Thinking back, in the olden days you used to rely just on the CPU in the home computer scenario to provide an unreliable timing mechanism.

Mog


Report this post
Top
 Profile  
 
 Post subject: Re: Breaking out of a PAUSE
Unread postPosted: Sat Mar 18, 2017 4:48 am 
Offline
User avatar

Joined: Wed Jul 10, 2013 8:11 am
Posts: 279
But with TIMER you are able to left the loop.
That is the difference to PAUSE.

/ Gregor


Report this post
Top
 Profile  
 
 Post subject: Re: Breaking out of a PAUSE
Unread postPosted: Sat Mar 18, 2017 4:55 am 
Offline
User avatar

Joined: Tue Jan 03, 2012 9:31 am
Posts: 5447
Location: Paris, France
This should do a pause breakable by the Back key: (not tested)
Code:
FN.DEF SLEEP(ms)
c=CLOCK()
DO: PAUSE 1: UNTIL CLOCK()-c > ms
FN.END

SLEEP(6000)
END "Finished normally after 6s"

ONBACKKEY:
END "Interrupted by the Back key"

_________________
- Creator of the Android BASIC! Compiler


Report this post
Top
 Profile  
 
 Post subject: Re: Breaking out of a PAUSE
Unread postPosted: Sat Mar 18, 2017 8:22 am 
Offline
User avatar

Joined: Sat Dec 08, 2012 2:14 am
Posts: 1105
Location: UK
I think I get it now, yes... Breaking out of a loop cleanly. These have always been techniques I have over looked.

Okay, but you can only have one TIMER.SET in your code though? Not multiples of?

Generally the BASIC I remember was you could assign a variable to a TIMER.

You can't for instance do, let's say:-

gameTimer1 = TIMER.SET 6000
gameTimer2 = TIMER.SET 1000

So, therefore CLOCK() is the way to go to, if you code right with multiples of timing in your program to cleanly exit?

Again it's no problem, I think BASIC! firefights against the way Java and Android works? It's just making sure I don't get perhaps future crashes in apps should I wish to share with other users.

I did a search before posting, I don't think assignment to TIMER.SET has come up before. I feel no need anyway, but just pointing out how I remember the way it worked.

Research via Google and this forum to search properly:-

site:rfobasic.freeforums.org timer.set

Mog


Report this post
Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
suspicion-preferred