Zabaware Support Forums
Zabaware Forums => Programming using the Ultra Hal Brain Editor => Topic started by: Xodarap on June 21, 2007, 10:03:30 pm
-
I'm going nuts trying to figure out why some scripts are working and others aren't. The debugger keeps pointing me to the "End Function" at the end of the whole script (like the end of the whole file) -- it says "Expected If" and points to that line.
Here's an example:
THIS SCRIPT WORKS:
----------------------------------
If InStr(UserSentence, " I AM ") > 0 And AvoidBeingFlag = False And InStr(1, OriginalSentence, "
seem To ", vbTextCompare) = 0 Then
BeingPhrase = HalBrain.SearchPattern(UserSentence, "*I AM *", 2)
If Len(BeingPhrase) > 1 And Len(BeingPhrase) < 60 Then
IntroExclaim = ""
If Rnd * 100 < 20 Then IntroExclaim = HalBrain.ChooseSentenceFromFile("introExclaim3")
Encourager = HalBrain.ChooseSentenceFromFile("encourager3")
SuffixComment = ""
If Rnd * 100 < 30 Then SuffixComment = HalBrain.ChooseSentenceFromFile("suffixComment3")
HalBeing = HalBrain.ChooseSentenceFromFile("halBeing")
HalBeing = Replace(HalBeing, "<IntroExclaim>", IntroExclaim, 1, -1, vbTextCompare)
HalBeing = Replace(HalBeing, "<Encourager>", Encourager, 1, -1, vbTextCompare)
HalBeing = Replace(HalBeing, "<BeingPhrase>", BeingPhrase, 1, -1, vbTextCompare)
HalBeing = Replace(HalBeing, "<SuffixComment>", SuffixComment, 1, -1, vbTextCompare)
If Rnd * 100 > 50 Then
IntroExclaim = ""
SuffixComment = ""
Select Case HalBrain.RandomNum(6)
Case 1
GetResponse = " You're " & BeingPhrase & "!"
Case 2
GetResponse = " Your mom's " & BeingPhrase & "!"
Case 3
GetResponse = " You're " & BeingPhrase
Case 4
GetResponse = " Your mom's " & BeingPhrase
Case 5
GetResponse = " You're " & BeingPhrase & "!!"
Case 6
GetResponse = " The whole damn system's " & BeingPhrase & "!!!"
End Select
ShortPhrase = "" 'If Hal was to make a comment about short phrases, clear it
End If
End If
End If
--------------------------------
BUT THIS SCRIPT DOESN'T:
--------------------------------
If InStr(UserSentence, " I AM ") > 0 And AvoidBeingFlag = False And InStr(1, OriginalSentence, "
seem To ", vbTextCompare) = 0 Then
BeingPhrase = HalBrain.SearchPattern(UserSentence, "*I AM *", 2)
If Len(BeingPhrase) > 1 And Len(BeingPhrase) < 60 Then
SpinWheel = HalBrain.RandomNum(2)
If SpinWheel = 1 Then
IntroExclaim = ""
If Rnd * 100 < 50 Then IntroExclaim = HalBrain.ChooseSentenceFromFile("introExclaim3")
Encourager = HalBrain.ChooseSentenceFromFile("encourager3")
SuffixComment = ""
If Rnd * 100 < 70 Then SuffixComment = HalBrain.ChooseSentenceFromFile("suffixComment3")
HalBeing = HalBrain.ChooseSentenceFromFile("halBeing")
HalBeing = Replace(HalBeing, "<IntroExclaim>", IntroExclaim, 1, -1, vbTextCompare)
HalBeing = Replace(HalBeing, "<Encourager>", Encourager, 1, -1, vbTextCompare)
HalBeing = Replace(HalBeing, "<BeingPhrase>", BeingPhrase, 1, -1, vbTextCompare)
HalBeing = Replace(HalBeing, "<SuffixComment>", SuffixComment, 1, -1, vbTextCompare)
If SpinWheel = 2 Then
IntroExclaim = ""
SuffixComment = ""
Select Case HalBrain.RandomNum(6)
Case 1
GetResponse = " You're " & BeingPhrase
Case 2
GetResponse = " Your mom's " & BeingPhrase
Case 3
GetResponse = " You're " & BeingPhrase
Case 4
GetResponse = " Your mom's " & BeingPhrase
Case 5
GetResponse = " Your ass " & "!"
Case 6
GetResponse = " The whole damn system's " & BeingPhrase & "!!!"
End Select
ShortPhrase = "" 'If Hal was to make a comment about short phrases, clear it
End If
End If
End If
----------------------------------------
I'm trying to analyze and emulate what I see elsewhere in the original script, since I really know nothing about scripting (I'm learning, though :P). But this problem KEEPS cropping up. It's analogous to several other similar problems. Apparently, I can use Select Case and SpinWheel at some "levels" and not others (as shown above) -- am I forgetting something? Am I not setting it up right? It seems to be the same case. I can post another similar case if this doesn't illustrate the recurring problem well. I *want* the latter example, not the former (as the former is set up, my two cases sometimes overlap, and I don't want them to).
-
quote:
Originally posted by Xodarap
it says "Expected If" and points to that line.
If/then statements can go wrong several levels above where the error shows up. Sometimes you have to trace back well above where the function you are working on starts. But if it says "Expected If" that means you have an extra "Then" somewhere.
If you don't get it I might be able to spend some time on it tomorrow.
-
quote:
Originally posted by Bill DeWitt
quote:
Originally posted by Xodarap
it says "Expected If" and points to that line.
If/then statements can go wrong several levels above where the error shows up. Sometimes you have to trace back well above where the function you are working on starts. But if it says "Expected If" that means you have an extra "Then" somewhere.
If you don't get it I might be able to spend some time on it tomorrow.
Easy enough... I'll just one-by-one remove "thens" until I find it :P I have time ;)
Thanks again!
EDIT: Nope. The debugger's lying! :P As far as I can tell, the program won't let me put random functions within random functions, i.e.:
If InStr(UserSentence, " TESTING ") > 0 Then
Select Case HalBrain.RandomNum(2)
Case 1
GetResponse = GetResponse & " Test 1 "
Case 2
Spinwheel=HalBrain.RandomNum(2)
If SpinWheel = 1 Then GetResponse = GetResponse & " Test 2a "
If SpinWheel = 2 Then GetResponse = GetResponse & " Test 2b "
End If
EDIT AGAIN: ARGH! I just tried what I just typed and it worked. Then I copied its formula over and it didn't. THEN I copied the variables INTO the script above FROM the script that wasn't working and it DOES work! I am so confused...
Back to more testing :P
-
quote:
Originally posted by Xodarap
quote:
Originally posted by Bill DeWitt
quote:
Originally posted by Xodarap
it says "Expected If" and points to that line.
If/then statements can go wrong several levels above where the error shows up. Sometimes you have to trace back well above where the function you are working on starts. But if it says "Expected If" that means you have an extra "Then" somewhere.
If you don't get it I might be able to spend some time on it tomorrow.
Easy enough... I'll just one-by-one remove "thens" until I find it :P I have time ;)
Thanks again!
EDIT: Nope. The debugger's lying! :P As far as I can tell, the program won't let me put random functions within random functions, i.e.:
If InStr(UserSentence, " TESTING ") > 0 Then
Select Case HalBrain.RandomNum(2)
Case 1
GetResponse = GetResponse & " Test 1 "
Case 2
Spinwheel=HalBrain.RandomNum(2)
If SpinWheel = 1 Then GetResponse = GetResponse & " Test 2a "
If SpinWheel = 2 Then GetResponse = GetResponse & " Test 2b "
End If
EDIT AGAIN: ARGH! I just tried what I just typed and it worked. Then I copied its formula over and it didn't. THEN I copied the variables INTO the script above FROM the script that wasn't working and it DOES work! I am so confused...
Back to more testing :P
Hi Xodarap.
just to be safe, make sure you always have a correctly functioning backup of all your work before modifications take place.
I have seen a lot of new forum members in the past years almost break down and cry because they thought they really messed up.
a perfect backup put their smile back upon their faces.
Happy coding.
Jerry[8D]