Author Topic: Is there an ON EXIT run sub/function?  (Read 4095 times)

0 Members and 1 Guest are viewing this topic.

This topic contains a post which is marked as Best Answer. Press here if you would like to see it.

Offline xra7en

  • Seasoned Forum Regular
  • Posts: 284
    • View Profile
Is there an ON EXIT run sub/function?
« on: February 19, 2022, 05:54:45 am »
Hi
Need to do a little app cleanup if a user clicks the "X" vs regular "q"uit etc.. In my case, I want to execute a "save_game" funciton even if they just "x" out of the app

VB5,6 have this, just curious if qb64 does :-)
I just like re-writing old DOS book games into modern QB64 code - weird hobby, I know!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Is there an ON EXIT run sub/function?
« Reply #1 on: February 19, 2022, 07:07:12 am »
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline xra7en

  • Seasoned Forum Regular
  • Posts: 284
    • View Profile
Re: Is there an ON EXIT run sub/function?
« Reply #2 on: February 19, 2022, 07:16:22 am »
THIS I know. I need a function/sub to run if they click the "x" (and not a "Q"uit option )

However, it will NOT run a sub or function if a user clicks the "x" on the terminal window. the terminal window will just stop.

For example clicking the red "x" in firefox, it will run some cleanup and delete cookies etc...

a qb64 window will just exit/end

edit: I know the title is confusing but there was not a better way to write that
I need the "exit/end" to RUN a sub/function



I just like re-writing old DOS book games into modern QB64 code - weird hobby, I know!

Marked as best answer by xra7en on February 19, 2022, 06:56:06 am

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Is there an ON EXIT run sub/function?
« Reply #3 on: February 19, 2022, 08:08:43 am »
You'd use the _EXIT command in your main loop to check for the exit condition.


DO
    count = count + 1
    PRINT count
    IF _EXIT THEN RunExitSub

   _LIMIT 30
LOOP

SUB RunExitSub
   PRINT
   PRINT "Closing files and stuff...."
   _DELAY 5
   SYSTEM
END SUB
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline xra7en

  • Seasoned Forum Regular
  • Posts: 284
    • View Profile
Re: Is there an ON EXIT run sub/function?
« Reply #4 on: February 19, 2022, 11:55:55 am »
o interesting!

did not think to check for _exit LOL, actually did not know I could

I'll give it a shot.
I just like re-writing old DOS book games into modern QB64 code - weird hobby, I know!

Offline xra7en

  • Seasoned Forum Regular
  • Posts: 284
    • View Profile
Re: Is there an ON EXIT run sub/function?
« Reply #5 on: February 19, 2022, 01:27:22 pm »
OK, that's a little tricky. it's not just ANY loop, if you have an inkey$ loop, I have to put it there. Had it in the main loop and it did nothing.
I just like re-writing old DOS book games into modern QB64 code - weird hobby, I know!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Is there an ON EXIT run sub/function?
« Reply #6 on: February 19, 2022, 02:05:26 pm »
I wonder if you might need it everywhere a loop might run? It's like an event.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Is there an ON EXIT run sub/function?
« Reply #7 on: February 19, 2022, 02:27:19 pm »
I wonder if you might need it everywhere a loop might run? It's like an event.

In that case, set an ON TIMER event to check it every half second or so.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!