Here is an example of a simple console. All console vars are Typed
so they will be unique to the console. In this case, press the "`"
(Tilde) key to drop/raise the console.
Set Con.S_Flag = 1 if your main program uses sync, 0 if not.
Con.Red,Con.Green and Con.Blue can set Console Screen Color,
and each would be 0-255.
Var Con.In will hold the entire command to be parsed. In
this example it is set to "" at each line-feed.
Con vars are Global, and it should be easy to add to them.
The console will show the last 8 lines entered.
Rem Project: dCon
Rem Created: 2/25/2006 5:54:37 PM
Rem ***** Main Source File *****
set display mode 800,600,32
`====Console Setup====
gosub SetCon
Con.S_Flag=1
Con.Red=10:Con.Green=10:Con.Blue=50
`=====================
backdrop on 0
make object cube 1,1
sync on
do
control camera using arrowkeys 0,0.01,0.01
turn object left 1,0.1
`==Call Console==
if inkey$()="`"
gosub Con2
endif
sync
loop
`============Console Setup==============
SetCon:
type ConScreen
xCon as integer
yCon as integer
zCon as integer
Y2 as integer
xText as integer
wText as integer
c as integer
t as integer
Bf as integer
S_Flag as integer
Cam as integer
Red as integer
Green as integer
Blue as integer
In as string
Ck as string
Rr as string
endtype
type ConBuffer
yText as integer
Back as string
endtype
global Con as ConScreen
`array size (back text buffer)
Con.Bf=10
dim Buffer(Con.Bf) as ConBuffer
`console camera
Con.Cam=10
`console size
Con.xCon=screen width()
Con.yCon=screen height()/3
Con.zCon=screen depth()
Con.Y2=0
`set up vertical text locations
Con.t=2
while Con.t<Con.Bf
Buffer(Con.t).yText=Con.yCon-Con.t*18
inc Con.t,1
endwhile
`active text line
Con.wText=Con.yCon-18
make camera Con.Cam
set camera view Con.Cam,0,0,Con.xCon,0
backdrop on Con.Cam
set current bitmap 0
return
`=======this is called from your main program======
`bring console down
Con2:
color backdrop Con.Cam,RGB(Con.Red,Con.Green,Con.Blue)
while Con.Y2<Con.yCon
inc Con.Y2,2
set camera view Con.Cam,0,0,Con.xCon,Con.Y2
if Con.S_Flag=1
sync
endif
endwhile
set current camera Con.Cam
`input text to console
do
text Con.xText,Con.wText,"> "+Con.In
Con.t=2
while Con.t<Con.Bf
if Buffer(Con.t).Back<>""
text Con.xText,Buffer(Con.t).yText,"> "+Buffer(Con.t).Back
endif
inc Con.t,1
endwhile
`start input routine
if Con.Ck=""
Con.Rr=""
Con.Ck=inkey$()
while inkey$()<>""
Con.Rr=inkey$()
text Con.xText,Con.wText,"> "+Con.In
endwhile
endif
if Con.Rr<>Con.Ck
Con.Ck=Con.Ck+Con.Rr
endif
`parse for control keys
`if tilde exit console
if Con.Ck="`"
Con.Ck=""
exit
endif
`if backspace, do backspace
if asc(Con.Ck)=8
Con.Ck=""
Con.c=len(Con.In)
if Con.c>0
Con.In=left$(Con.In,Con.c-1)
endif
endif
`return key - do line feed
`Con.In will hold commands
`to parse and is Global.
if asc(Con.Ck)=13
Con.Ck=""
Con.t=Con.Bf
while Con.t>2
Buffer(Con.t).Back=Buffer(Con.t-1).Back
dec Con.t,1
endwhile
Buffer(2).Back=Con.In
Con.In=""
endif
`not control key, add to string
if Con.Ck<>""
Con.In=Con.In+Con.Ck
Con.Ck=""
endif
if Con.S_Flag=1
sync
endif
loop
`roll up console window and exit console
while Con.Y2>0
dec Con.Y2,2
set camera view Con.Cam,0,0,Con.xCon,Con.Y2
if Con.S_Flag=1
sync
endif
endwhile
set current camera 0
return
`========end console routine=====================
-JerBil
Ad Astra Per Asper