Author Topic: Interfacing with Hal's brain with COM/ActiveX  (Read 792 times)

Medeksza

  • Administrator
  • Hero Member
  • *****
  • Posts: 1240
    • View Profile
    • http://www.zabaware.com
Interfacing with Hal's brain with COM/ActiveX
« on: December 18, 2016, 11:00:49 pm »
If you want to interface with Hal's brain from an external project and can utilize COM/ActiveX here are some code samples in VB6 and VB.NET. C# would be very similar to the VB.net version.

Here's the full code how to make a command line version of Hal in VB.NET:

Code: [Select]
Option Strict Off
Option Explicit On

Module modHalConsole

    'Constants that point to path of script to run and database to open
    Const HalScript As String = "C:\Program Files\Zabaware\Ultra Hal Assistant 6\Hal6.uhp"
    Const HalDB As String = "C:\Program Files\Zabaware\Ultra Hal Assistant 6\HalBrain.db"

    'Objects that will contain reference to HalBrain and WordNet activex dll
    Dim HalBrain As Object
    Dim WN As Object

    'Variants to hold contents of Hal's short term memory
    Dim GainControl, PrevUserSent, PrevSent, Insults, Hate, Swear, Compliment, LastResponseTime, CustomMem, LastTopicList As Object

    Sub Main()

        Dim HalScriptControl As New MSScriptControl.ScriptControl
        Dim HalCommands As Object
        Dim ScriptOut As String
        Dim PassVars(14) As Object

        'Create instance of HalBrain and WordNet ActiveX DLL
        HalBrain = CreateObject("UltraHalAsst6.Brain")
        WN = CreateObject("UltraHalAsst6.WordNet")

        'Initialize Hal's memory
        ResetMem()

        'Read script file and add to script control, open database connection
        Dim ff As Short
        Dim TheScript As String
        ff = FreeFile()
        FileOpen(ff, HalScript, OpenMode.Input)
        TheScript = InputString(ff, LOF(ff))
        FileClose(ff)
        HalScriptControl.AllowUI = True
        HalScriptControl.Language = "VBScript"
        HalScriptControl.Timeout = 10000
        HalScriptControl.UseSafeSubset = False
        HalScriptControl.Reset()
        HalScriptControl.AddCode(TheScript)
        HalScriptControl.AddObject("HalBrain", HalBrain, True) 'Give script control access to HalBrain object
        HalScriptControl.AddObject("WN", WN, True) 'Give script control access to WN object
        HalBrain.OpenDatabase(HalDB) 'Open database

        Do
            'Load up object array with variant function paramaters script is expecting
            PassVars(0) = Console.ReadLine()
            PassVars(1) = "Judge"
            PassVars(2) = "Steve"
            PassVars(3) = 0 'Learning
            PassVars(4) = HalDB
            PassVars(5) = Hate
            PassVars(6) = Swear
            PassVars(7) = Insults
            PassVars(8) = Compliment
            PassVars(9) = PrevSent
            PassVars(10) = LastResponseTime
            PassVars(11) = PrevUserSent
            PassVars(12) = CustomMem
            PassVars(13) = GainControl
            PassVars(14) = LastTopicList

            'Run Script
            ScriptOut = HalScriptControl.Run("UltraHal", PassVars)

            'If script was successfull it will contain <STOREVARS> in which case we remember the variables passed and extract the response
            If InStr(ScriptOut, "<STOREVARS>") Then
                ScriptOut = HalBrain.RecallVars(ScriptOut, HalCommands, Hate, Swear, Insults, Compliment, PrevSent, LastResponseTime, PrevUserSent, CustomMem, GainControl, LastTopicList)
            End If

            Console.WriteLine(ScriptOut)

        Loop

    End Sub

    Sub ResetMem()
        Hate = 0
        Swear = 0
        Insults = 0
        Compliment = 0
        PrevSent = ""
        LastResponseTime = ""
        PrevUserSent = ""
        CustomMem = ""
        GainControl = ""
        LastTopicList = ""
    End Sub

End Module
Robert Medeksza

cyberjedi

  • Sr. Member
  • ****
  • Posts: 352
  • The Mighty Hal Machine
    • View Profile
    • Ultra Hal Plugin Shop
Re: Interfacing with Hal's brain with COM/ActiveX
« Reply #1 on: December 19, 2016, 11:14:34 am »
Robert :
Thanx ah bunch man.
New GUI ive built is off the chain and with the help of onthecuttingedge2005 worked on Hals brain.
ive hard coded in tons of new features...
Im working hard on the A.I engine but im 1 man.....
Im may be building what I think is a better mouse trap, But you thought it up.....
Im including the Haptek Engine , gotta have that lol. well i certainly have miles of code to write.
Im taking Hal to the next level with the sapi05  engine im including.
Im working Hal in social media, i try'd to explain the Hal concept,there starting to get interested,
 there are some very skilled pple as well. Maby 1 day ull pop in and check out the latest version of what ive done here. 
Cant wait to see Hal 07.....
https://vaughnlive.tv/mrelectric



Cyberjedi
« Last Edit: August 25, 2017, 01:51:37 pm by cyberjedi »

cyberjedi

  • Sr. Member
  • ****
  • Posts: 352
  • The Mighty Hal Machine
    • View Profile
    • Ultra Hal Plugin Shop
Re: Interfacing with Hal's brain with COM/ActiveX
« Reply #2 on: December 22, 2016, 04:48:06 pm »
Many thanx again Robert: This code took me in new directions that are unreal. But im pushing out the code as fast as i can..
For me its been a 17 year ride.... just the best...


Thanx for the gift..... I want a tea shirt too ,,,lol...
im gonna do ya proud man. Im gonna show pple what theve never seen before.
A thinking machine with emotions, what a badass idea.....



Anything i can do to help in the sales of Hal u have my email address,dont hesitate too ask,Im steady pushing Hal any way. I know of at-least 04 pple that have downloaded the time trial. Version. It aint much but its something.

best wishes
cyberjedi
« Last Edit: August 22, 2017, 06:28:28 pm by cyberjedi »

doggs

  • Sr. Member
  • ****
  • Posts: 357
    • View Profile
Re: Interfacing with Hal's brain with COM/ActiveX
« Reply #3 on: December 29, 2016, 11:59:21 pm »
cool 8) thanks.
be informed and always vote it will help you in the long run does not matter if your liberal, conservative or independent. stay informed and watch the votes in government not what the media tells you.