Jump to content

Recommended Posts

Posted (edited)

I am trying to make a basic chat responder since I'm bored and have nothing else to do, lol. There is 1 input box and 1 button. When you click the button, it reads the box and based on what you typed, it gives a reply. simple. However, I didn't want to make multiple lines of code that lead to the same msgbox response.

If GUICtrlRead($Me) = "Hello" Then
     MsgBox(blah)
ElseIf GUICtrlRead($Me) = "hello" Then
     MsgBox(blah)
ElseIf GUICtrlRead($Me) = "hellO" Then
     MsgBox(blah)

Is there any way to do something that doesn't count caps?

That would save alot of time and space...

Edited by xPloit

00101101011110000101000001101100011011110110100101110100

Posted (edited)

Select...Case

***edit*** oops, guess i should have read the whole post, my bad, i just saw the stacked elseif's and that was my conditioned response.... StringLower() is the one i'd go with any time you're accepting input and giving someone the chance to screw it up

Edited by cameronsdad
Posted

I am trying to make a basic chat responder since I'm bored and have nothing else to do, lol. There is 1 input box and 1 button. When you click the button, it reads the box and based on what you typed, it gives a reply. simple. However, I didn't want to make multiple lines of code that lead to the same msgbox response.

If GUICtrlRead($Me) = "Hello" Then
     MsgBox(blah)
ElseIf GUICtrlRead($Me) = "hello" Then
     MsgBox(blah)
ElseIf GUICtrlRead($Me) = "hellO" Then
     MsgBox(blah)

Is there any way to do something that doesn't count caps?

That would save alot of time and space...

If StringLower(GUICtrlRead($Me)) = 'hello' Then
     MsgBox(blah)

Better?

I don't know what else to tell ya. ;)

AutoIt Stuff:

 

UDFs: {Grow}

Posted (edited)

i like stringlower haha. Thanks for the quick replies!

except that doesn't seem to work...

Func _Answer()
    If StringLower(GUICtrlRead($Me)) = "hello" or "hi" or "hey" Then
        MsgBox(0,"Response","Why hello there!")
    ElseIf StringLower(GUICtrlRead($Me)) = "how are you" or "how r u" or "how are u" or "how r you" or "how are you?" or "how r u?" or "how are u?" or "how r you?" Then
        MsgBox(0,"Response","I am doing well thanks!")
    Else
        MsgBox(0,"Reply","I was not programmed to respond to that statement")
    EndIf
EndFunc
Edited by xPloit

00101101011110000101000001101100011011110110100101110100

Posted (edited)

maybe you can tell me what's wrong with my code then haha

post it?

***edit***

sorry i didn't see it there. your problem is you're evaluating non boolean expressions.

***edit 2***

perhaps more elaboration...

meaning instead of doing it the way you're doing it, you have to either do multiple

$val1 = $val2 or $val1 = $val3 ;or etc

or you can use an array, OR (and this is my favorite when i have a LOT to check)

;make a blob
$IfItsAnyOfThese = "hihelloheyhuhwhatwhosaidthat"
;then evaluate all at once:
if StringInStr($IfItsAnyOfThese,$SubString) Then;rest here
Edited by cameronsdad
Posted

I'm afraid I dont understand...boolean expressions are 'true' or 'false'

If StringLower(GUICtrlRead($Me)) = (is 'true') "hey" or "hello" or "hi" Then

ElseIf (if the above isn't 'true')

etc.

00101101011110000101000001101100011011110110100101110100

Posted

I'm afraid I dont understand...boolean expressions are 'true' or 'false'

If StringLower(GUICtrlRead($Me)) = (is 'true') "hey" or "hello" or "hi" Then

ElseIf (if the above isn't 'true')

etc.

i realized it might be too vague as soon as i wrote (thinking of your other threads) so i added some explanation
Posted (edited)

okay, that makes sense except for one part...where does $SubString come from? Obviously that won't work just by typing it into Scite...it's not defined.

figured it out...

$SubString = GUICtrlRead($Me)

Edited by xPloit

00101101011110000101000001101100011011110110100101110100

Posted (edited)

I see what you're wanting to do now. Here's my best shot at it.

#include <Array.au3>

Dim $Search[3][3] = [   ["hello",   "hey",  "hi"], _
                        ["brb",     "afk",  "bbl"], _
                        ["bye",     "cya",  "ttyl"] ]
Dim $Respond[3] = ["Why hello there!", "See you soon.", "Goodbye!"]
Global $Search, $Respond

For $i = 1 To 5
    $Me = InputBox("Prompt", "Input a message.")
    reply(StringLower($Me))
Next

Func reply($Message)
    $Check = _ArraySearch($Search, StringLower($Message))
    If Not @error Then
        MsgBox(262144, "Message", $Respond[$Check])
    Else
        MsgBox(262144, "Message", "I don't know what to say to that.")
    EndIf
EndFunc

I think you get what I did:

+ A simple 2D array where rows are composed of columns that all represent the same type of message (hello, hey, hi)

+ The other array is the respond message for the entire row above.

Example: The program will respond "Why hello there!" to "hello", "hey", and "hi" and so forth with the other rows.

Edit: Added StringLower() to be passed to the function.

Edited by cembry90

AutoIt Stuff:

 

UDFs: {Grow}

Posted

yeah, sorry when i take the time to actually write up an example, i use identifiers that clearly communicate their purpose or make me laugh (frequently my exit function is some awful long string incorporating "MakeItStop". i do that for a few reasons, one being that the person i'm trying to teach (not work for) has to understand what i've written and make some attempt to rewrite it to work with their identifiers. sneaky and helpful and funny. that's me

Posted (edited)

Func _Answer()
    Local $sQuery = (GUICtrlRead($Me), $sAnswer, $sLast
    If StringRegExp($sQuery, "(?i)how.+r.+u") Then
        $sAnswer = "I am doing well thanks!"
    Else
        Switch $sQuery
            Case "hello", "hi", "hey"
                $sAnswer = "Why hello there!"
            Case Else
                $sLast = statement
                If StringRight($sQuery, 1) = "?" Then $slast = "question"
                $sAnswer = "I was not programmed to respond to that " & $slast & "."
        EndSwitch
    EndIf
        MsgBox(0,"Reply", $sAnswer)
EndFunc

The regex will even get lines like "How r u doing?"

EDIT: Added the variable $sLast so it will read better if $sQuery is a question.

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...