Hi everyone, i have finally got around to making my chat program.
http://ceme.tech/DL2849
In my code, if you enter something it just ends the program; does anyone see why?

Code:
ClrHome
Disp "Chatbot"
Disp "Version 0.1
Pause
Disp "Made by: Liam P"
Pause
ClrHome
Input "What's your name?",Str1
ClrHome
Menu("TI-AI Chatbot","Chat",A,"Quit",B)

Lbl B
Disp "Goodbye"
Disp Str1
Disp ":D"
Pause
ClrHome
Stop

Lbl A
Input "Input text: ",Str2
ClrHome
If inString(Str2,"HELLO")
Then
Disp "Greetings"Str2 

If inString(Str2,"HI")
Then
Disp "Sup!"
Goto A

If inString(Str2,"JOKE")
Then
Disp "I eat bytes!"
Goto A

If inString(Str2,"BYE")
Then
Then
Goto B

If inString(Str2,"HOW ARE YOU")
Disp "Good, you?"
Goto A
 
If inString(Str2,"BAD")
Then
Disp "I'm sorry"
Goto A

If inString(Str2,"GOOD")
Then
Disp "That's good!"
Goto A
No ends or elses to ur ifs.
So at the end of a block,
Code:


If inString(Str2,"JOKE")
Then
Disp "I eat bytes!"
Goto A
Else

then the next if statement? and is there a supposed to be a space between the blocks?
Edit: i think i got it fully working except if i input BAD or GOOD (in short, anything after the HOW ARE YOU block) then there is an error. here is the code:

Code:
ClrHome
Disp "Chatbot"
Disp "Version 0.1
Pause
Disp "Made by: Liam P"
Pause
ClrHome
Input "What's your name?",Str1
ClrHome
Menu("TI-AI Chatbot","Chat",A,"Quit",B)

Lbl B
Disp "Goodbye"
Disp Str1
Disp ":D"
Pause
ClrHome
Stop

Lbl A
Input "Input text: ",Str2
ClrHome
If inString(Str2,"HELLO")
Then
Disp "Greetings"
Pause
Goto A
Else

If inString(Str2,"HI")
Then
Disp "Sup!"
Pause
Goto A
Else

If inString(Str2,"JOKE")
Then
Disp "I eat bytes!"
Pause
Goto A
Else

If inString(Str2,"BYE")
Then
Goto B
Else

If inString(Str2,"HOW ARE YOU")
Then
Disp "Good, you?"
Pause
Goto A
Else
 
If inString(Str2,"BAD")
Then
Disp "I'm sorry"
Pause
Goto A
Else

If inString(Str2,"GOOD")
Then
Disp "That's good!"
Goto A
You are missing end statements, if else works like
Code:

If inString(Str2,"JOKE")
Then
Disp "I eat bytes!"
Goto A
Else
Statement
End
I added an End block at the end of everything, but it still does not work.
The End commands need to go in the correct locations, not at the very end. When you do an If followed by a Then, you're telling the calculator to execute a block of commands if that If expression evaluates to true. It needs to know where the end of that block is in case the expression is false, because it will skip down to that point and continue executing from there. So you need to look at your code and think about where execution should skip to if the If:Then is false. Put an End there. Do this for every If:Then you have in your code.
So i tried that but it still does not work â˜šī¸

Code:
ClrHome
Disp "Chatbot"
Disp "Version 0.1
Pause
Disp "Made by: Liam P"
Pause
ClrHome
Input "What's your name?",Str1
ClrHome
Menu("TI-AI Chatbot","Chat",A,"Quit",B)

Lbl B
Disp "Goodbye"
Disp Str1
Disp ":D"
Pause
ClrHome
Stop

Lbl A
Input "Input text: ",Str2
ClrHome

If inString(Str2,"HELLO")
Then
Disp "Greetings"
Pause
Goto A
End

If inString(Str2,"HI")
Then
Disp "Sup!"
Pause
Goto A
End

If inString(Str2,"JOKE")
Then
Disp "I eat bytes!"
Pause
Goto A
End

If inString(Str2,"BYE")
Then
Goto B
End

If inString(Str2,"HOW ARE YOU")
Then
Disp "Good, you?"
Pause
Goto A
End
 
If inString(Str2,"BAD")
Then
Disp "Im sorry"
Pause
Goto A
End

If inString(Str2,"GOOD")
Then
Disp "Thats good!"
Pause
Goto A
End
Oof that program is entirely memory leaks. Never use Goto to jump out of an if-then statement. It's only OK to use goto in a single line if statement.
http://tibasicdev.wikidot.com/memory-leaks

Exactly what error are you getting and what line?
So, it is a syntax error on the line indicated.


Code:
If inString(Str2,"HOW ARE YOU")
Then
Disp "Good, you?"
Pause
Goto A
End
#error appears here
If inString(Str2,"BAD")
Then
Disp "Im sorry"
Pause
Goto A
End

If inString(Str2,"GOOD")
Then
Disp "Thats good!"
Pause
Goto A
End

The entire code works perfect except that last bit.
Edit: I have been testing my code on WabbitEMU (and on my calculator) and I got those errors but I just tested on Justified/SourceCoder and it worked perfect. 😁
Any idea why it works on Justified and not Wabbit or my calculator?
Check if the the commands and the string got tokenized or if the words are individual characters. Also, check for any trailing whitespace. I think your issue is just sourcecoder weirdness.

Edit: Try clearing then re-typing that line on your calculator and see if it runs. If so, you know the code is valid.
I testing it on my CE and every Pause command was individual characters. This program is now working 🙂 Thank you! I just need to make a bigger word database now. Does anyone want to help with that?
Before I made CAMLbot, my first project was a chatbot just like this one 🙂. My advice, unless you're planning on making a massive program with the entire dictionary, is to use nice, broad words as keywords. I prefer to get a general response out of most things instead of a few specific responses and an "I don't know that word" for everything else. Priority is really important here; if the input is "Hi, I want a joke" and "HI" is before "JOKE" in your dictionary, it will just respond "Sup!"

Also, I think chatbots feel less rigid when you program a few possible responses for every input and then randomly cycling through them (like "HI" linking to either "Hello there!" or "Hi! How are you?" or "Hey, what's up?"). Plus, I'd use a few keywords that actually do things, like having "GAME" take you to a little number guessing game, "CALC" doing a calculation, etc.

Exclamation And, of course, watch out for memory leaks! Labels & Gotos are a slippery slope. Exclamation
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement