Posted: Mon Dec 21, 2009 11:56 pm Post subject: Re: "enter key" problem !!
To compare the individual letters of a string, you use the index of the character you want. So if you want to check the first letter:
code:
var name : string
get name
put name(1)
Sponsor Sponsor
Zren
Posted: Tue Dec 22, 2009 12:02 am Post subject: RE:"enter key" problem !!
Okay. But you want it to ask for the name again if there is numbers right? and if it's only letters then you exit the loop and finish the program right?
ddndd
Posted: Tue Dec 22, 2009 12:16 am Post subject: Re: RE:"enter key" problem !!
Zren @ Tue Dec 22, 2009 12:02 am wrote:
Okay. But you want it to ask for the name again if there is numbers right? and if it's only letters then you exit the loop and finish the program right?
that is exactly what i want and i kinda did that but now im trying to make turing understand that when the user hits enter it shouldnt go to the next line it should just stay there and ask for the name again
ddndd
Posted: Tue Dec 22, 2009 12:21 am Post subject: Re: "enter key" problem !!
TheGuardian001 @ Mon Dec 21, 2009 11:56 pm wrote:
To compare the individual letters of a string, you use the index of the character you want. So if you want to check the first letter:
code:
var name : string
get name
put name(1)
ok i didnt know that but that is not what im trying to do tho im trying to make turing not go to the next line when the user hits enter
thnx tho
TheGuardian001
Posted: Tue Dec 22, 2009 12:30 am Post subject: Re: "enter key" problem !!
So, wait, if I understand this right, you want it to ask for their name twice on the same line?
If that's the case, I'd like you to go back to the start of the thread when the people told you to use locate(row,column).
ddndd
Posted: Tue Dec 22, 2009 12:46 am Post subject: Re: "enter key" problem !!
TheGuardian001 @ Tue Dec 22, 2009 12:30 am wrote:
So, wait, if I understand this right, you want it to ask for their name twice on the same line?
If that's the case, I'd like you to go back to the start of the thread when the people told you to use locate(row,column).
ok if u run this
setscreen ("graphics:440;500,position:400;100,title: - = T I C T A C T O E =,nobuttonbar")
var name1 :string
var f1 : int := Font.New ("arial:20")
var f2 : int := Font.New ("arial:10")
var font : int := Font.New ("Goudy Stout:30")
const l: int := 16
const o: int := 4
drawfillbox(0,0,maxx,maxy,black)
loop
delay (10)
cls
drawfillbox(0,0,maxx,maxy,black)
drawfillbox (maxx div 2+200, maxy div 2 +15, maxx div 2 - 200, maxy div 2 - 15, white)
Draw.Text ("TicTacToe", maxx div 2 - 210, maxy -50 ,font,red)
Draw.Text ("Enter your name please",maxx div 2 - 150,maxy div 2 + 50,f1,red)
Text.Locate (16,4)
get name1
Text.Locate (l,o)
if name1 > "A" and name1 < "z" or name1 >"a" and name1 < "z" then
exit
end if
end loop
this is what is going to happen when the user hits enter instead of writing their name
see that white thing that is what happens when they press enter, i dont want turing to do that i want to just not skip the line and to just keep flashing inside of the white box
do u know what i mean know ??
TheGuardian001
Posted: Tue Dec 22, 2009 3:43 pm Post subject: Re: "enter key" problem !!
Yes, you mean you want it to keep it on the same line.
which means you want locate(row,column)
For example:
code:
var name : string
get name
locate (1, length(name)+2)
get name
locate will move the text cursor to the selected row and column.
Zren
Posted: Tue Dec 22, 2009 4:58 pm Post subject: RE:"enter key" problem !!
Ooooooooh. What you want can't be done using get command. However it won't add the return value into the variable dude. So don't worry.
If you want to make it so you can only write Alphabetical characters and ignore numbers and return statements. You'll have to imitate the get command with getch(). I'll explain more so if your interested.
Also. Your if statement to check each character for numbers still doesn't work as intended. Your comparing a string to a character. You need to check each character in the string.
Sponsor Sponsor
ddndd
Posted: Tue Dec 22, 2009 6:08 pm Post subject: Re: "enter key" problem !!
TheGuardian001 @ Tue Dec 22, 2009 3:43 pm wrote:
Yes, you mean you want it to keep it on the same line.
which means you want locate(row,column)
For example:
code:
var name : string
get name
locate (1, length(name)+2)
get name
locate will move the text cursor to the selected row and column.
nope cuz when i hit enter it will just go to the next line and that is not what i want it to do !!
ddndd
Posted: Tue Dec 22, 2009 6:11 pm Post subject: Re: RE:"enter key" problem !!
Zren @ Tue Dec 22, 2009 4:58 pm wrote:
Ooooooooh. What you want can't be done using get command. However it won't add the return value into the variable dude. So don't worry.
If you want to make it so you can only write Alphabetical characters and ignore numbers and return statements. You'll have to imitate the get command with getch(). I'll explain more so if your interested.
Also. Your if statement to check each character for numbers still doesn't work as intended. Your comparing a string to a character. You need to check each character in the string.
yeeeees :p
ok im interested i know some stuff about getch but i think if i used it the user will be able to just enter one character and that is it do you know what i mean??
fr ex:
var name : string (1)
getch (name)
get name
and if i put 5 instead of the 1 then it will just give me an error !!
Zren
Posted: Tue Dec 22, 2009 6:26 pm Post subject: RE:"enter key" problem !!
code:
View.Set ("offscreenonly")
var ch : string (1)
var str : string := ""
loop
if hasch () then
getch (ch)
str += ch
end if
cls
put str
View.Update
delay (10)
end loop
This basically imitates get. It allows you to understand how you would gather each character one at a time and add it to a string. Lucky for us Backspace still works. And with a little modding you can check the character press to check if it's the Enter key or a number. Just don't forget to include Backspace if you limit to only letters.
Try getting to limit the numbers in a separate program first, then bring it over to your main program. It's a lot easier.
pjohnston
Posted: Tue Dec 22, 2009 9:54 pm Post subject: Re: "enter key" problem !!
ddndd @ Mon Dec 21, 2009 11:53 pm wrote:
but why do i need to do that i dont want the user to be forced to put only letters u kno maybe someone wants to use m332 or something like that as their name i just want turing to know when they press the key enter it should just ask for the name again and not go to the next line
Yeah... I just got that. I wasn't sure exactly what the input checker was supposed to do. Sorry for the confusion.