I made a console for my game than I gave it to the OMMORPG project since it can be really useful. Here it is for you guys who never look on the site.
Here is the code all put in neat little functions for easy use. With a little test code
sync on
sync rate 60
```````````
``Globals``
```````````
`console lines array type
type cline
line$ as string
color as integer
endtype
`Console array
dim clines(0) as cline
`psentencesarray
dim psentences(-1) as string
`console image varible
global ci as integer
`console line varible
global cl as integer
`console varible
global c as integer
`Input text function varibles
global r as integer
global text$ as string
`````````
``setup``
`````````
setup_console()
make object cube 1,1
`````````````
``main loop``
`````````````
do
`console debugger
if scancode()=41 and c=0 and r=0
clear entry buffer
c=1
r=1
else
if scancode()=41 and c=1 and r=0
c=0
r=1
hide sprite 1
endif
endif
if c=1 then console()
if scancode()=0 then r=0
`sync
sync
loop
```````````````````
`Console functions`
```````````````````
function setup_console()
`draw console and put it in an image
box 0,0,640,150,rgb(0,0,120),rgb(0,0,120),rgb(0,0,120),rgb(0,0,120)
box 0,110,640,130,rgb(0,0,20),rgb(0,0,20),rgb(0,0,20),rgb(0,0,20)
ci=free_image()
get image ci,0,0,640,130
sprite 1,0,0,ci
set sprite alpha 1,50
hide sprite 1
endfunction
function console()
`draw console
paste sprite 1,0,0
`print four things inputed if any
for x=cl to cl+5
if array count(clines()) > x
ink clines(x).color,0
text 0,(x-cl)*20,clines(x).line$
endif
next x
`let them input text
ink rgb(0,120,0),0
temp_string$=My_input(80)
text 0,110,temp_string$
`if they input text
if returnkey()=1 and r=0
`write the string in the next line
console_writeline(temp_string$,rgb(0,120,0))
`see if it is a command
parse_string(temp_string$)
`update varibles
text$=""
r=1
endif
endfunction
function console_writeline(string$,color)
clines(array count(clines())).line$=string$
clines(array count(clines())).color=color
array insert at bottom clines()
if array count(clines()) > 5 then inc cl
endfunction
`This will parse a string from a file or console
function parse_string(string$)
`see if there are any remarks or spaces to exit the function
if left$(string$,2)="\\" or string$="" then exitfunction
`store all words in an array
store_words(string$)
`select the strings command
select lower$(psentences(0))
`see if it matches any of the commands
`object position commands
case "get_object_position"
console_writeline("Object position x: "+str$(object position x(int(val(psentences(1))))),rgb(0,120,0))
console_writeline("Object position y: "+str$(object position y(int(val(psentences(1))))),rgb(0,120,0))
console_writeline("Object position z: "+str$(object position z(int(val(psentences(1))))),rgb(0,120,0))
endcase
case "position_object"
position object int(val(psentences(1))),int(val(psentences(2))),int(val(psentences(3))),int(val(psentences(4)))
endcase
case default
`write the string in the next line
console_writeline("Command "+psentences(0)+" does not exist",rgb(120,0,0))
endcase
endselect
if array count(psentences()) > 0 then empty array psentences()
endfunction
`This is my custom input command
function My_input(max)
text$=text$+entry$()
clear entry buffer
if returnkey()=1 then clear entry buffer
if scancode()=14 and r=0 then text$=left$(text$,len(text$)-1) : r=1
if len(text$) > max then text$=left$(text$,max)
if scancode()=0 then r=0
endfunction text$
function store_words(string$)
for i=1 to words(string$)
`create a new index to store the word
array insert at bottom psentences()
`get the word and store it
psentences(array count(psentences()))=get_word(string$,i)
`if it is a blank element delete the element
if psentences(array count(psentences()))="" then array delete element psentences()
`sync
sync
next i
endfunction
`This will get any word in a string
function get_word(string$,w)
cw=1
repeat
inc i
char$=mid$(string$,i)
if char$=" " or char$="," or char$="" then inc cw
until cw=w
if char$=" " or char$=","
else
dec i
endif
string$=right$(string$,len(string$)-i)
i=0
`create a loop
repeat
inc i
`get the character and see if it is a space or comma
char$=mid$(string$,i)
until char$=" " or char$="," or char$=""
if char$="," then inc i
`delete the other words
string$=left$(string$,i-1)
endfunction string$
function get_parameter(string$,w)
cw=1
repeat
inc i
char$=mid$(string$,i)
if char$="," or char$="" then inc cw
until cw=w
if char$=","
else
dec i
endif
string$=right$(string$,len(string$)-i)
i=0
`create a loop
repeat
inc i
`get the character and see if it is a space or comma
char$=mid$(string$,i)
until char$="," or char$=""
`delete the other words
string$=left$(string$,i-1)
endfunction string$
`This will get how many words are in a string
function words(string$)
w=1
repeat
inc i
char$=mid$(string$,i)
if char$=" " or char$="," then inc w
until char$=""
endfunction w
`This will get the next free image
function free_image()
repeat
inc i
until image exist(i)=0
endfunction i
Here is the lick with all the information since I am to lazy to re-write it here
http://forum.openmmo.co.uk/index.php?topic=412.0
NARUTO IS THE NINJA.....not really
[url=http://forum.openmmo.co.uk/index.php?topic=328.0]
WIP...4 Elements