Name: Input Enhacement
Type: DBP Expansion (Function Set)
Liscense: Free for Commercial/Non Commercial use if credit is given.
Description: A set of functions meant to replace DBP's input command. These functions allow other things to happen in your program while it is working, where DBP's input command freezes your game while waiting for a response from the user. This can be useful for chat messages in multiplayer games, or a name feild when customizing a character.
08/05/06 - Added 3 New Expressions & Added Example
Commands:
InputSetup() `Must be called before using other input commands
MakeInput(gadget,front$,x,y,hascursor,maxchar) `Creates a new input
RequestInput(gadget) `Checks for pressed keys to add to input string
DiplayInput(gadget) `Draws the input on the screen
ResetInput(gadget) `Resets the input and deactivates it
returnvalue=GetInput$(gadget) `Gets the string of the input
returnvalue=GetInputChar(gadget) `Gets the characters in the input string.
returnvalue=GetInputX(gadget) `Returns the x position of the input
returnvalue=GetInputY(gadget) `returns the y position of the input
To use, create a blank DBA file and attach it to your project. Place this inside of it:
Rem *** Include File: inputenhacement.dba ***
Rem Created: 8/5/2006 11:17:11 AM
Rem Input Enhacement
Rem Version 1.0
Rem Written By Airslide
Rem Command List
` Make Input(gadget,front$,x,y,hascursor,maxchar)
` Request Input(gadget)
` Diplay Input(gadget)
` Reset Input(gadget)
` returnvalue=GetInput$(gadget)
` returnvalue=GetInputChar(gadget)
` returnvalue=GetInputX(gadget)
` returnvalue=GetInputY(gadget)
_inputsetup:
global maxgadgets=10
global newinput$
global backspaceused
type tinput
xpos as integer
ypos as integer
maxchar as integer
active as integer
endable as integer
totalinput$ as string
cursor as integer
front$ as string
endtype
global dim inputs(maxgadgets) as tinput
return
function InputSetup()
gosub _inputsetup
endfunction
function RequestInput(gadget as integer)
GenericErrorCheck(gadget)
newinput$=entry$()
ti$=inputs(gadget).totalinput$
if keystate(14)=1
if backspaceused=0 then react=1 : backspaceused=1 : clear entry buffer
else
backspaceused=0
endif
total$=inputs(gadget).totalinput$
if react=0 and len(total$)<inputs(gadget).maxchar then inputs(gadget).totalinput$=ti$+newinput$ : clear entry buffer
if react=1 then inputs(gadget).totalinput$=left$(ti$,len(ti$)-1)
endfunction
function DisplayInput(gadget as integer)
GenericErrorCheck(gadget)
extra$=""
x1=inputs(gadget).xpos
y1=inputs(gadget).ypos
if inputs(gadget).cursor=1 then extra$="|"
text x1,y1,inputs(gadget).front$+inputs(gadget).totalinput$+extra$
endfunction
function ResetInput(gadget as integer)
GenericErrorCheck(gadget)
inputs(gadget).totalinput$=""
endfunction
function MakeInput(gadget as integer,front$ as string,xpos as integer,ypos as integer,cursor as integer,maxchar as integer)
i=gadget
if inputs(i).active=1
exit prompt "This Input Gadget is already taken. Use 'ResetInput(gadget)' to free this input first.","Input Enhancement Error" : end
endif
inputs(i).active=1
inputs(i).xpos=xpos
inputs(i).ypos=ypos
inputs(i).cursor=cursor
inputs(i).front$=front$
inputs(i).maxchar=maxchar
endfunction
function MakeFreeInput(xpos as integer,ypos as integer)
repeat
inc i
if i<maxgadgets
if inputs(i).active<1 then found=1
else
exit prompt "Too many active Input gadgets. Use 'ResetInput(gadget)' to free one first.","Input Enhancement Error" : end
endif
until found
inputs(i).active=1
inputs(i).xpos=xpos
inputs(i).ypos=ypos
endfunction i
function GetInput$(gadget)
GenericErrorCheck(gadget)
a$=inputs(i).totalinput$
endfunction a$
function GetInputChar(gadget)
GenericErrorCheck(gadget)
a=len(inputs(i).totalinput$)
endfunction a
function GetInputX(gadget)
GenericErrorCheck(gadget)
a=inputs(i).xpos
endfunction a
function GetInputY(gadget)
GenericErrorCheck(gadget)
a=inputs(i).ypos
endfunction a
function GenericErrorCheck(gadget)
if gadget>maxgadgets
exit prompt "This Input Number Exceeds the Max Number of Inputs.","Input Enhancement Error" : end
endif
if inputs(gadget).active<1
exit prompt "This Input does not exist or is not active!","Input Enhancement Error" : end
endif
endfunction
Example:
Rem ***** Main Source File *****
sync on : sync rate 0 `This allows us to redraw the input
InputSetup() `This command must be called before input commands
`The following command is not nessasary in most cases. It is usually required by DBP
`to create a 3d object, however, in order for sync to work right.
make object sphere 1,1
`This command will create a new input gadget. Syntax:
`MakeInput(gadget,front$,x,y,cursor,maxchar)
`gadget - The gadget number that handels your input. Must not exist already.
`front$ - the string before the input. Put "" if you don't want anything
`x - The x position on the screen
`y - The y position on the screen
`cursor - A value of 0 or 1. 1 means a cursor will be drawn, 0 means none will.
`maxchar - The maximum number of characters the user can type.
MakeInput(1,"Enter Your Name:",0,0,1,48)
do
`This command adds the pressed keys to the input string. Syntax:
`RequestInput(gadget)
`gadget - The gadget number for the input.
RequestInput(1)
`This command draws the input on the screen. Syntax:
`DisplayInput(gadget)
`gadget - The gadget number for the input.
DisplayInput(1)
`This expression returns the string of the input. Syntax:
`returnvalue=GetInput$(gadget)
`gadget - The gadget number for the input.
test$=GetInput$(1)
sync
loop
Known Bugs:
*If user holds down the backspace key they will have to repeat pressing it several times before deleting prevoius character