I've seen a few posts asking how to accomplish entering text whithout using the INPUT command as it messes up the syncronization of the program, so I've been working on this function. I was concidering creating a library of functions but 1 function should do the job.
The only current working feature is the input of single-line text wherever you want on the screen, but I thought I'd share it as it still works. I know / was working on adding in these features this morning:
- Text Wrapping (So no cut-off words at the end of lines)
- Multi-Line Text Input
- On/Off Setting (So say you wanted to only allow them to input text when they clicked a button)
- Some other things I cant remember right now
Anyways I have to go to a friend's birthday today so I wont have much time to work on the function and tomorrow Im off to a wedding. Ill try and finish off the function tonight but if not tomorrow afternoon should be enough time unless something comes up.
Either way, here's the basic function without the features I mentioned above:
FUNCTION DText(String$, Backspace, Delay#, Rate#)
String$ = String$ + ENTRY$()
CLEAR ENTRY BUFFER
IF KEYSTATE(Backspace) = 1 THEN Delete = 1
IF Delete = 1
WHILE D# <= Delay#
INC D#,Rate#
ENDWHILE
IF D#>=2
CLEAR ENTRY BUFFER
String$=LEFT$(String$,(LEN(String$)-1))
ENDIF
ENDIF
ENDFUNCTION String$
As of right now the while loop stops the program for a second when the backspace is pressed but its just temporary, like I said this is just a basic skeleton of the system but I thought I'd get it out there.
Here's what each parameter currently does:
String$ : The String variable name to store the input data in.
Backspace : The keystate for the backspace button, added this param incase people didnt want to use the backspace key (which is keystate 14 if you're wondering)
Delay# : The Delay# between backspaces, use this with the next param to get the desired result
Rate# The rate of decrease that Delay# goes by. So if Delay# was 5000 and Rate# was 1, it would loop 5000 times decreasing Delay# by 1.
And a sample of using the function:
SYNC ON:SYNC RATE 0:AUTOCAM OFF:HIDE MOUSE
MAKE OBJECT CUBE 1,10
POSITION CAMERA 0,200,-300
POINT CAMERA 0,0,0
DO
D$=DText(D$,14,500,.0005)
CENTER TEXT OBJECT SCREEN X(1),OBJECT SCREEN Y(1)-50,D$
IF UPKEY()=1 THEN MOVE OBJECT 1,.1
IF DOWNKEY()=1 THEN MOVE OBJECT 1,-.1
IF LEFTKEY()=1 THEN MOVE OBJECT LEFT 1,.1
IF RIGHTKEY()=1 THEN MOVE OBJECT RIGHT 1,.1
SYNC
LOOP
FUNCTION DText(String$, Backspace, Delay#, Rate#)
String$ = String$ + ENTRY$()
CLEAR ENTRY BUFFER
IF KEYSTATE(Backspace) = 1 THEN Delete = 1
IF Delete = 1
WHILE D# <= Delay#
INC D#,Rate#
ENDWHILE
IF D#>=2
CLEAR ENTRY BUFFER
String$=LEFT$(String$,(LEN(String$)-1))
ENDIF
ENDIF
ENDFUNCTION String$
Move with the arrow keys / type your message with... all... of the keys
And use backspace to delete.
As you'll see the backspace halts the program because of the size of the loop, not to worry Ill fix that when I release the full version.
Last note; The function returns the string to be displayed. Looking at the code you'll notice that in the sample you pass the string returned as the string name, this prevents you from having to declare string as a global.
- RUC'