Moved on a bit now has scroll bars( also by Phaelax), you can pick an item and it will turn red plus it is also put in the other list.
in the down load there is the images you need for the sprite plus two txt files one containing some food items, but the list could be anything you want.
the code
Rem Project: scrolltextbox1
Rem Created: 20/03/2008 09:35:06
` This code was downloaded from The Game Creators
` It is reproduced here with full permission
` http://www.thegamecreators.com
`set display mode 1024,768,16
rem found orginal by Phaelax in code base
rem modfied to take two files and display them
rem plus able to pick from left list to add to right list
rem also able to remove an item from the right list.
#constant SLIDER_HORIZONTAL = 1
#constant SLIDER_VERTICAL = 2
type sliderComponent
x as integer
y as integer
min as float
max as float
value as float
isDragging as boolean
mOffsetX as float
mOffsetY as float
thumbX as float
thumbY as float
endtype
type sliderComponentUI
trackWidth as float
trackHeight as float
trackColor as dword
thumbWidth as float
thumbHeight as float
thumbColor as dword
orientation as byte
endtype
global s as sliderComponent
s.x = 303
s.y = 85
s.min = 1
s.value = 1
s.thumbX = s.x
s.thumbY = s.y
sliderUI as sliderComponentUI
sliderUI.trackWidth = 18
sliderUI.trackHeight = 390
sliderUI.trackColor = rgb(192,192,192)
sliderUI.thumbWidth = 20
sliderUI.thumbHeight = 13
sliderUI.thumbColor = rgb(128,128,128)
sliderUI.orientation = SLIDER_VERTICAL
global s2 as sliderComponent
s2.x = 333
s2.y = 85
s2.min = 1
s2.max = 200
s2.value = 1
s2.thumbX = s2.x
s2.thumbY = s2.y
sliderUI2 as sliderComponentUI
sliderUI2.trackWidth = 18
sliderUI2.trackHeight = 390
sliderUI2.trackColor = rgb(192,192,192)
sliderUI2.thumbWidth = 20
sliderUI2.thumbHeight = 13
sliderUI2.thumbColor = rgb(128,128,128)
sliderUI2.orientation = SLIDER_VERTICAL
load image "bar.png", 1,1
load image "ends.png", 2,1
load image "thumb.png", 3,1
rem text file to display
rem file filled with some items
filename$ = "item.txt"
rem file with nothing in it
filename2$ ="picked.txt"
rem wrap text to this many characters (0 for no text wrapping)
maxCharWidth = 35
rem array list to hold text from file
dim words1$(0) as string
dim words2$(0) as string
rem check to see if file specified is a text file
if lower$(right$(filename$, 4)) = ".txt"
rem check if file exists
if file exist(filename$)
rem open file for reading
open to read 1, filename$
rem add text from file to array list
while file end(1) = 0
read string 1, temp$
if maxCharWidth > 0
wrapText(temp$, maxCharWidth, 0)
else
array insert at bottom words1$(0)
words1$(array count(words1$(0))) = temp$
endif
endwhile
endif
endif
s.max = array count(words1$(0))-25
dim picked(s.max+25)
dim added(0)
for o = 0 to s.max
picked(o)=0
next o
rem close the file
close file 1
if lower$(right$(filename2$, 4)) = ".txt"
rem check if file exists
if file exist(filename2$)
rem open file for reading
open to read 1, filename2$
rem add text from file to array list
while file end(1) = 0
read string 1, temp$
if maxCharWidth > 0
wrapText(temp$, maxCharWidth, 1)
else
array insert at bottom words2$(0)
words2$(array count(words2$(0))) = temp$
endif
endwhile
endif
endif
rem close the file
close file 1
global downformtop leftboxposition rightboxposition boxLength boxHeight clicked
downformtop = 80
leftboxposition = 10
rightboxposition = 350
lin as integer
count as integer
tx as integer
ty as integer
lin = 1
count = 25
tx = leftboxposition
ty = downformtop
lin2 as integer
count2 as integer
tx2 as integer
ty2 as integer
lin2 = 1
count2 = 25
tx2 = rightboxposition
ty2 = downformtop
boxLength = text width(space$(maxCharWidth))
if maxCharWidth = 0 then boxLength = screen width()
boxHeight = text height(space$(1))*(count+1)
repeat
cls
_handleSliderVertical(sliderUI)
_handleSliderVertical2(sliderUI2)
rem mouse bar move list
if s.value>1
if mouseclick()=1 and s.min<s.value
if lin > 1 then lin=int(s.value)
endif
if mouseclick()=1 and s.max>s.value
if lin< array count (words1$(0))-count then lin=int(s.value)
endif
endif
if s2.value>1
if mouseclick()=1 and s2.value>s2.min
if lin2 > 1 then lin2=int(s2.value)
endif
if mouseclick()=1 and s2.value<s2.max
if lin2< array count (words1$(0))-count then lin2=int(s2.value)
endif
endif
rem move list with keys
if upkey() = 1
if lin > 1 then dec lin, 1
endif
if downkey() = 1
if lin < array count(words1$(0))-count then inc lin, 1
endif
rem box to show text boundaries
ink rgb(255,255,255),0
box tx-2, ty-2, tx+boxLength+2, ty+boxHeight+2
ink rgb(100,100,100),0
box tx, ty, tx+boxLength, ty+boxHeight
rem display the text
showText(tx,ty,lin,count, rgb(255,128,255),0)
if leftkey() = 1
if lin2 > 1 then dec lin2, 1
endif
if rightkey() = 1
if lin2 < array count(words2$(0))-count2 then inc lin2, 1
endif
rem box to show text boundaries
ink rgb(255,255,255),0
box tx2-2, ty2-2, tx2+boxLength+2, ty2+boxHeight+2
ink rgb(100,100,100),0
box tx2, ty2, tx2+boxLength, ty2+boxHeight
rem display the text
showText(tx2,ty2,lin2,count2, rgb(255,128,255),1)
until spacekey()
rem wraps text and adds lines appropriately to array list
function wrapText(t$ as string, max as integer, t as integer )
if t= 0
r$ = left$(t$,max)
array insert at bottom words1$(0)
i = array count(words1$(0))
words1$(i) = r$
nl = len(t$) - max
if nl > 0
t$ = right$(t$,nl)
wrapText(t$, max , 0)
endif
endif
if t= 1
r$ = left$(t$,max)
array insert at bottom words2$(0)
i = array count(words2$(0))
words2$(i) = r$
nl = len(t$) - max
if nl > 0
t$ = right$(t$,nl)
wrapText(t$, max , 1)
endif
endif
endfunction
rem displays text starting at coordinates X,Y and starts with line "lin"
rem showing "count" number of rows (or until end of text is reached)
function showText(x as integer, y as integer, lin as integer, count as integer, color as dword, t as integer )
if t=0
if lin > 0
th = text height(words1$(1))
L = 0
for t = lin to lin+count
if t <= array count(words1$(0))
if mousex()>leftboxposition and mousex()<leftboxposition + boxlength
if mousey()> y+l*th and mousey()<y+l*th+th
if picked(t)<>0
ink color+4000, 0
text x, y + L*th, words1$(t)
else
ink color+1700, 0
text x, y + L*th, words1$(t)
endif
if mouseclick()=1 and clicked<>1
clicked = 1
if picked(t)<>1
picked(t)=1
words2$(array count(words2$(0)))=words1$(t)
array insert at bottom words2$(0)
array insert at bottom added(0)
added(array count(added(0)))=t
endif
endif
else
if picked(t)=1
rem picked color
ink rgb(0,255,0), 0
text x, y + L*th, words1$(t)
else
ink color, 0
text x, y + L*th, words1$(t)
endif
endif
` endif
else
if picked(t)=1
rem picked color
ink rgb(0,255,0), 0
text x, y + L*th, words1$(t)
else
ink color, 0
text x, y + L*th, words1$(t)
endif
endif
inc L
endif
next t
endif
endif
if t=1
if lin > 0
th = text height(words2$(1))
L = 0
ink color, 0
for t = lin to lin+count
if t <= array count(words2$(0))
if mousex()>rightboxposition and mousex()<rightboxposition + boxlength
if mousey()> y+l*th and mousey()<y+l*th+th
ink color+1700, 0
text x, y + L*th, words2$(t)
if mouseclick()=1 and clicked<>1
clicked = 1
ARRAY DELETE ELEMENT words2$(0),t
picked(added(t))=0
ARRAY DELETE ELEMENT added(0),t
endif
else
ink color, 0
text x, y + L*th, words2$(t)
endif
else
ink color, 0
text x, y + L*th, words2$(t)
endif
inc L
endif
next t
endif
endif
if mouseclick()=0
clicked=0
endif
endfunction
rem Vertical Slider
function _handleSliderVertical(ui as sliderComponentUI)
rx = sliderUI.trackHeight / 64
x# = s.x - ui.trackWidth/2
rem slider bar
for i = 1 to rx
paste image 1, x#,s.y+(i-1)*64
next i
rem top and bottom ends of slider bar
paste image 2, x#,s.y-7
paste image 2, x#,s.y+64*rx
rem draw thumb
sprite 1,x#, s.thumbY-3,3
rem handle mouse events
if mouseclick() = 1 and s.isDragging = 0
if mousex() >= x# and mousex() <= x#+ui.thumbWidth
if mousey() >= s.thumbY and mousey() <= s.thumbY+ui.thumbHeight
s.isDragging = 1
s.mOffsetY = s.thumbY - mousey()
endif
endif
endif
if s.isDragging = 1
s.thumbY = mousey() + s.mOffsetY
if s.thumbY < s.y then s.thumbY = s.y
if s.thumbY > (s.y+ui.trackHeight)-ui.thumbHeight then s.thumbY = (s.y+ui.trackHeight)-ui.thumbHeight
rem set slider value
s.value = ((s.max - s.min) * (s.thumbY-s.y)) / (ui.trackHeight-ui.thumbHeight)
endif
if mouseclick() <> 1 then s.isDragging = 0
endfunction
function _handleSliderVertical2(ui as sliderComponentUI)
rx = sliderUI2.trackHeight / 64
x# = s2.x - ui.trackWidth/2
rem slider bar
for i = 1 to rx
paste image 1, x#,s2.y+(i-1)*64
next i
rem top and bottom ends of slider bar
paste image 2, x#,s2.y-7
paste image 2, x#,s2.y+64*rx
rem draw thumb
sprite 2,x#, s2.thumbY-3,3
rem handle mouse events
if mouseclick() = 1 and s2.isDragging = 0
if mousex() >= x# and mousex() <= x#+ui.thumbWidth
if mousey() >= s2.thumbY and mousey() <= s2.thumbY+ui.thumbHeight
s2.isDragging = 1
s2.mOffsetY = s2.thumbY - mousey()
endif
endif
endif
if s2.isDragging = 1
s2.thumbY = mousey() + s2.mOffsetY
if s2.thumbY < s2.y then s2.thumbY = s2.y
if s2.thumbY > (s2.y+ui.trackHeight)-ui.thumbHeight then s2.thumbY = (s2.y+ui.trackHeight)-ui.thumbHeight
rem set slider value
s2.value = ((s2.max - s2.min) * (s2.thumbY-s2.y)) / (ui.trackHeight-ui.thumbHeight)
endif
if mouseclick() <> 1 then s2.isDragging = 0
endfunction
Dark Physics makes any hot drink go cold.