dupa

Author Topic: Scripting Help Needed  (Read 2653 times)

Judge

  • Newbie
  • *
  • Posts: 7
    • View Profile
Scripting Help Needed
« on: June 06, 2008, 12:11:11 pm »
I'm trying to make a plugin work similar to how HAL's joke script works.  My plugin works exactly as the joke script does, but I want to make it better.  I want HAL to ask the joke question, and if the user replies correctly, HAL will congratulate the user.  The opposite will also be true: if the user replies incorrectly, HAL will correct the user.  The basic joke script in the HAL brain is:

'RESPOND: JOKES
'If the user wants Hal to tell a joke, then Hal will tell one

If HalBrain.TopicSearch(UserSentence, "jokeDetect") = "True" Then GetResponse = GetResponse & HalBrain.ChooseSentenceFromFile("jokes")
HalBrain.DebugWatch GetResponse, "Jokes"


Essentially, the user can type anything after HAL asks the joke -- during the DebugWatch time -- and HAL will respond with the answer.

I think my goal should be accomplished by a simple subroutine.  But, whenever I put a subroutine or function into a plugin or even directly into the brain, it comes up with error 1002 "Syntax Error".  I'm using "VBScript in a Nutshell" as a reference and I see no problem with my subroutine syntax.  I'm thinking it's a HAL-specific issue.  This is my basic script:

'RESPOND: JOKES
'If the user wants Hal to tell a joke, then Hal will tell one

If HalBrain.TopicSearch(UserSentence, "jokeDetect") = "True" Then TellJoke

Sub TellJoke
GetResponse = HalBrain.ChooseSentenceFromFile("Jokes")
If InStr(UserSentence, "ROAMING CATHOLIC") > 0 Then GetResponse = "Correct! Well Done!"
If InStr(UserSentence, "ROAMING CATHOLIC") = 0 Then GetResponse = "A roaming Catholic"
End Sub


To simplify the matter, I'm using just 1 joke and the answer is "A roaming Catholic".  The joke is typed in the Hal Brain Editor file Jokes including the <topic> </topic> dividers, so there should be an easy way to access the answer by using a function of HAL without saying the answer in the script.

To summarize: Why do I get a syntax error when I use a subroutine?  How can I access the answer to the joke without stating the answer in my script?  I want the scipt to work for all jokes, I'm trying to simplify it by getting it to work for one joke first.

I'm new to HAL and I've only started trying to program two days ago, so any assistance will be greatly appreciated.

Thanks!
 

Judge

  • Newbie
  • *
  • Posts: 7
    • View Profile
Scripting Help Needed
« Reply #1 on: June 06, 2008, 01:06:33 pm »
I've discovered that putting the subroutine in the Functions section allows it to run without error.  But now it won't allow the GetResponse to work. I've also found that:

'RESPOND: JOKES
'If the user wants Hal to tell a joke, then Hal will tell one

If HalBrain.TopicSearch(UserSentence, "jokeDetect") = "True" Then GetResponse = GetResponse & HalBrain.ChooseSentenceFromFile("jokes")
HalBrain.DebugWatch GetResponse, "Jokes"


Works the same as:

'RESPOND: JOKES
'If the user wants Hal to tell a joke, then Hal will tell one

If HalBrain.TopicSearch(UserSentence, "jokeDetect") = "True" Then GetResponse = GetResponse & HalBrain.ChooseSentenceFromFile("jokes")

What does HalBrain.DebugWatch GetResponse, "Jokes" do?
How can I modify the subroutine to work as I desire?

Thank you
« Last Edit: June 06, 2008, 01:07:24 pm by Judge »
 

ramccoid

  • Sr. Member
  • ****
  • Posts: 321
    • View Profile
    • http://www.visualillustrations.co.uk
Scripting Help Needed
« Reply #2 on: June 07, 2008, 05:26:02 am »
Hi Judge,
Welcome to the forum. HalBrain.DebugWatch checks the information, the joke in your case, to see if it has been used before in the conversation.

If you use a Function to achieve your subroutine then you can carry your variables into it, example:

Functon TellJoke(GetResponse,UserSentence)
GetResponse = HalBrain.ChooseSentenceFromFile("Jokes")
If InStr(UserSentence, "ROAMING CATHOLIC") > 0 Then GetResponse = "Correct! Well Done!"
If InStr(UserSentence, "ROAMING CATHOLIC") = 0 Then GetResponse = "A roaming Catholic"
TellJoke = Getresponse
End Function

and to call up the function use something like:

Getresponse = TellJoke(GetResponse,UserSentence)

Roy.
« Last Edit: June 07, 2008, 05:34:40 am by ramccoid »