• Welcome to Valhalla Legends Archive.
 

OnTalk Error

Started by Yegg, October 24, 2004, 01:42 PM

Previous topic - Next topic

Yegg

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

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:


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?

Dyndrilliac

Try this: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


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).
Quote from: Edsger W. DijkstraIt is practically impossible to teach good programming to students that have had a prior exposure to BASIC; as potential programmers they are mentally mutilated beyond hope of regeneration.

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 =

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.

Dyndrilliac

Quote from: Yegg on October 24, 2004, 02:45 PM
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 =

You should use the CInt function to convert the string to an Integer for the equation.
Quote from: Edsger W. DijkstraIt is practically impossible to teach good programming to students that have had a prior exposure to BASIC; as potential programmers they are mentally mutilated beyond hope of regeneration.

Yegg

#5
I have another question, if i add something like:

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


now under my ontalk, wut do i do, for Call Commands, im not sur exactly wut it is

Warrior


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


Is what I would use and I just coded that in the reply box but I think its what your looking for.
Quote from: effect on March 09, 2006, 11:52 PM
Islam is a steaming pile of fucking dog shit. Everything about it is flawed, anybody who believes in it is a terrorist, if you disagree with me, then im sorry your wrong.

Quote from: Rule on May 07, 2006, 01:30 PM
Why don't you stop being American and start acting like a decent human?

Dyndrilliac

#7
I do: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
Quote from: Edsger W. DijkstraIt is practically impossible to teach good programming to students that have had a prior exposure to BASIC; as potential programmers they are mentally mutilated beyond hope of regeneration.

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?

Dyndrilliac

You always have to call a function in order to make use of it.
Quote from: Edsger W. DijkstraIt is practically impossible to teach good programming to students that have had a prior exposure to BASIC; as potential programmers they are mentally mutilated beyond hope of regeneration.

Warrior

#10

Call ParseCommands(Username,Message)


Unless you do it this way, expect a run-time error.
Quote from: effect on March 09, 2006, 11:52 PM
Islam is a steaming pile of fucking dog shit. Everything about it is flawed, anybody who believes in it is a terrorist, if you disagree with me, then im sorry your wrong.

Quote from: Rule on May 07, 2006, 01:30 PM
Why don't you stop being American and start acting like a decent human?

Yegg

#11
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

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


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
Call CMDS(username, message, Ping)
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

Dyndrilliac

Set a limit in the Split() Function.
Quote from: Edsger W. DijkstraIt is practically impossible to teach good programming to students that have had a prior exposure to BASIC; as potential programmers they are mentally mutilated beyond hope of regeneration.