function exit() ?

is it possible to have a function exit() that gets automatically called when the game ends like function setup() is called when the game starts?

No, but here is a program I wrote that demonstrates how to override the close() function and still be able to close the program:

function setup()
    oldClose = close -- Make a function that does the same thing as the originl close function
        close = function() -- Must be afte rsetting oldClose (not as a usual function declaration), otherwise oldClose won't work
        print("I'm not closing! You can put code here")
        -- oldClose() -- Uncomment this when you want the program to close after the action.
    end
end

function draw()
end

function touched (t)
    close()
end

```


Good luck!

Quick update, here is a version with the exit() function:

function setup()
    oldClose = close -- Make a function that does the same thing as the originl close function
        close = function() -- Must be afte rsetting oldClose (not as a usual function declaration), otherwise oldClose won't work
        exit()
        oldClose() -- Comment this when you want the program to prove my method works
    end
end

function draw()
end

function touched (t)
    close()
end

function exit ()
    print("closing!")
end

```

Again, hope that helps!

A variation on @Zoyt’s theme:


function setup() end
 
function draw() background(0) end
 
function touched (t)
    exit()
end
 
function exit ()
    print("closing!")
    close()
end

Thats sort of what I meant, Ill just make an exit button using that, thank you.

Also does the close function close the app if it has been made in to an ipa?