Valhalla Legends Forums Archive | Visual Basic Programming | OnTalk Error

AuthorMessageTime
Yegg
Ok i have a major error under my ontalk part of my bot where i have the commands, heres 1 of my commands:

[code]If LCase(message) = "?trigger" And GetUser("users", LCase(username)) >= "10" Or LCase(message) = "?trigger" And LCase(username) = Master Or GetUser("users", LCase(username)) >= "10" And LCase(message) = "?trig" Or LCase(username) = Master And LCase(message) = "?trig" Or LCase(username) = Master And LCase(message) = "?tr" Or GetUser("users", LCase(username)) >= "10" And LCase(message) = "?tr" Then
Send "My Current Trigger is [ " & Trigger & " ]"
End If
GoTo Done
Done:[/code]

Now, with this code, (all the other commands follow below this 1) if i do 1 of my many commands, the bot attempts to do like 20 other random commands at the same time and it gets ipbanned, wuts wrong with this code?
October 24, 2004, 6:42 PM
Dyndrilliac
Try this:[code]Select Case True
        Case LCase(message) = "?trigger" And GetUser("users", LCase(username)) >= 10
            Send "My Current Trigger is [ " & Trigger & " ]"
        Case LCase(message) = "?trigger" And LCase(username) = Master
            Send "My Current Trigger is [ " & Trigger & " ]"
        Case GetUser("users", LCase(username)) >= 10 And LCase(message) = "?trig"
            Send "My Current Trigger is [ " & Trigger & " ]"
        Case GetUser("users", LCase(username)) >= 10 And LCase(message) = "?tr"
            Send "My Current Trigger is [ " & Trigger & " ]"
    End Select
   
    GoTo Done[/code]

There are a lot of (in my opinion) architectural problems with your code. You should split the message and deal with the commands using a Select Case statement to quickly and efficiently iterate through them. Using Ifs like that in large quantities just isn't feasable. You should also try to mold your code into a "tree", and eliminate Goto statements, as they can create program flow problems and I personally see it as bad  coding style when a ladder of ifs or cases would work just fine, not to mention better.

Also, I couldn't help noticing you were using strings ("10") in equations. What is the return datatype on your GetUser() function? If it is integer than you need to remove the quotations (I did this in the code I provided for you already).
October 24, 2004, 7:41 PM
Yegg
k, thanks for the help, i'll try that, but i used "10" for the users access in users.txt. for example, it would have username=30 or somethin like that, 10 wus just the number after =
October 24, 2004, 7:45 PM
Grok
Good suggestions.  I might add one more.

Separate your command-sensing code from the security check.  After you parse the command and know what it is, pass it to a procedure which verifies user security to perform arbitrary commands.  The command and the user might be the parameters for the function.  After validatation, call a function which executes the command.

