User can crash my program by entering a letters instead of numbers
Author |
Message |
Nai
|
Posted: Fri Jun 12, 2009 6:11 pm Post subject: User can crash my program by entering a letters instead of numbers |
|
|
What is it you are trying to achieve?
I am in the process of making an rpg game for my Grade 10 Info. Tech. class. In my game, there is a bank, which the user may enter and withdraw/deposit money. I am trying to eliminate any possiblility that the user will be able to crash the program by entering a letter or other key instead of a number when they are trying to withdraw/deposit their money.
What is the problem you are having?
When the player of my game enters the bank and tries to deposit or withdraw money, they are able to crash my program by inputting a letter or any other non-numeric key.
Describe what you have tried to solve this problem
I have already solved the problem of the keyboard queue having left-over input from the player's movement into the store (the player uses the arrow keys to move), so that when I use my get command to allow the user to input the amount of money that they wish to withdraw/deposit, their Up Arrow presses are not displayed. This was done using a conditional loop, an "exit when not hasch", and a getch command.
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Here is my game file. The section for the player's activities in the bank begin at line 1419.
Please specify what version of Turing you are using
I am using version 4.1.1 of Turing.
Thank you for any help you can provide.
Description: |
My work - in progress video game. Go left one screen and up one screen to find your way to the bank. |
|
Download |
Filename: |
game prototype.t |
Filesize: |
70.57 KB |
Downloaded: |
79 Time(s) |
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
BigBear
|
|
|
|
|
Kharybdis
|
Posted: Fri Jun 12, 2009 10:38 pm Post subject: Re: User can crash my program by entering a letters instead of numbers |
|
|
what he is saying is that for any basic error trapping in your program, you have to make everything a string, even if what you're asking is actually a number.
example of how this would be implemented:
Turing: | %For integers...
var banknum : string
loop
put "Please enter your bank account number:"
get banknum
exit when strintok (banknum )
put "That is not valid input!"
end loop
put strint (banknum ) / 2, " < ---- your number divided by 2"
%for reals...
loop
put "Please enter the percentage with decimal places:"
get banknum
exit when strrealok (banknum )
put "that is not a valid input!"
end loop
put strreal (banknum ) / 2, " <---- your number divided by 2" |
I would look into these commands for error trapping:
Turing: | strintok %checks if its valid to convert to integer
strreal %checks if its valid to convert to a real number
intstr %converts the integer to a string
realstr %converts the real number to a string
strrealok%checks if its ok to convert from string to real
|
|
|
|
|
|
|
Nai
|
Posted: Sat Jun 13, 2009 12:18 am Post subject: Re: User can crash my program by entering a letters instead of numbers |
|
|
Thanks, this part of program is working almost perfectly now. Now, onto wrestling with some music processes...
|
|
|
|
|
|
BigBear
|
Posted: Sat Jun 13, 2009 9:24 am Post subject: RE:User can crash my program by entering a letters instead of numbers |
|
|
If your teacher has the latest version of turing I would suggest using Music.PlayFileLoop
|
|
|
|
|
|
Nai
|
Posted: Sat Jun 13, 2009 6:23 pm Post subject: RE:User can crash my program by entering a letters instead of numbers |
|
|
Thanks, until now I had just been using Music.PlayFile, which meant my background music would only play once. This will help a lot.
|
|
|
|
|
|
Nai
|
Posted: Tue Jun 16, 2009 7:16 pm Post subject: RE:User can crash my program by entering a letters instead of numbers |
|
|
I just submitted the final copy of this game in Turing Submissions if anyone would like to take a look at it.
|
|
|
|
|
|
|
|