This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Chre903's profile picture

Program to ask Questions, loop/funtion not working?

Started by Chre903, 05 June 2013 - 12:58 PM
Chre903 #1
Posted 05 June 2013 - 02:58 PM
It took me a few hours to get this Programm written and it actualy "work" but i only can ask one time then the Programm ends and i canot bring it to "loop"

Script:
http://pastebin.com/fQCMjqFV

I deleted the answeres in this script so it is better to read.

i found the funtion key() on the CC Wiki. it is exactly what i want, but i dont understand how it works :P/>/>
When i have my fonction ask() inside of function key(), the program stops with the message ":22:attempt so call string".
But without that, after a key press, it cleares the first printed part but didnt clears the "answer" i got and then it stuck and i have to Terminate it.

i can't figure out, how to propper loop and can ask multiple questions without restarting the programm.

also, is there a better way to print the answers instead of alot of elseif ? i cant think of a way to make it a funtion. (the same for the printed questions on the Screen).
Lyqyd #2
Posted 05 June 2013 - 02:59 PM
Split into new topic.
LBPHacker #3
Posted 05 June 2013 - 04:04 PM
+1 for putting it up to pastebin, despite the fact that you clearly are new here. That proves to be difficult for some other members.

The problem is that on line 7, function "ask" replaces itself with the string the user entered. The next call to ask will try to call that string.
Solution: Rename the function "ask", but not with Replace in an editor, because that would rename the string as well.

Have done it for you (398eDqyT)

EDIT: By the way, line 64: "What did you say?" instead of "What did you said?".
Chre903 #4
Posted 05 June 2013 - 06:52 PM
+1 for putting it up to pastebin, despite the fact that you clearly are new here. That proves to be difficult for some other members.

The problem is that on line 7, function "ask" replaces itself with the string the user entered. The next call to ask will try to call that string.
Solution: Rename the function "ask", but not with Replace in an editor, because that would rename the string as well.

Have done it for you (398eDqyT)

EDIT: By the way, line 64: "What did you say?" instead of "What did you said?".

Thank you very much, you helped me a lot!

I improved the Script a bit too, the printed Question are now a function so i can recall them, cleared the screen more often so it is better to read and added a little "Press any Key to Continue" text to it.

http://pastebin.com/RrCMbs8p

I hope this program helps other people too, i googled for something like it for a while :P/>