first off id like to apologize for the naming of my variables i usually just give them a letter and a number and move on however i tried to comment as best i could.
so i had an itch to build a custom browser for my world editor for loading and exporting models ect.
My problem is im trying to reuse me function text_position() on line 405. it worked fine when it was part of the main body of the other function normallisting() you can see i stuck it back in there so it would run. i sucessfully reused it in my other function file_type_filter(). but the same code wont run in the function i built it for and im kinda baffled so i thought i would try to global the command obviously but it seems to throw me a compiler error and i dont understand because its always used as an integer.attached is the media
`Created. 9,2,2014
`Owner: Jacob Clayton
`Email: Smerfboyblue@yahoo.com
`This Browser is free to use in any program as long as any..
`program or product sold for profit or community open source gives credit to the author..
`"me"as a programmer on the project..
`enjoy it. it was so much fun to write :P
set window on
set window layout 0,0,1
set window title "File Browser"
set window position 200,200
sync on
sync rate 60
fastsync
load image "highlight.bmp",1,1
`delcaring sprite varaibles for easier reading and programming
abrowser#=11
achecka#=12
acheckb#=20
adrvlst#=13
ascroll#=14
amainbar#=15
amousep#=2
amousel#=16
`global aa
global ak#
global ahh# as byte
global aline#
global ag#
global clic$ as string
global arr# as word
global att# as word
global ag# as word
global ab# as byte
global tt
global filetype as byte
global imagenum as byte
global typequantity
global filetype
global a4# as word
global a5# as word
global a6# as word
global a7# as word
global a8# as word
global a10# as word
global a11# as word
global a12# as word
load image "file browser.bmp",abrowser#,1
load image "folder.bmp",17,1
load image "bmp.bmp",18,1
load image "ini.bmp",19,1
load image "scroll bar.bmp",ascroll#
LOAD IMAGE "MOUSE.BMP",amousel#,1
get image amousep#,0,0,1,1,1
set text font "modern"
set text size 12
`SET UP SPRITES
sprite ascroll#,27,308,ascroll#
set sprite priority ascroll#,15
set sprite ascroll#,2,1
sprite abrowser#,0,0,abrowser#
set sprite priority abrowser#,abrowser#
set dir "c:\program files"
`create scrolling background
create bitmap 3,1220,310
SET CURRENT BITMAP 0
draw sprites first
filter =0
`*******************************************************************************************************
`*******************************************************************************************************
Do
`Whole program inside Timer to reduce lag it may cause in your main program
StartTime=timer()
`sets each row of text to start 48 px for the top cause sprite is covering top
a4#=48
a5#=48
a6#=48
a7#=48
a8#=48
a10#=48
a11#=48
a12#=48
`tt=time to time for timer start
if tt > 10
set current bitmap 3
ink rgb (255,255,255),0
box 0,0,1220,310
ink RGB(1,10,1),0
if filter=0
normallisting()
endif
if filter >0
file_type_filter()
endif
`starting the checklist
`and setting the cursor to print 20 lines at a time inc xpost 190 and line spacing 12px same as font size
endif
EndTime=timer()
ElapsedTime=EndTime-StartTime
tt=tt+elapsedtime
`setinng 2 sprites at mouse current pos
`1 for scrolling 1 for pin pointing
`and showing/hiding sprites when hit
sprite amousep#,mousex(),mousey(),amousep#
sprite amousel#,mousex(),mousey(),amousel#
`##############################
` keeping scroll sprite from going off the page
astop#=337+sprite x(ascroll#)-sprite x(ascroll#)
aend#=27-sprite x(ascroll#)+sprite x(ascroll#)
if sprite x (ascroll#) < 27
sprite ascroll#,aend#,308,ascroll#
endif
if sprite x (ascroll#) >400
sprite ascroll#,astop#,308,ascroll#
endif
if sprite collision (amousel#,ascroll#)=1 and mouseclick()=1
sprite ascroll#,mousex(),308,ascroll#
endif
`page movment
`this is for scrolling of the text
`it will scroll -190 px to the left for each row of "20 lines of text" divided
` buy the width of the bar and ho many total rows of text there are
apage#= (int(ab#/20))
ak#=0
for ar = 1 to apage#
if sprite x(ascroll#) > 710/ar
inc ak#,ar/ar+-190
endif
next ar
`checkling to see witch row we are currently on
`checks up to 8 rows * 20 files per row = 160 files total at the moment
`can easily be increased
If ak#=0
ag#=0
Endif
null1#=-189
null2#=20
for i= 1 to 8
IF ak#= null1#
aG#=null2#
ENDIF
dec null1#,189
inc null2#,20
next
` getting mouse position divide it buy spacing to make it the same as checklist count then subtracting
`8 because the file browser is 8 off because of the top sprite
aline#=((mousey()+60)/12)-8
`show or hide highlighter if its showing when its not supposed to.
if sprite collision (amousel#,ascroll#)=0
if sprite exist(1)=1
show sprite 1
endif
highlighter()
else
if sprite exist(1)=1
hide sprite 1
endif
endif
`return key set directory to clic$
dir$=get dir$()
if returnkey()=1
wait 100
set dir clic$
endif
`set dir dir$
open_file()
loop
`prints current checklist when mouse is clicked and hilights current one with sprite
`tells what row is being clicked and where the mouse is on that row
`1st columb
function highlighter()
if mouseclick()=1 and mousex() < 180 and mousey()<288 and mousey() > 48
`rest each rows values or they accidentally stack and give wrong checklist values
att#=0
arr#=0
` if stament to make sure mouse is clicked it doesnt try to return a invalid checklist#
if aline#+ag# <= ab#
`aline=mousey()/font size or pixels plus ag which is how many rows the sprite has scrolled scroll -189px at a time
`so basically a quick breakdown and explanation
`20 lines per culumn spaced at 12 pixels same as fotn size, so to determin the checklist item
`selected since u cant read text off a sprite checklist= aline# wich is the mouse position divided buy 12 so
` if u were on the fith checklist number 12x5 pixels would say 5!!!!
`then since the checklist is in rows of 20 buy adding ag# to aline#, ag reads the ak# variable wich says how far the
`screen has been scrolled and increments ag buy 20.
`so to summerize ak#= if column has been scrolled
`ag# incremented buy 20 for each scroll
`aline telling what item in each row is selected
`so if page is scrolled once and the third item is picked
`checklist = aline#(3)+ag#(1)= 4th column 3rd item or checlkist number 43 phew
`get the lenght of the currently selected string file/folder and scale the highlighter to it
ahh#=text width (checklist string$(aline#+ag#))
`sprite width of string
sprite 1,30,aline#*12+36,1
set sprite alpha 1,80
set sprite priority 1,100
size sprite 1,ahh#+16,12
`click to print text
clic$=checklist string$(aline#+ag#)
endif
endif
`2nd columb
if mouseclick()=1 and mousex()>180 and mousex()< 350 and mousey()<288 and mousey() >48
att#=0
ahh#=0
if aline#+20+ag# <= ab#
arr#=text width (checklist string$(aline#+20+ag#))
sprite 1,220,aline#*12+36,1
set sprite alpha 1,80
set sprite priority 1,100
size sprite 1,arr#+16,12
`prints text
clic$=checklist string$(aline#+20+ag#)
else
arr#=0
endif
endif
`3rd columb
if mouseclick()=1 and mousex() >=350 and mousex()<455 and mousey()<288 and mousey() >48
arr#=0
ahh#=0
if aline#+40+ag# <= ab#
att#=text width (checklist string$(aline#+40+ag#))
sprite 1,410,aline#*12+36,1
`if att to keep highlighter from running out into program on
`third row if its to long it shortens it to the browser width
if att#>30
size sprite 1,42,12
else
size sprite 1,att#+16,12
endif
set sprite alpha 1,80
set sprite priority 1,100
`prints text
clic$=checklist string$(aline#+40+aG#)
endif
endif
endfunction
function open_file()
text 600,500,"Open"
`set dir path$
`file_type_filter()
endfunction
function save_file()
`set dir path$
`file_type_filter()
endfunction
function file_type_filter()
perform checklist for files
find first
ab#=checklist quantity()
for i=1 to ab#
find next
filetype=checklist value a(i)
if right$(checklist string$(i),2)="bj" or right$(checklist string$(i),2)=".x" or right$(checklist string$(i),2)="sm"
inc aa,1
text_position()
`ink rgb (0,1,0),0
print checklist string$(i)
aa=0
endif
next
get image 3,0,0,460,310,1
set current bitmap 0
sprite 40,0,0,3
sync
if tt > 100
tt=0
endif
endfunction
function file_type_image()
`controls pasting file type icons on browser
if a4# > 48 then paste image imagenum,10+ak#,(a4#-14),1
if a5# > 48 then paste image imagenum,200+ak#,(a5#-14),1
if a6# > 48 then paste image imagenum,390+ak#,(a6#-14),1
if a7# > 48 then paste image imagenum,580+ak#,(a7#-14),1
if a8# > 48 then paste image imagenum,770+ak#,(a8#-14),1
if a10# > 48 then paste image imagenum,960+ak#,(a10#-14),1
if a11# > 48 then paste image imagenum,1150+ak#,(a11#-14),1
if a12# > 48 then paste image imagenum,1340+ak#,(a12#-14),1
endfunction
function drivelst()
endfunction
function normallisting()
perform checklist for files
find first
ab#=checklist quantity()
for aa =1 to ab#
find next
`aa=get file type()
if aa <=20
set cursor 30+ak#,a4#
inc a4#,12
endif
if aa >20 and aa <=40
set cursor 220+ak#,a5#
inc a5#,12
endif
if aa > 40 and aa <=60
set cursor 410+ak#,a6#
inc a6#,12
endif
if aa > 60 and aa <=80
set cursor 600+ak#,a7#
inc a7#,12
endif
if aa > 80 and aa <=100
set cursor 790+ak#,a8#
inc a8#,12
endif
if aa > 100 and aa <=120
set cursor 980+ak#,a10#
inc a10#,12
endif
if aa > 120 and aa<= 140
set cursor 1170+ak#,a11#
inc a11#,12
endif
if aa > 140 and aa <=160
set cursor 1200+ak#,a12#
inc a12#,12
endif
`******************************************************************
a90#=checklist value a(aa)
`endif this code below is what actually prints the checklist on the screen. It will check and see if
`if the string /file name is longer than 170 px or 28 character and reduce it so it fitst properly.
`it also makes sure if it is a directory that it has extension .dir on it else it prints the normal file name
`and extension if the file name is longer than 170 it adds ... and dir to it.
`it servers no purpose in the acutal progam as of now exepct to let me know if a file is a dir for testing purpoes
if text width (checklist string$(aa)) > 170
print left$(checklist string$(aa),28)+"...."
if a90#=1
print left$(checklist string$(aa),28)+".dir"
endif
else
if a90#=1
imagenum=17
file_type_image()
print checklist string$(aa)+".dir"
else
if a90#=0
if right$(checklist string$(aa),3)="BMP"
imagenum=18
file_type_image()
else
if a90#=0
if right$(checklist string$(aa),3)="ini" or right$(checklist string$(aa),3)="bat" or right$(checklist string$(aa),3)="inf"
imagenum=19
file_type_image()
endif
endif
endif
endif
print checklist string$(aa)
endif
endif
next aa
get image 3,0,0,460,310,1
set current bitmap 0
sprite 40,0,0,3
text 120,334,clic$
text 120,362,str$(tt)
sync
if tt > 100
tt=0
endif
endfunction
function text_position()
if aa <=20
set cursor 30+ak#,a4#
inc a4#,12
endif
if aa >20 and aa <=40
set cursor 220+ak#,a5#
inc a5#,12
endif
if aa > 40 and aa <=60
set cursor 410+ak#,a6#
inc a6#,12
endif
if aa > 60 and aa <=80
set cursor 600+ak#,a7#
inc a7#,12
endif
if aa > 80 and aa <=100
set cursor 790+ak#,a8#
inc a8#,12
endif
if aa > 100 and aa <=120
set cursor 980+ak#,a10#
inc a10#,12
endif
if aa > 120 and aa<= 140
set cursor 1170+ak#,a11#
inc a11#,12
endif
if aa > 140 and aa <=160
set cursor 1200+ak#,a12#
inc a12#,12
endif
endfunction
A child's dream never dies.