The function is working exactly the way you made it. If the mouse isn't clicked it exits the function. If it is clicked in that area it does nothing... "exit" should only be used to exit a loop not a function. If you want to exit a function before the functions end use "exitfunction". There's nothing in the function that tells the rest of your code if the button has been hit.
The function just needs to have a switch that starts at zero (which is off) and only turns on when the mouse has been clicked and is in the area being checked. At the end of the function you add the same switch so the function returns the variable. If the switch is still off the button hasn't been clicked... if it's on then it has been clicked.
I also changed the function to the proper way to handle x and y coordinates. The x and y of the upper left corner and the x and y of the lower right corner... which is just like the "box" command.
Rem Concrete Part of Calculator
Rem Create All the Number Tiles
Rem Answer Box
Box 0 , 0 , screen width() , screen height()*.154
Rem Clear Buttom
Box screen width()*.364 , screen height()*.231 , screen width()*.636 , screen height()*.308
Rem 7 Button
Box screen width()*.182 , screen height()*.385 , screen width()*.273 , screen height()*.462
Rem 8 Button
Box screen width()*.364 , screen height()*.385 , screen width()*.455 , screen height()*.462
Rem 9 Button
Box screen width()*.545 , screen height()*.385 , screen width()*.636 , screen height()*.462
Rem + Button
Box screen width()*.727 , screen height()*.385 , screen width()*.818 , screen height()*.462
Rem 4 Button
Box screen width()*.182 , screen height()*.539 , screen width()*.273 , screen height()*.615
Rem 5 Button
Box screen width()*.364 , screen height()*.539 , screen width()*.455 , screen height()*.615
Rem 6 Button
Box screen width()*.545 , screen height()*.539 , screen width()*.636 , screen height()*.615
Rem - Button
Box screen width()*.727 , screen height()*.539 , screen width()*.818 , screen height()*.615
Rem 1 Button
Box screen width()*.182 , screen height()*.692 , screen width()*.273 , screen height()*.769
Rem 2 Button
Box screen width()*.364 , screen height()*.692 , screen width()*.455 , screen height()*.769
Rem 3 Button
Box screen width()*.545 , screen height()*.692 , screen width()*.636 , screen height()*.769
Rem x Button
Box screen width()*.727 , screen height()*.692 , screen width()*.818 , screen height()*.769
Rem 0 Button
Box screen width()*.182 , screen height()*.846 , screen width()*.273 , screen height()*.923
Rem = Button
Box screen width()*.364 , screen height()*.846 , screen width()*.455 , screen height()*.923
Rem / Button
Box screen width()*.545 , screen height()*.846 , screen width()*.636 , screen height()*.923
Rem Make Text Black
Ink RGB(0,0,0), 0
Rem Create Text on the Tiles
Rem Clear
Center Text 325 , 120 , "Clear"
Rem 7
Center Text 145 , 195 , "7"
Rem 8
Center Text 262 , 195 , "8"
Rem 9
Center Text 379 , 195 , "9"
Rem +
Center Text 496 , 195 , "+"
Rem 4
Center Text 145 , 268 , "4"
Rem 5
Center Text 262 , 268 , "5"
Rem 6
Center Text 379 , 268 , "6"
Rem -
Center Text 496 , 268 , "-"
Rem 1
Center Text 145 , 343 , "1"
Rem 2
Center Text 262 , 343 , "2"
Rem 3
Center Text 379 , 343 , "3"
Rem x
Center Text 496 , 343 , "x"
Rem 0
Center Text 145 , 416 , "0"
Rem =
Center Text 262 , 416 , "="
Rem /
Center Text 379 , 416 , "/"
Rem Non Concrete Part of Calculator
Answer# = 0
` These two lines are just to show you whats going on
` Make text overwrite any previous text
set text opaque
` Change the color to red text white background
ink rgb(255,0,0),rgb(255,255,255)
Do
` Check if Button 1 has been clicked
` Calling the function returns either a 0 (Not clicked) or a 1 (Clicked)
if TileClick(1,116,332,173,368)=1
text 0,0,"Hit button 1"
endif
` Check if Button 2 has been clicked
if TileClick(1,232,332,290,368)=1
text 0,0,"Hit button 2"
endif
Loop
` Because there is no exit in the do/loop these lines
` will never be ran
Answer# = 7
print Answer#
Wait Key
end
Function TileClick(Click,LeftX,TopY,RightX,BottomY)
` Create a switch... this really isn't needed because
` inside a function all variables not global start at
` zero already. I put it here to show a full example
` of a switch. A switch at zero = Off
Hit=0
If Mouseclick()=Click and mousex()=>LeftX and mousex()=<RightX and mousey()=>TopY and mousey()=<BottomY
` If the button is hit turn the switch on (make Hit=1)
Hit=1
endif
` Exit the function with Hit... 0=Not clicked 1=Clicked
endfunction Hit
What would make it easier is if you used absolute coordinates. You can force the screen size by using the command "set display mode" so you don't have to use "screen width()" and "screen height()" to create the buttons... but use exact coordinates (like I did when calling the function). Also you should probably put all those button coordinates in an array so you can easily create and check every button with a couple of for/next loops rather than an "if" statement for each button.