Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 "enter key" problem !!
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
ddndd




PostPosted: Mon Dec 21, 2009 7:54 pm   Post subject: "enter key" 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
Sponsor
Sponsor
Sponsor
sponsor
Zren




PostPosted: Mon Dec 21, 2009 8:21 pm   Post subject: RE:"enter key" 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




PostPosted: Mon Dec 21, 2009 8:39 pm   Post subject: RE:"enter key" problem !!

I do not know how to fix it easier then this:
Turing:

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




PostPosted: Mon Dec 21, 2009 8:39 pm   Post subject: Re: "enter key" 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:


Turing:
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




PostPosted: Mon Dec 21, 2009 9:25 pm   Post subject: Re: RE:"enter key" problem !!

Zren @ Mon Dec 21, 2009 8:21 pm wrote:
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




PostPosted: Mon Dec 21, 2009 9:27 pm   Post subject: Re: RE:"enter key" problem !!

Zasalamel @ Mon Dec 21, 2009 8:39 pm wrote:
I do not know how to fix it easier then this:
Turing:

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 Razz
ddndd




PostPosted: Mon Dec 21, 2009 9:29 pm   Post subject: Re: "enter key" problem !!

pjohnston @ Mon Dec 21, 2009 8:39 pm wrote:
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:


Turing:
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




PostPosted: Mon Dec 21, 2009 9:40 pm   Post subject: Re: "enter key" problem !!

ddndd @ Mon Dec 21, 2009 9:29 pm wrote:

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.
Sponsor
Sponsor
Sponsor
sponsor
ddndd




PostPosted: Mon Dec 21, 2009 9:52 pm   Post subject: Re: "enter key" 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 thing i know that but i used this so the user cant enter 123131 as their name but they can still do this u2323 which might be their nickname or something
Zren




PostPosted: Mon Dec 21, 2009 9:57 pm   Post subject: Re: RE:"enter key" problem !!

ddndd @ Mon Dec 21, 2009 9:25 pm wrote:
Zren @ Mon Dec 21, 2009 8:21 pm wrote:
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:
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

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


Or more specifically:
code:
loop
    text locate
    get name
    if name has only alphabetical characters then
        exit
    end if
end loop


Also. You need to look up the function 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




PostPosted: Mon Dec 21, 2009 10:15 pm   Post subject: Re: RE:"enter key" problem !!

Zren @ Mon Dec 21, 2009 9:57 pm wrote:
ddndd @ Mon Dec 21, 2009 9:25 pm wrote:
Zren @ Mon Dec 21, 2009 8:21 pm wrote:
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:
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

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


Or more specifically:
code:
loop
    text locate
    get name
    if name has only alphabetical characters then
        exit
    end if
end loop


Also. You need to look up the function 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.


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 Sad
thanks for ur help tho Smile
Zren




PostPosted: Mon Dec 21, 2009 10:25 pm   Post subject: RE:"enter key" 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




PostPosted: Mon Dec 21, 2009 11:29 pm   Post subject: Re: RE:"enter key" problem !!

Zren @ Mon Dec 21, 2009 10:25 pm wrote:
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 <=10 then ...
or something else ??
and btw i couldnt find the enter key on that chart
Zren




PostPosted: Mon Dec 21, 2009 11:42 pm   Post subject: RE:"enter key" problem !!

Why would you need the ASCII value of the enter key? Your checking to make sure each character in the string name is okay.
get name
Won't include the return at the end.

And yes. We can specify a range of numbers using two boolean statements.

if 10 > a and a < 15 then % 11, 12, 13, 14
if 10 >= a and a < 15 then % 10, 11, 12, 13, 14
if 10 > a and a <= 15 then % 11, 12, 13, 14, 15
if 10 > a and a < 15 then % 10, 11, 12, 13, 14, 15
ddndd




PostPosted: Mon Dec 21, 2009 11:53 pm   Post subject: Re: "enter key" problem !!

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
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 27 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: