Hi Coders,
Try this out, tell me what you think, could the function be be made smaller?
<edit> edited code with rems to make clearer.
Rem Project: newradiobuttonsworking
Rem Created: 4/17/2005 2:31:37 PM
rem By Howdo
Rem ***** Main Source File *****
rem Standard Setup Code
sync on : sync rate 0 :
color backdrop rgb(0,0,128) :rem set background to black
set text font "arial" : set text size 12 : set text transparent
rem make choice avaiable to all parts
rem set dim to number buttons you required
dim button(5,4)
global choice button
for h=1 to 5
button(h,0)=0
next h
choice=1 : rem make button one on
rem load buttons
load image "onoffbutton.bmp",1
rem make it a sprite
sprite 1,0,0,1
rem put sprite on screen
paste image 1,0,0
rem get first button in off postion
get image 2,1,1,63,63,1
rem load into sprite 2
sprite 2,200,200,2
rem get button in on postion
get image 3,65,1,126,63,2
rem load into sprite 3
sprite 3,0,0,3
rem hide sprite 1
hide sprite 1
rem clone sprite 2 to 4,5,6 and 7
clone sprite 2,4
clone sprite 2,5
clone sprite 2,6
clone sprite 2,7
`hide sprite 3
rem place sprites on screen
sprite 3,200,200,2
button(1,1)=200
sprite 4,262,200,2
button(2,1)=262
sprite 5,323,200,2
button(3,1)=323
sprite 6,385,200,2
button(4,1)=385
sprite 7,445,200,2
button(5,1)=445
rem load y postion
for i=1 to 5
button(i,2)=200
button(i,3)=62 :rem sprite length
button(i,4)=62 :rem sprite height
next i
rem number of button to check
numberofbuttons=5
rem load in pictures to show change path if pictures not availble.
load image "C:WINDOWSWEBWallpaperFollow.jpg",8
load image "C:WINDOWSWEBWallpaperPeace.jpg",9
rem *************************8
rem start main loop
do
rem find out which button and show which is switch on
mychoice=choosebutton(numberofbuttons)
rem show which choice
if mychoice=2
paste image 8,0,0
endif
if mychoice=4
paste image 9,0,0
endif
text 100,100,"The button you presed was ="+str$(mychoice)
rem set mychoice to a number then make if code do or gosub or function.
sync
loop
function choosebutton(manybuttons)
rem is mouse cursor over button
for cbutton=1 to manybuttons
if mousex()=>button(cbutton,1) and mousex()<=button(cbutton,1)+button(cbutton,3) and mousey()=>button(cbutton,2) and mousey()<=button(cbutton,2)+button(cbutton,4) `check to see if the mouses y position is at button 1-18 since it checks 1 each loop and then checks the next
rem if button clicked
if mouseclick()=1 `if you also have the mouse clicked
rem put number in choice
choice=cbutton
endif
endif
rem check if choice = cbutton number
if choice=cbutton
sprite cbutton+2,button(cbutton,1),button(cbutton,2),3 : rem turn on
else
sprite cbutton+2,button(cbutton,1),button(cbutton,2),2 : rem leave off
endif
next cbutton
endfunction choice
In Space No One can Hear You Scream! (When your comm Line is cut?)