Valhalla Legends Forums Archive | Battle.net Bot Development | Help with a flags access system.

AuthorMessageTime
LackLuster)
Ok, so my bot is using a flags system, and I am having trouble with having users added remotely...

The flags are currently strings (Least efficient method, I know, but it's the easiest, and my bot isn't meant to be super fast or anything!), KBSXMT, and I can't have somebody added unless they are added with their flags in the same order... Any ideas on how to fix it?
November 5, 2005, 3:06 AM
Kp
Stop using a string.  A bitmask will implicitly solve your problem, as well as looking nicer. :)
November 5, 2005, 4:08 AM
LackLuster)
Thank you... I'm a newb, so hopefully I can figure out how to make a bitmask work. :x
November 5, 2005, 5:44 PM
Networks
Create a function that orders the letters in the beginning? I don't see why it has to be that way, maybe you should change the method in which your bot checks for flags.

Kp is extremely correct, bitwise is far more efficient and powerful and is well worth learning it.
November 5, 2005, 7:23 PM
Quarantine
http://visualbasic.about.com/od/usingvbnet/l/bldykand_or_not.htm

ot: extremely correct? :p
November 5, 2005, 7:42 PM
JoeTheOdd
I'm not quite sure what you're trying to do, but I think its see if they have a specific flag. You need to use InStr() and see if it returns a non-zero.

An example of how this is done is modAccess from prjJoeBotRGE. You'll obviously need to change the variables referencing the position of the data, but whatever.

[code]Public Function GetFlags(Username As String) As String
    Let GetFlags = CStr(modINI.ReadINI("JoeBotRGE-DB", Username, "config.ini"))
End Function

Public Function HasFlag(Username As String, Flag As String) As Boolean
    Let HasFlag = CBool(InStr(1, modINI.ReadINI("JoeBotRGE-DB", Username, "config.ini"), Flag))
End Function

Public Sub AddFlag(Username As String, Flag As String)
    Dim CurFlag As String: Let CurFlag = UCase(modINI.ReadINI("JoeBotRGE-DB", Username, "config.ini"))
    Call modINI.WriteINI("JoeBotRGE-DB", Username, IIf(InStr(1, CurFlag, Flag) <> 0, CurFlag, CurFlag & Flag), "config.ini")
End Sub

Public Sub RemFlag(Username As String, Flag As String)
    Dim CurFlag As String: Let CurFlag = UCase(modINI.ReadINI("JoeBotRGE-DB", Username, "config.ini"))
    Call modINI.WriteINI("JoeBotRGE-DB", Username, Replace(CurFlag, Flag, vbNullString), "config.ini")
End Sub[/code]

You'll also need modINI for using INI files.

[code]Public Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Public Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As Any, ByVal lpFileName As String) As Long

Public Sub WriteINI(sSection As String, sKey As String, sValue As String, sFile As String)
    Call WritePrivateProfileString(sSection, sKey, sValue, App.Path & "\" & sFile)
End Sub

Public Function ReadINI$(riSection$, riKey$, riFile$)
    Dim sRiBuffer$, sRiValue$, sRiLong$

    riFile$ = (App.Path & "\" & riFile$)
    If Dir(riFile$) <> "" Then
        sRiBuffer = String(255, vbNull)
        sRiLong = GetPrivateProfileString(riSection, riKey, Chr(1), sRiBuffer, 255, riFile)
        If Left(sRiBuffer, 1) <> Chr(1) Then
            sRiValue = Left(sRiBuffer, sRiLong)
            ReadINI = sRiValue
        End If
    Else
        ReadINI = ""
    End If
End Function[/code]

[hr]

A bitwise flags system would be a bit harder to implement, but probably faster to use. I'd code this for you, but I'm pretty lazy right now. =p.
A = 0x01
B = 0x02
C = 0x04
D = 0x08
E = 0x10
F = 0x20
G = 0x40
H = 0x80
F = 0x100
..and so on, doubling each time, until you get to Z = whatever Z equals.
To check it for a flag, say A
If lFlags And A = A Then
  'Flag = True
Else
  'Flag = False
End If
November 6, 2005, 3:30 AM
Networks
A BitWise flag system isn't at all harder, it's just one more thing to learn. If anything it takes up far less space in your computer's memory opposed to literal strings which is why anyone should look into it.
November 6, 2005, 3:52 AM

Search