Thread

VS SDK: Making mutliple Chat events (Sdk)

VS SDK: Making mutliple Chat events // Sdk

1  |  

gamer

May 6, 2001, 7:15am
Hey, I would like to make my bot respond to serveral different chat commands
with different actions. Yet you can only have each SDK event once, if I use
Private 'Sub sdk_EventChat()' twice then I get ambigous name.

So would anyone be kind enough to supply the code to allow you to make a bot
able to respond to serveral chat commands?

Thanx in advance :)

-Gamer

kah

May 6, 2001, 8:36am
that's a quite usual first-time error to do :-)) (did it myself)

here's an example:
Private Sub sdk_EventChat()
If sdk.AwChatMessage = "you are a donkey" Then
sdk.AwSay "I am not!"
ElseIf sdk.AwChatMessage = "you are a Xelagot" Then
sdk.AwSay "nope, I'm a GamerBot"
ElseIf sdk.AwChatMessage = "wanna eat dinner with me?" Then
sdk.AwSay "sorry, I'm too busy!"
End If
End Sub

I hope that it helps :-))

KAH

[View Quote]

gamer

May 6, 2001, 9:08am
Thats helps a LOT...thanx very much for helping a newbie along his way :)

[View Quote]

baron

May 6, 2001, 9:17am
Or you can use the Select Case statement, if you use many options the code is more readable (at least for me).

Private Sub sdk_EventChat()
Select Case sdk.AwChatMessage
Case "you are a donkey"
sdk.AwSay "I am not!"
Case "you are a Xelagot"
sdk.AwSay "nope, I'm a GamerBot"
Case "wanna eat dinner with me?"
sdk.AwSay "sorry, I'm too busy!"
End Select
End Sub

Baron

[View Quote]

gamer

May 6, 2001, 9:49am
Hmm...yeah thats good...that can be applied to noon-sdk coding too...which
will be good for another program I'm working on, thanks!

[View Quote]

m a k a v e l i

May 6, 2001, 2:08pm
Or if you would like to get all the case crap out of the way do this:

Private Sub sdk_EventChat()
Message = LCase(sdk.AwChatMessage)
If Message = "hello" Then
sdk.AwSay "Hello!"
End If
If Message = "you suck!" then
sdk.AwSay "No, You SUCK!"
End If
End Sub

I have a code download at http://makaveli.8m.net that is the basic code form
that I use, all you do is add the code.

azazael

May 6, 2001, 6:02pm
Just like loops, case statements save so much hassle. I'd go as far as
saying they're an essential tool in the programmers arsenal, they make code
so much easier to read, save a shed load of typing and probably produce more
efficient code. Get to know them well :0)

Regards
Az


[View Quote]

m a k a v e l i

May 6, 2001, 6:12pm
Case would work, but it would be dumb if you wanted your bot case sensitive,
now wouldn't it? Baron, you would do it differently than you stated:

Private Sub sdk_EventChat()
Message = LCase(sdk.AwChatMessage)
Select Case Message
Case "you are a donkey"
sdk.AwSay "I am not!"
End Select
End Sub

That makes it not Case Sensitive, you need to make it better before you
offer your code, because the person will ask why it won't respond to "HeLlO"
when they have their code Case "hello"

azazael

May 6, 2001, 6:20pm
Go on Makaveli, I could do with a laugh. Why would a whole raft of If
statements be better than a Case statement?

No Reply Necessary

Az
[View Quote]

m a k a v e l i

May 6, 2001, 6:30pm
Did you even read my post? Case would work, just giving advice to Baron's
post.

baron

May 6, 2001, 7:14pm
I can think of a lot more things that need to be adressed besides case sensitive in the content of AW_EVENT_CHAT. In case you haven't noticed I didn't address them; I just showed a path using Select Case statement as a mean for clean and readable code, wasn't giving real code at all, just an example :)
Select Case works for me, if you prefer If and Elseif or anything else, that's fine, everyone has his style.

Baron



[View Quote]

azazael

May 6, 2001, 9:51pm
yes Makaveli I did, you ought to try it sometime. You said a case statement
would be 'dumb'
[View Quote]

moria

May 7, 2001, 2:10pm
ouch huge possible overhead.

In a case statement version you will go to the specific and drop out.. in
the if loop you will go through every single one every time.

If you get more than about 10 or 15 options its gonna start to crawl with
more than one person saying things around.

Each of those if's should at least have an exit loop in them, but the case
method would be better for this type of repetetive action.. its also less
code to parse as well.

Moria




[View Quote]

1  |  
Awportals.com is a privately held community resource website dedicated to Active Worlds.
Copyright (c) Mark Randall 2006 - 2022. All Rights Reserved.
Awportals.com   ·   ProLibraries Live   ·   Twitter   ·   LinkedIn