Quote: "points 2,3,4,5, and 6 are things i don't know how to do, also how"
#2 it just a standard variable that represents the start of the window viewed text. If you use the command ARRAY COUNT() that shows how big the array is and subtract 10 you'll start 10 lines from the bottom of the array. I changed it to 10 lines to fit in your console window.
` Create the Buffer array
dim Buffer$(1000)
` Set the top-of-the-window variable
BuffTop=array count(Buffer$())-10
#3 is a FOR/NEXT loop that shows the array starting from the top-of-the-window variable to 10 lines after the top-of-the-window variable.
` Show the buffer
for t=BuffTop to BuffTop+10
` Show the buffer line
text 0,y,"Buffer$("+str$(t)+") = "+Buffer$(t)
inc y,20
next t
#4 can be done a couple of ways. You can use a FOR/NEXT loop to reassign each element in the array or you can use IanMs Matrix 1 Utilities Plugins ROTATE ARRAY command.
` Move all the strings in the buffer up one line
for t=1 to BuffEnd
Buffer$(t-1)=Buffer$(t)
next t
` Move all the strings in the buffer up one line
rotate array Buffer$()
#5 and #6 you use the INC and DEC command to increase/decrease the number.
` Decrease the top-of-the-window variable BuffTop
dec BuffTop
` Increase the top-of-the-window variable BuffTop
inc BuffTop
` Decrease the top-of-the-window variable BuffTop by 11
dec BuffTop,11
` Increase the top-of-the-window variable BuffTop by 11
inc BuffTop,11
Quote: "this is the console that i have made from your code, but there is also problem with console that can open and close with the same key, like pressing tilde key for opening and closing of the console."
The easiest way to use the same key for both turning on and off the console and not opening and quickly closing the console window again is to use a REPEAT/UNTIL loop after the user hits the key to check for no keys are being pressed. It does stop all action till the user lets go of the key but generally people don't sit there and hold the key down forever.
` Check for the console key `
if keystate(41)
` Check if the console switch is already on
if Console=1
` Turn the switch off
Console=0
else
` Turn the switch on
Console=1
endif
` Wait for the user to lets go of the key
repeat
until scancode()=0
` Clear the buffer
clear entry buffer
endif
Here's the entire program:
sync rate 0
sync on
` Create the Buffer array
dim Buffer$(1000)
` Make sure BuffTop and BuffEnd are global so they can be seen in functions
global BuffTop
global BuffEnd
` Make an object
make object cube 1,1
` Set the rotate switch
Rotate=1
` Set a timer
tim=timer()
` Set the starting delay
Delay=50
` Set the top-of-the-window variable
BuffTop=array count(Buffer$())-10
` Set the bottom of the array
BuffEnd=array count(Buffer$())
do
` Check for the console key `
if keystate(41)
` Check if the console switch is already on
if Console=1
` Turn the switch off
Console=0
else
` Turn the switch on
Console=1
endif
` Wait for the user to lets go of the key
repeat
until scancode()=0
` Clear the buffer
clear entry buffer
endif
` Check if the console window is on
if Console=1
` Show console
`text 10,10,"Console Window Open"
box 0,0,screen width(),screen height()/2,rgb(0,0,0)
line 0,screen height()/2-1,screen width(),screen height()/2-1,rgb(0,200,0)
line 0,screen height()/2,screen width(),screen height()/2,rgb(0,200,0)
text 0,screen height()/2-20,"]"+Comm$+"_"
`line 0,screen height()/2-22,screen width(),screen height()/2-22,rgb(0,200,0)
`line 0,screen height()/2-23,screen width(),screen height()/2-23,rgb(0,200,0)
` Reset y to zero
y=0
` Show the buffer
for t=BuffTop to BuffTop+10
` Show the buffer line
text 0,y,"Buffer$("+str$(t)+") = "+Buffer$(t)
inc y,20
next t
` Grab a key and clear the buffer
a$=entry$():clear entry buffer
` Check for backspace
if asc(a$)=8 then Comm$=left$(Comm$,len(Comm$)-1):a$=""
` Check for enter
if asc(a$)=13
` Call the AddBuffer function to add the command line to the buffer
AddBuffer(Comm$)
` Make the user input higercase
Comm$=upper$(Comm$)
` Find the command
select Comm$
` Rotate on
case "START"
` Check if rotating already
if Rotate=1
` Add to the buffer it's already rotating
AddBuffer("Error: Object already rotating.")
else
` Add to the buffer the change
AddBuffer("Confirmed: Object now rotating.")
endif
` Turn on Rotate switch
Rotate=1
endcase
` Rotate off
case "STOP"
` Check if not rotating already
if Rotate=0
` Add to the buffer it's already rotating
AddBuffer("Error: Object already stopped.")
else
` Add to the buffer the change
AddBuffer("Confirmed: Object stopped.")
endif
` Turn off Rotate switch
Rotate=0
endcase
` Slow down rotation
case "SLOW"
` Increase the delay by 50
inc Delay,50
AddBuffer("Confirmed: Object delay increased to "+str$(Delay)+" miliseconds.")
endcase
` Speed up rotation
case "FAST"
` Decrease the delay by 50
dec Delay,50
AddBuffer("Confirmed: Object delay decreased to "+str$(Delay)+" miliseconds.")
endcase
` No commands selected
case default
AddBuffer("Error: Command not recognized.")
endcase
endselect
` Reset command string
Comm$=""
` Turn off the console window
`Console=0
` Clear a$
a$=""
endif
` Add character to Comm$
Comm$=Comm$+a$
` Check for up arrow (to scroll buffer up)
if keystate(200) and BuffTop-1>-1
` Decrease the top-of-the-window variable BuffTop
dec BuffTop
endif
` Check for down arrow (to scroll buffer down)
if keystate(208) and BuffTop+10<BuffEnd
` Increase the top-of-the-window variable BuffTop
inc BuffTop
endif
` Check for pageup
if keystate(201)
` Decrease the top-of-the-window variable BuffTop by 11
dec BuffTop,11
` Make sure BuffTop stays within the array
if BuffTop<0 then BuffTop=0
endif
` Check for pagedown
if keystate(209)
` Increase the top-of-the-window variable BuffTop by 11
inc BuffTop,11
` Make sure BuffTop stays within the array
if BuffTop+10>BuffEnd then BuffTop=BuffEnd-10
endif
endif
` Check if it's time to rotate the object
if Rotate=1 and timer()>tim+Delay
` Rotate the object
rotate object 1,wrapvalue(Angle),0,0
` Increase the rotation
inc Angle
` Reset the timer
tim=timer()
endif
sync
loop
end
function AddBuffer(Tex$)
` Move all the strings in the buffer up one line
for t=1 to BuffEnd
Buffer$(t-1)=Buffer$(t)
next t
`rotate array Buffer$()
` Add the last command line to the buffer
Buffer$(BuffEnd)=Tex$
endfunction
And if you really want to make cool programs you need to add IanMs Matrix 1 Utilities Plugin to Darkbasic Pro (so you can use ROTATE ARRAY).
http://forum.thegamecreators.com/?m=forum_view&t=85209&b=18