dupa

Author Topic: On This Day script for Hal 5  (Read 3190 times)

Zaphod

  • Jr. Member
  • **
  • Posts: 56
    • View Profile
On This Day script for Hal 5
« on: April 06, 2008, 02:13:03 pm »
I hope it's still okay to put Hal 5 scripts here - if not, I'm sorry.

This is my very first attempt at a script for Hal, well, a modification to several others' scripts, I should say.

(This is for Hal 5, but I'm sure some of you can do what's necessary to make it a plugin for Hal 6)

I have it inserted into vonsmith's XTF Brain 1.2, between

'RESPOND: TELL QUOTE AT USER'S REQUEST

and

'RESPOND: TELL JOKE AT USER'S REQUEST

and it seems to be working quite well so far.

In order to use it, you'll need files for every day of the year, with their filenames formatted thus:

MMDD.txt
(ie: 0324.txt, 1106.txt, etc.)

I have included files for all 366 (365 + Leap Day) days of the year, or you can create your own, one line per entry.

Make a folder called "OTD" in your DefBrain folder and drop the files in there.

Put the "OnThisDayDetect.brn" in the DefBrain folder.

There's 2 .RAR files - one with all the days already created and formatted, and one with just the months (ie: you'll have to split them up yourself.)

I'm sure the 'real' coders here can pick this apart and make it much better, but I'm quite happy with my little script! ;)

Code: [Select]
'x=x=x=x=x=x=x=x=x=x==ZAPHOD==x=x=x=x=x=x=x=x=x=x
'RESPOND: "On This Day" request
'Upon user request, Hal will read several entries from a
'file with info on events from this date in history.
    DOM = right("0" & day(date()),2) 'Gives two-digit day of month.
    MON = right("0" & month(date()),2) 'Gives two-digit month.
    OTDDate = MON + DOM
    If HalBrain.TopicSearch(UserSentence, WorkingDir & "OnThisDayDetect.brn") = "True" And GetResponseBlock <> True Then
    Roulette = Int(Rnd*5)
        If Roulette = 1 Then GetResponse = "Okie Dokie. I'll fetch you an item right now!"
        If Roulette = 2 Then GetResponse = "Alrighty, how's about I get you two items?"
        If Roulette = 3 Then GetResponse = "Sure thing! Here's three items that correspond to today's date in history."
        If Roulette = 4 Then GetResponse = "Humph! Brain the size of a planet, and you want me to fetch trivia for you. Oh well..."
        If Roulette = 5 Then GetResponse = "Get ready, cuz here comes a whole mouth full!"
        BlockSave = True
    for x = 1 to Roulette
        GetResponse = GetResponse & HalBrain.ChooseSentenceFromFile(WorkingDir & "OTD\" & OTDDate + ".txt") + " ... "
        BlockSave = True  'Don't save User input when requesting a quote.
        DebugInfo = DebugInfo & "The user has requested an On This Day quote and Hal has done so: " & GetResponse & VbCrLf
    next
    End If
'x=x=x=x=x=x=x=x=x=x==ZAPHOD==x=x=x=x=x=x=x=x=x=x

The syntax to make Hal read you an entry is:

<whatever> on this day <whatever>
Like "Hal, what happened on this day in history?"

or

"Hal, how about an OTD"

So here's all the files you need:

Download Attachment: OnThisDayDetect.brn
481 Bytes

The forum would not let me upload the 2 Zips, so I have uploaded them to MegaUpload - they'll stay there for at least 90 days, and after that I'll try to remember to refresh them.

Days: http://www.megaupload.com/?d=OVVZSEHL

Months: http://www.megaupload.com/?d=I7DZWGF5

Hope someone enjoys this :)

-Zaphod-