Jump to content

Recommended Posts

Posted

Howdie,

I have this piece of code

Func _Talk($Input)
    Switch $Input
        Case "Hi", "Greetings"
            Return "Hello"
    EndSwitch
EndFunc
(Shorten).

So, now, if I run it (with inputbox & stuff, of course) it only responds on "Hi", not on "Hi.", "Hi?" or "Hi!". I know it could be made by using If and StringInStr but that is really long and unreadable. Switch (or Select) is simple and compact :)

I would very appreciate your solution/response/howto (if you have it, of course).

What Doesn't Work

I tried this but they won't work:

Func _Talk($Input)
    Switch $Input
        Case "Hi" OR "Greetings"
            Return "Hello"
    EndSwitch
EndFunc
That would always return "Hello", eg. "What's Up?" "Hello"

Thanks! :P

i542

I can do signature me.

Posted (edited)

Still involves a messy "String" function, which I'm guessing you want to stay away from. But this is how I might do it.

Msgbox(1,"",_Talk(InputBox("","Hello")))


Func _Talk($Input)
    Select
        Case StringRegExp($Input,"Hi?") OR StringRegExp($Input,"Greetings?")
            Return "Hello"
    EndSelect
    Return "Fine, don't say Hi."
EndFunc
Yes, I tried it, but it won't work :). Thanks on answer. Edited by i542

I can do signature me.

Posted

What won't work about it? It responds on "Hi", "Hi!", "Hi.", and "Hi?" just like you asked.

Yeees, but on "How are you" it respond by "Hi" :)

I can do signature me.

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...