Author |
Message |
general_bleh
|
Posted: Tue May 02, 2006 10:38 am Post subject: TXT combat (if and loop) |
|
|
I'm making a game called txt combat and I need help with If and loop commands. I'm trying to let the user make a mistake when they input info. As it stands when they make a mistake the loop just outputs "INVALID INPUT" infinitaly rather than putting "Invalid input" once, then returning to let the person input info. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
neufelni
|
Posted: Tue May 02, 2006 10:50 am Post subject: (No subject) |
|
|
code: |
var info : string
loop
put "Enter info: "
get info
if info = "mistake" then % You can put any mistake here
put "Invalid input"
end if
end loop
|
|
|
|
|
|
|
Delos
|
Posted: Tue May 02, 2006 10:52 am Post subject: (No subject) |
|
|
Hello and welcome.
You've entered into an infinite loop there. It's most likely that your input commands occur outside of the loop, hence any relevant variables do not change.
That or your exit condition is non-existant/never fulfilled. We'll know a lot more when you post your code.
As a general heuristic, post your code (using [code] tags) whenever you ask a question. This will serve to garner you far more help since we'll be able to see a lot more from that than from a description, however detailed it may be. Also, to the best of your abilities, ensure that the code runs (unless of course you're asking about a particular compile-time error). What I mean here is that if you post a snippet of your code with variables all over the place, take a minute and redeclare those variables so that when we place that code in our APIs, it runs.
Read [The Rules] if you haven't yet. This is the usual shpeel I give people, so don't stress too much.
For some reason, your sig. seems terribly familiar...almost as if you've frequented these boards as a different persona before. |
|
|
|
|
|
do_pete
|
Posted: Tue May 02, 2006 12:36 pm Post subject: Re: TXT combat (if and loop) |
|
|
general_bleh wrote: I'm making a game called txt combat and I need help with If and loop commands. I'm trying to let the user make a mistake when they input info. As it stands when they make a mistake the loop just outputs "INVALID INPUT" infinitaly rather than putting "Invalid input" once, then returning to let the person input info.
Do you want the user to input numbers? If so strintok will check if it's a valid integer. |
|
|
|
|
|
general_bleh
|
Posted: Tue May 02, 2006 1:14 pm Post subject: (No subject) |
|
|
No I want them to input their class "Knight" or "knight" is an example |
|
|
|
|
|
neufelni
|
Posted: Tue May 02, 2006 2:12 pm Post subject: (No subject) |
|
|
This here is what you need.
code: |
var Class : string
var valid : boolean := false
loop
put "Enter class: "..
get Class
if Class = "Knight" or Class = "knight" then
valid := true
put "The input is valid"
else
put "Invalid input"
end if
exit when valid
end loop
|
|
|
|
|
|
|
do_pete
|
Posted: Tue May 02, 2006 3:20 pm Post subject: (No subject) |
|
|
Use code: | if Str.Upper (Class) = "KNIGHT" then |
|
|
|
|
|
|
HellblazerX
|
Posted: Tue May 02, 2006 4:35 pm Post subject: (No subject) |
|
|
Well if all you need is simple error checking, then you could just use loops rather than if statements and boolean flags:
code: | var class : string
loop
put "Enter class:"
get class
exit when class = "Knight" or class = "knight"
put "Invalid input"
end loop
//the rest of the code
|
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
TokenHerbz
|
Posted: Tue May 02, 2006 5:47 pm Post subject: (No subject) |
|
|
i want that Str.Upper (text) fcn...
can someone PM me both upper and lower? im going to stick it in turing lib.. |
|
|
|
|
|
Cervantes
|
Posted: Tue May 02, 2006 6:45 pm Post subject: (No subject) |
|
|
Did you even open the link that I gave you in the other thread? I think this is third post like this...
Add it yourself. It's very simple. Looping through each characer, if the ASCII value indicates it is a lower case value, add 32 to it. Else, leave it alone. |
|
|
|
|
|
|