User input in Font.Draw
Author |
Message |
neufelni
|
Posted: Mon Jun 06, 2005 11:07 am Post subject: User input in Font.Draw |
|
|
I need help with this. Almost everything is working but the backspace isn't working quite properly. I can backspace it but it still puts the deleted letters later when the full name is displayed. It only deletes the last letter entered. Can any one help?
code: |
setscreen ("graphics: max; max, nocursor, noecho")
colourback (black)
cls
var name : string (1)
var namex : int := 270
var font1 : int := Font.New ("Impact:30")
var fullname : string := ""
var num : int := 1
Font.Draw ("Enter your name: ", 10, 500, font1, 14)
loop
getch (name)
exit when name = (KEY_ENTER)
if name = (KEY_BACKSPACE) and namex > 270 then
Draw.FillBox (namex, 450, namex + 30, 600, 7)
namex := namex - 30
fullname :=fullname(1..num-2)+" "
elsif name = "q" or name = "Q" or name = "w" or name = "W" or name = "e" or name = "E" or name = "r" or name = "R" or name = "t" or name = "T" or name = "y" or name = "Y" or name = "u" or name = "U" or name = "i" or name = "I" or name = "O" or name = "o" or name = "p" or name = "P" or name = "a" or name = "A" or name = "s" or name = "S" or name = "d" or name = "D" or name = "f" or name = "F" or name = "W" or name = "g" or name = "G" or name = "h" or name = "H" or name = "j" or name = "J" or name = "k" or name = "K" or name = "l" or name = "L" or name = "z" or name = "Z" or name = "x" or name = "X" or name = "c" or name = "C" or name = "v" or name = "V" or name = "b" or name = "B" or name = "n" or name = "N" or name = "m" or name = "M" or name = " " then
namex := namex + 30
Font.Draw (name, namex, 500, font1, 14)
fullname := fullname + name
end if
num := num + 1
end loop
cls
Font.Draw ("Player : ", maxx - 375, maxy - 75, font1, 14)
Font.Draw (fullname, maxx - 250, maxy - 75, font1, 92) |
|
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
StarGateSG-1

|
Posted: Mon Jun 06, 2005 11:23 am Post subject: (No subject) |
|
|
After you back space you aren't getting rid of the letter you are just hiding it, I think that is the problem that code is insane though. It need to be fixed up why not just of name = 'anything else' and when people enter there ame they aren't going to use like alt |
|
|
|
|
 |
fehrge
|
Posted: Mon Jun 06, 2005 4:39 pm Post subject: (No subject) |
|
|
The only reason that it deletes the last letter is that you have not added it to the fullname variable. |
|
|
|
|
 |
Cervantes

|
Posted: Mon Jun 06, 2005 4:50 pm Post subject: (No subject) |
|
|
You're making this harder than it needs to be:
Turing: |
View.Set ("offscreenonly,nocursor")
colourback (black)
cls
var CHAR : string (1)
var name := ""
var font1 : int := Font.New ("Impact:30")
Font.Draw ("Enter your name: ", 10, 500, font1, 14)
loop
getch (CHAR )
exit when CHAR = (KEY_ENTER )
if CHAR = (KEY_BACKSPACE ) and length (name ) > 0 then
name := name (1 .. * - 1) %truncates one character off the end of the string
elsif index ("QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm", CHAR ) ~ = 0 then %if CHAR is found in the alphabet
name + = CHAR
end if
cls
Font.Draw ("Player : " + name, 10, maxy - 75, font1, 14)
View.Update
delay (3)
end loop
|
If you don't know about index(), go check the tutorial section for a tut called Index by AsianSensation. There's also a link in the walkthrough. |
|
|
|
|
 |
|
|