
-----------------------------------
ddndd
Mon Dec 21, 2009 7:54 pm

&quot;enter key&quot; problem !!
-----------------------------------
What is it you are trying to achieve?
ok so im trying to make a program that asks the user for their names but it is a little diffrent b/c im going to use it for my tictactoe games

What is the problem you are having?
when ever the user inputs an enter the it will just go to the next line, im trying to stop that, i wanna make it ask for the name again but it is not working for some reason

Describe what you have tried to solve this problem
i tried diffrent things but nothing worked, if u guys have any ideas please tell me !!


Turing:

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")
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
if name1 < "A" or name1 < "a" or name1 > "z" or name1 > "z" then
Draw.Text ("Error, Enter your name again", maxx div 2 - 100, maxy div 2  -50,f2,red)
get name1
end if
/*if name1 > "A" or name1 >"a" or name1 < "z" or name1 < "z" then
exit
end if*/

end loop



Please specify what version of Turing you are using
4.1

-----------------------------------
Zren
Mon Dec 21, 2009 8:21 pm

RE:&quot;enter key&quot; problem !!
-----------------------------------
You kind of got it backwards a little. Right now it asks for your name again and again until you enter Z or A and then asks you again inside the loop. Instead it would be better to write the "Enter your name please" text every loop except the first. And exit the loop when the name is good.

-----------------------------------
Zasalamel
Mon Dec 21, 2009 8:39 pm

RE:&quot;enter key&quot; problem !!
-----------------------------------
I do not know how to fix it easier then this:

var name1 : char
put "Enter your name then press the shift key to continue"
loop
    exit when eof
    get name1
    exit when name1 = KEY_SHIFT
end loop


-----------------------------------
pjohnston
Mon Dec 21, 2009 8:39 pm

Re: &quot;enter key&quot; problem !!
-----------------------------------
To prevent the input cursor from going to the next line, you have to erase the contents of the input box, and set the input cursor's location back to the beginning of the input box. See the following code for an example:


if name1 < "A" or name1 < "a" or name1 > "z" or name1 > "z" then
    Draw.Text ("Error, Enter your name again", maxx div 2 - 100, maxy div 2 - 50, f2, red)
    Text.Locate (16, 4)
    for i : 1 .. 49
        put " " ..
    end for
    Text.Locate (16, 4)
    get name1
end if


Your if statement looks a bit funny by the way. Are you trying to check the string for non-letters? If so, you have to check every letter one at a time. Comparing the whole string won't work.

-----------------------------------
ddndd
Mon Dec 21, 2009 9:25 pm

Re: RE:&quot;enter key&quot; problem !!
-----------------------------------
You kind of got it backwards a little. Right now it asks for your name again and again until you enter Z or A and then asks you again inside the loop. Instead it would be better to write the "Enter your name please" text every loop except the first. And exit the loop when the name is good.
nope it is asking the user for their names the > a and < z is just to check if the user enters letters not other characters for ex numbers, and what do you mean the name is good ?? how im going to know if it is good or not ??

-----------------------------------
ddndd
Mon Dec 21, 2009 9:27 pm

Re: RE:&quot;enter key&quot; problem !!
-----------------------------------
I do not know how to fix it easier then this:

var name1 : char
put "Enter your name then press the shift key to continue"
loop
    exit when eof
    get name1
    exit when name1 = KEY_SHIFT
end loop


ok i did what u wrote and that didnt help much 
the user still can press enter and it will go to the next line 
and can u plz explain what u wrote in more details cuz i dont know how to use the char stuff since im only in grade 10 :P

-----------------------------------
ddndd
Mon Dec 21, 2009 9:29 pm

Re: &quot;enter key&quot; problem !!
-----------------------------------
To prevent the input cursor from going to the next line, you have to erase the contents of the input box, and set the input cursor's location back to the beginning of the input box. See the following code for an example:


if name1 < "A" or name1 < "a" or name1 > "z" or name1 > "z" then
    Draw.Text ("Error, Enter your name again", maxx div 2 - 100, maxy div 2 - 50, f2, red)
    Text.Locate (16, 4)
    for i : 1 .. 49
        put " " ..
    end for
    Text.Locate (16, 4)
    get name1
end if


Your if statement looks a bit funny by the way. Are you trying to check the string for non-letters? If so, you have to check every letter one at a time. Comparing the whole string won't work.

i tired ur code and still didnt really work, the user can still press enter and it will go to the next line, and for the if statments what is funny about it ??, u dont have to check every letter this way is much easier and simpler and does the exact same thing so ...

