
-----------------------------------
general_bleh
Tue May 02, 2006 10:38 am

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.

-----------------------------------
neufelni
Tue May 02, 2006 10:50 am


-----------------------------------

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
Tue May 02, 2006 10:52 am


-----------------------------------
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
Tue May 02, 2006 12:36 pm

Re: 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.
Do you want the user to input numbers? If so strintok will check if it's a valid integer.

-----------------------------------
general_bleh
Tue May 02, 2006 1:14 pm


-----------------------------------
No I want them to input their class "Knight" or "knight" is an example

-----------------------------------
neufelni
Tue May 02, 2006 2:12 pm


-----------------------------------
This here is what you need.


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
Tue May 02, 2006 3:20 pm


-----------------------------------
Use if Str.Upper (Class) = "KNIGHT" then

-----------------------------------
HellblazerX
Tue May 02, 2006 4:35 pm


-----------------------------------
Well if all you need is simple error checking, then you could just use loops rather than if statements and boolean flags:

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


-----------------------------------
TokenHerbz
Tue May 02, 2006 5:47 pm


-----------------------------------
i want that Str.Upper (text) fcn...

can someone PM me both upper and lower?  im going to stick it in turing lib..

-----------------------------------
Cervantes
Tue May 02, 2006 6:45 pm


-----------------------------------
Did you even open the link that I gave you in the [url=http://www.compsci.ca/v2/viewtopic.php?p=115863]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.