Separating your parsing logic, security check, and command execution will allow you to modify any one part later, without having to significantly rework your code.
October 24, 2004, 7:48 PM
Dyndrilliac
[quote author=Yegg link=topic=9300.msg85937#msg85937 date=1098647119]
k, thanks for the help, i'll try that, but i used "10" for the users access in users.txt. for example, it would have username=30 or somethin like that, 10 wus just the number after =
[/quote]

You should use the CInt function to convert the string to an Integer for the equation.
October 24, 2004, 8:32 PM
Yegg
I have another question, if i add something like:

[code]Sub Commands(ByVal username As String, ByVal Message As String)
username = Replace(username, "*", "")
Master = Form2.txtMaster.text
Trigger = Form2.txtTrigger.text
Dim s() As String
s() = Split(message, " ")
Select Case True
        Case GetUser("users", LCase(username)) >= "10" And LCase(message) = "?trigger" Or LCase(username) = Master And LCase(message) = "?trigger"
            Send "My Current Trigger is [ " & Trigger & " ]"
        Case GetUser("users", LCase(username)) >= "10" And LCase(message) = "?trig" Or LCase(username) = Master And LCase(message) = "?trig"
            Send "My Current Trigger is [ " & Trigger & " ]"
        Case GetUser("users", LCase(username)) >= "10" And LCase(message) = "?tr" Or LCase(username) = Master And LCase(message) = "?tr"
            Send "My Current Trigger is [ " & Trigger & " ]"
    End Select
   
    GoTo Done
End Sub[/code]

now under my ontalk, wut do i do, for Call Commands, im not sur exactly wut it is[code][/code]
October 24, 2004, 9:35 PM
Quarantine
[code]
Public Function ParseCommands(Username As String, Message As String)
    Dim Cmd() As String
        Cmd() = Split(Message, Space(1))

Select Case LCase(Cmd(0))
    Case "?trigger", "?trig", "?tr"
        If GetUser("users", LCase(Username)) >= "10" Or LCase(Username) = Master Then
            Send "My Current Trigger is [ " & Trigger & " ]"
        End If
            GoTo Done
                Exit Function
    Case Else
        '
End Select
               
Done:

End Function
[/code]

Is what I would use and I just coded that in the reply box but I think its what your looking for.
October 24, 2004, 9:47 PM
Dyndrilliac
I do:[code]Public Sub CommandRecognition(UserName As String, Message As String)
    Tmp = UserName
    UserName = Replace(UserName, "*", vbNullString)
   
    If LCase(Product) = "px2d" Or LCase(Product) = "vd2d" Then
        If InStr(Tmp, "*") = 0 Then Tmp = "*" & UserName
    End If
   
    Dim tChar As String
    tChar = Left$(Message, 1)
    If Not tChar = varTrigger Then Exit Sub
    Dim CommandName As String
    Dim Splt() As String
    Dim CommandCount() As String
    Dim Text() As String
    CommandCount() = Split(Message, "; ")
    For I = 0 To UBound(CommandCount)
        If CommandCount(I) = vbNullString Then GoTo ErrCommand
        CommandName = Split(CommandCount(I), Space(1))(0)
        If CommandName = vbNullString Then GoTo ErrCommand
        If InStr(CommandName, varTrigger) <> 0 Then CommandName = Replace(CommandName, varTrigger, vbNullString)
        Text() = Split(CommandCount(I), Space(1), 2)
        Select Case LCase(CommandName)
            Case "ver"
           
            Case "say"
           
            Case "blah"
           
        End Select
ErrCommand:
    Next I
End Sub[/code]
October 24, 2004, 11:43 PM
Yegg
ok, warrior, im going to use ur way of doing commands, my only question is, do i have to "activate" ParseCommands. like under ontalk or something do something like Call ParseCommands?
October 24, 2004, 11:48 PM
Dyndrilliac
You always have to call a function in order to make use of it.
October 25, 2004, 1:20 AM
Quarantine
[code]
Call ParseCommands(Username,Message)
[/code]

Unless you do it this way, expect a run-time error.
October 25, 2004, 1:37 AM
Yegg
Ok, warrior, i havn't really tried using ur parsecommands much until now when i really needed it, but i have a problem with it, heres the following code that i'm currently using

[code]Private Sub CMDS(ByVal username As String, ByVal message As String, ByVal Ping As Long)
Master = Form2.txtMaster.text
Trigger = Form2.txtTrigger.text
    Dim Cmd() As String
        Cmd() = Split(message, Space(1))

Select Case LCase(Cmd(0))
    Case Trigger & "designate", Trigger & "des", Trigger & "d"
        If GetUser("users", LCase(username)) >= "80" Or LCase(username) = Master Then
            PBuffer.InsertNTString "/designate " & Cmd(1)
            PBuffer.SendPacket &HE
        End If
            GoTo Done
                Exit Sub
    Case Else
        '
End Select
               
Done:

End Sub[/code]

i dunno y this happens, cuz it seems to happen only to me, but it will only do the command once, and from then on, it stops working. what do i do?
also, under my ontalk sequence, i have
[code]Call CMDS(username, message, Ping)[/code]
is there something wrong with that that is allowing the command to run only once?

Edit:nvm i figured it out, also warrior ur code wont do something like say 1 2 3 it would only say 1
November 1, 2004, 10:55 PM
Dyndrilliac
Set a limit in the Split() Function.
November 2, 2004, 8:30 PM

Search