-----------------------------------
pjohnston
Mon Dec 21, 2009 9:40 pm

Re: &quot;enter key&quot; problem !!
-----------------------------------

i tired ur code and still didnt really work, the user can still press enter and it will go to the next line, and for the if statments what is funny about it ??, u dont have to check every letter this way is much easier and simpler and does the exact same thing so ...


Did you delete your IF block and replace it with the one I suggested? When I tried that in Turing 4.1, it prevented the input cursor from moving to the next line in every case. Also, the comparison you are doing "if name1 < "A"......" will not catch invalid characters unless they are at the beginning of the string. Using comparison operators on strings only tells you which one comes first in alphabetical order.

-----------------------------------
ddndd
Mon Dec 21, 2009 9:52 pm

Re: &quot;enter key&quot; problem !!
-----------------------------------
Did you delete your IF block and replace it with the one I suggested? When I tried that in Turing 4.1, it prevented the input cursor from moving to the next line in every case. Also, the comparison you are doing "if name1 < "A"......" will not catch invalid characters unless they are at the beginning of the string. Using comparison operators on strings only tells you which one comes first in alphabetical order.[/quote]

yes i did this is what the whole thing looks like and it still doesnt work !!

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
if name1 < "A" or name1 < "a" or name1 > "z" or name1 > "z" then
    Draw.Text ("Error, Enter your name again", maxx div 2 - 100, maxy div 2 - 50, f2, red)
    Text.Locate (16, 4)
    for i : 1 .. 49
        put " " ..
    end for
    Text.Locate (16, 4)
    get name1
end if
if name1 > "A" or name1 >"a" or name1 < "z" or name1 < "z" then 
exit
end if
end loop



and for the  a and < z is just to check if the user enters letters not other characters for ex numbers, and what do you mean the name is good ?? how im going to know if it is good or not ??

You program runs like this:
[code]loop
    text locate
    get name
    if name has non alphabetical characters then
        %Needs a text locate here in order to have it appear over the other text
        %To solve your origional problem
        %However this is not the right way to do it
        get name
    end if
end loop[/code]
You are asking for the name twice in the same loop. And at that, your origional text would still show without drawing over it first. Why? Why not just let the loop cycle and ask for the name again?

[code]loop
    text locate
    get name
    exit when name is okay
end loop[/code]

Or more specifically:
[code]loop
    text locate
    get name
    if name has only alphabetical characters then
        exit
    end if
end loop[/code]

Also. You need to look up the function [url=http://compsci.ca/holtsoft/doc/ord.html]ord since it will get a ASCII number value of a character. Then just look at your friend neighbourhood ASCII chart to look at the ranges you want.

-----------------------------------
ddndd
Mon Dec 21, 2009 10:15 pm

Re: RE:&quot;enter key&quot; problem !!
-----------------------------------
You kind of got it backwards a little. Right now it asks for your name again and again until you enter Z or A and then asks you again inside the loop. Instead it would be better to write the "Enter your name please" text every loop except the first. And exit the loop when the name is good.
nope it is asking the user for their names the > a and < z is just to check if the user enters letters not other characters for ex numbers, and what do you mean the name is good ?? how im going to know if it is good or not ??

You program runs like this:


ok so i did what u said fr the first part it is shorter now and kinda simpler, but i dont get the ord thing cuz it is too advanced fr me and ihavnt learned any thing about it in class so im not sure where to go with it i tried reading it and then looked up the ascii chart and i just didnt know what do next :( 
thanks for ur help tho :)

-----------------------------------
Zren
Mon Dec 21, 2009 10:25 pm

RE:&quot;enter key&quot; problem !!
-----------------------------------
Here's a copy of an ascii chart: http://www.jimprice.com/ascii-0-127.gif

put ord("A") %outputs 65

You can see that the ascii value of A is 65 while the lowercase is 97. Z=90 and z=122.

The diference between capitals and lowercase is 32.

You do know how to specify a range of numbers right?

-----------------------------------
ddndd
Mon Dec 21, 2009 11:29 pm

Re: RE:&quot;enter key&quot; problem !!
-----------------------------------
Here's a copy of an ascii chart: http://www.jimprice.com/ascii-0-127.gif

put ord("A") %outputs 65

You can see that the ascii value of A is 65 while the lowercase is 97. Z=90 and z=122.

The diference between capitals and lowercase is 32.

You do know how to specify a range of numbers right?

ummm do u mean using ifs ??
ex if x> >= 3 and x 