----------------------------------- Computer Tue Jun 24, 2003 7:21 am make a list to call in an if condition ----------------------------------- I want to start making an interactive program that a user can take to. so can i do something like this so when a user greets the computer it can say many different things. so create a group of things a user could say. list := hello, hi, bonjour, yo, sup ...etc if user = list then put " Hi there" else put " your not very polite didn't even say hi" end if i know this isn't real code but its just to illustrate my question. How would I go about actually coding this? ----------------------------------- Mazer Tue Jun 24, 2003 9:09 am ----------------------------------- i could see 1 or 2 ways of doing what your asking. the first would be to use an array. var list : array 1 .. 5 of string := init ("hello", "hi", "bonjour", "yo", "sup") and then, once you get the input from the user check each for i : 1 .. 5 if user = list (i) then % stuff happens here end if end for but that wouldn't be so great. the other idea would be using index. it's a function that results the starting position of one string inside another string (results 0 if it wasn't found). var list : string := "hello hi bonjour yo sup" then get the user input and check to see if what they typed was inside the list: if index (list, user) > 0 then % they inputed one of the greetings put "hello to you" end if of course, it would matter that the user spells the word correctly and it has to be case sensitive (ie, "hello", not "Hello") ----------------------------------- Andy Tue Jun 24, 2003 10:30 am ----------------------------------- lol mazer, i dun think he understands arrays yet, hey computer go to the tutorial section and click on the arrays tutorial, by me, not by tony, actually here's the link http://www.compsci.ca/bbs/viewtopic.php?t=1117 but first, learn about strings first ----------------------------------- Computer Tue Jun 24, 2003 4:48 pm ----------------------------------- I do know about strings, but hasch is a bit confusing. But you're right i dont know anything about arrays. ----------------------------------- naoki Tue Jun 24, 2003 10:36 pm ----------------------------------- hasch checks if any keyboard button has been pressed i think it's better than just getch because the program can keep running instead of waiting for input ----------------------------------- Blade Wed Jun 25, 2003 11:06 am ----------------------------------- Input.KeyDown rules them both... instead of using the array algorythim, use the index, more efficient ----------------------------------- Andy Wed Jun 25, 2003 11:33 am ----------------------------------- i'd have to disagree with you blade, it all depends on the situation. if ur making a game that runs very fast, Input.KeyDown does work much better, but if ur program runs very slowly hasch and getch will work better since you'd want to use the buffer then again of course, you could enhance both in ur program ----------------------------------- PaddyLong Wed Jun 25, 2003 12:26 pm ----------------------------------- hasch is great if you even just want to wait for them to push any button and situations like that ----------------------------------- Andy Wed Jun 25, 2003 1:44 pm ----------------------------------- ya Input.KeyDown takes too long to set up when campared to hasch and getch of course