Quote: "gave me error message "Could not understand command at line 21.""
You had the right idea. The BOX command doesn't need parenthesis.
What you have:
What it should be:
Just changing that does work but you won't see it because you keep clearing the screen and writing bright white text over a box that's bright white. You can change the color with the INK command so you can see it actually working.
do
cls
if make_button(0, 0, 100, 100) = 1
` Change the ink color back to bright white (which is the staring color)
ink rgb(255,255,255),0
print "clicked"
endif
LOOP
function make_button(x1, y1, x2, y2 )
` Change the ink color to grey
ink rgb(100,100,100),0
` Make the box
box x1, y1, x2, y2
if mousex() > x1 and mousex() < x2
if mousey() > y1 and mousey() < y2
if mouseclick() = 1
clicked = 1
else
clicked = 0
endif
endif
ENDIF
ENDFUNCTION clicked
Quote: "is it possible to make a type within a function?"
It would work if you took that UDT and array out of the function and put it at the top of your code. This also shows the dangers of using names that are too long.
` Define the UDT
type button
top as integer
left as integer
right as integer
bottom as integer
butt_text as string
endtype
` Create the array based on the UDT button
dim clickable_button(100) as button
` Add the button to the array
make_button(0,0,100,100,0,"Test")
do
cls
if show_button(0) = 1
` Change the ink color back to bright white (which is the staring color)
ink rgb(255,255,255),0
print "clicked"
endif
LOOP
function show_button(button_number)
` Change the ink color to grey
ink rgb(100,100,100),0
` Make the box
box clickable_button(button_number).left, clickable_button(button_number).top, clickable_button(button_number).right, clickable_button(button_number).bottom
` Change the ink color back to bright white
ink rgb(255,255,255),0
` Show the text
center text (clickable_button(button_number).right-clickable_button(button_number).left)/2,(clickable_button(button_number).bottom-clickable_button(button_number).top)/2-text height(clickable_button(button_number).butt_text),clickable_button(button_number).butt_text
if mousex() > clickable_button(button_number).left and mousex() < clickable_button(button_number).right
if mousey() > clickable_button(button_number).top and mousey() < clickable_button(button_number).bottom
if mouseclick() = 1
clicked = 1
else
clicked = 0
endif
endif
ENDIF
ENDFUNCTION clicked
function make_button(x1, y1, x2, y2, button_number, button_text$)
clickable_button(button_number).top = y1
clickable_button(button_number).left = x1
clickable_button(button_number).right = x2
clickable_button(button_number).bottom = y2
clickable_button(button_number).butt_text = button_text$
ENDFUNCTION