dupa

Author Topic: How to add a timer in Hal script?  (Read 3642 times)

knight2000

  • Full Member
  • ***
  • Posts: 155
    • View Profile
How to add a timer in Hal script?
« on: March 04, 2019, 10:15:04 am »
I need to add a countdown timer in a Hal plugin im creating, but it doesn't seem that WScript.Sleep is available within Hals script. Not sure why but i get an object error. Has anyone tried working with timers in Hal's script before? I want something like the following:

WScript.Sleep 5000
HalCommands = HalCommands & "<MICOFF>"

So after 5 seconds turn off Hal's mic.


Art

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3848
    • View Profile
Re: How to add a timer in Hal script?
« Reply #1 on: March 04, 2019, 03:31:34 pm »
Just a suggestion,

A lot of plugins use the IF / THEN statements based on the following:

86,400 = Number of minutes / day
86,400 / 60 will give you minutes = 1440

Here is a clip from one of the many Loneliness Plugins for Hal. Hope this helps.
----------------------------------------
 Rem PLUGIN: MINUTE_TIMER
'------------------
' Declare variables
'------------------
    Dim randomPatience, loChance, loTemper, loMinuteFactor, temperThresh1, temperThresh2, temperThresh3
    If HalBrain.TopicSearch("PATIENCE", "lonelyParameter") = "99" Then
'
'--------------------
' Set minutes to a random integer from 4 to 30
'--------------------
        Randomize
        loPatience = Int(32 * Rnd + 3)
        randomPatience=True
    Else
'
'--------------------
' Set minute value (loPatience) to the parameter chosen in the PATIENCE menu
'--------------------
        loPatience = CDbl(HalBrain.VBVal(HalBrain.TopicSearch("PATIENCE", "lonelyParameter")))
   if loPatience = 0 Then loPatience = 32
    End If
'
'--------------------
' Set frustration value (loFrustration) to the parameter chosen in the FRUSTRATION menu
'--------------------
    loFrustration = CInt(HalBrain.VBVal(HalBrain.TopicSearch("FRUSTRATION", "LonelyParameter")))
    if loFrustration = 0 then loFrustration = 15
'
'--------------------
' Skip the rest of this plugin if the user has spoken
'--------------------
        If LastIdleResponse <> "" Then
'
'------------------
' Otherwise, convert PATIENCE to minutes factor (loMinuteFactor)
'------------------
        loMinuteFactor = loPatience / 1440
'
'--------------------
' If the pause exceeds the minute factor, create a chance for Hal to speak once per minute
'--------------------
        If Now - LastIdleResponse > loMinuteFactor Then
        If InStr(1, IdlePrevUser, "BE RIGHT BACK", 1) > 0  Or InStr(1, IdlePrevUser, "BRB", 1) > 0  Or InStr(1, IdlePrevUser, "BE QUIET", 1) > 0  Or InStr(1, IdlePrevUser, "SHUT UP", 1) > 0  Then Exit Sub
'
In the world of AI it's the thought that counts!

- Art -

knight2000

  • Full Member
  • ***
  • Posts: 155
    • View Profile
Re: How to add a timer in Hal script?
« Reply #2 on: March 04, 2019, 04:38:38 pm »
Thanks for the reply Art! How does this code constantly check the values. Would this code be wrapped in a loop?

Art

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3848
    • View Profile
Re: How to add a timer in Hal script?
« Reply #3 on: March 04, 2019, 05:16:15 pm »
I believe it is incremented if conditions aren't met.


I'm not a programmer by any means. Maybe take a look at the entire Loneliness Plugin for a better idea of what's happening.

« Last Edit: March 04, 2019, 05:19:47 pm by Art »
In the world of AI it's the thought that counts!

- Art -

knight2000

  • Full Member
  • ***
  • Posts: 155
    • View Profile
Re: How to add a timer in Hal script?
« Reply #4 on: March 05, 2019, 02:29:15 pm »
I'll check it out