Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tiny optimization
#9
Okay I was thinking of a little bit different way to do the commands. What i came up with is very similar to HandleData.
This method would make it easier for users to add commands without using left, mid and whatnot and counting letters.

HandleKeyPresses

Add
Code:
Dim Command() As String

After
Code:
If Left$(MyText, 1) = "/" Then

Add
Code:
Command = Split(MyText, " ")
This code will split the string when there is a space and sets to the Command array.

Add:
Code:
Select Case Command(0)
Now we add a select case statement that will do different things depending on the actual command.

The following is just a simple example:
Code:
Case "/help"
                    Call AddText("Social Commands:", HelpColor)
                    Call AddText("'msghere = Broadcast Message", HelpColor)
                    Call AddText("-msghere = Emote Message", HelpColor)
                    Call AddText("!namehere msghere = Player Message", HelpColor)
                    Call AddText("Available Commands: /help, /info, /who, /fps, /inv, /stats, /train, /trade, /party, /join, /leave", HelpColor)

The following will first check to make sure there's more than one string in our array so we don't error out, then it will send the second string in the array. The first string will always be the command.
Code:
Case "/info"
                    ' Checks to make sure we have more than one string in the array
                    If UBound(Command) >= 1 Then
                        Call SendData(CPlayerInfoRequest & SEP_CHAR & Command(1) & END_CHAR)
                    End If
Code:
' Party request
                Case "/party"
                    ' Make sure they are actually sending something
                    If UBound(Command) >= 1 Then
                        Call SendPartyRequest(Command(1))
                    Else
                        Call AddText("Usage: /party playernamehere", AlertColor)
                    End If

Code:
' Giving another player access
                Case "/setaccess"
                    ' Check access level
                    If GetPlayerAccess(MyIndex) >= ADMIN_CREATOR Then
                        ' Check to make sure we have the right amount of additional info
                        If UBound(Command) >= 2 Then
                            Call SendSetAccess(Command(2), Command(1))
                        End If
                    End If

Just a little something to tell someone they don't have a valid command.
Code:
Case Else
                    AddText "Not a valid command!", HelpColor

Then right before the
Code:
End If
for the
Code:
If Left$(MyText, 1) = "/" Then

Add
Code:
End Select
            
            MyText = vbNullString
            frmMirage.txtMyChat.Text = vbNullString
            Exit Sub

Just an idea. Let's hear what everyone thinks.
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)