#1
  1. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Meriden, Connecticut
    Posts
    1,797
    Rep Power
    154

    Declaring True Problem


    I've been having a problem with checking if something equals True of False for a long time now. Here's the code (an example).
    Code:
    class FL:
        flags = False
    Later in the code, I have the code that declares whether it is True or False.
    Code:
    def event_flags(username, uflags):
        if username[-3] == ' 00':
            username = username[:-3]
        else:
            pass
        print "FLAGS: "+username+", "+uflags
        Log("FLAGS: "+username+", "+uflags)
        if username == 'sL[' and uflags == 2:
            FL.flags = True
        elif username == 'sL[' and uflags == 18:
            FL.flags = True
        else:
            pass
        if username == 'sL[' and uflags != 2 or username == 'sL[' and uflags != 18:
            FL.flags = False
        else:
            pass
    This code prints out the proper stuff, the correct flags (uflags). Only it doesn't seem to declare flags as True or False. Here is where the code gets determined (just an example).
    Code:
        # Kick
        if user.lower() in access and msg[:5].lower() == tr+"kick":
            if FL.flags == True:
                if msg[6:] not in userlist:
                    Queue(nothere)
                else:
                    if msg[6:].lower() in access or msg[6:].lower() in safelist:
                        pass
                    else:
                        Queue(kick+msg[6:])
            elif FL.flags == False:
                Queue(noops)
            else:
                pass
    userlist = the list of users in the channel
    user = user sending the message
    msg = message
    nothere = tells that the user is not in the channel
    noops = tells that the bot doesn't have ops. THis is dtermined by the flags. Queue() is just my queue, obviously. The bot has no problem sending messages but when it needs to determine whether or not it has the proper flags for certain commands it doesn't work correctly. It still reads FL.flags as False. What should I do?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2004
    Location
    Bimingham,AL
    Posts
    68
    Rep Power
    10

    try this


    Code:
    class FL:
        self.flags = False
  4. #3
  5. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Meriden, Connecticut
    Posts
    1,797
    Rep Power
    154
    self isn't declared as anything. That won't work.
  6. #4
  7. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Originally Posted by †Yegg†
    self isn't declared as anything. That won't work.
    Try using flags or FL.flags rather than self.flags - self.flags should be used if you want to access the variable from an method.

    Mark.
    programming language development: www.netytan.com Hula

  8. #5
  9. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Meriden, Connecticut
    Posts
    1,797
    Rep Power
    154
    I did trying using FL.flags, for instance,
    if FL.flags == True.
    Since I don't plan on releasing my bot, and I only use it for one purpose and I know it has a flags of 2 or 18 (operator status), I just set it to always be True. Thanks anyway.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Posts
    624
    Rep Power
    34
    You can condense this code:

    Code:
    def event_flags(username, uflags):
        if username[-3] == ' 00':
            username = username[:-3]
        else:
            pass
        print "FLAGS: "+username+", "+uflags
        Log("FLAGS: "+username+", "+uflags)
        if username == 'sL[' and uflags == 2:
            FL.flags = True
        elif username == 'sL[' and uflags == 18:
            FL.flags = True
        else:
            pass
        if username == 'sL[' and uflags != 2 or username == 'sL[' and uflags != 18:
            FL.flags = False
        else:
            pass

    into

    Code:
    def event_flags(username, uflags):
        if username[-3] == ' 00':
            username = username[:-3]
    
        print "FLAGS: "+username+", "+uflags
        Log("FLAGS: "+username+", "+uflags)
    
        if username == 'sL[':
            if uflags == 2 or uflags == 18:
                FL.flags = True
            else:
                FL.flags = False

    You don't always need to put "else: pass" at the end.


    As to why it isn't setting it to True or False, I don't understand the question. Are you sure this bit is working correctly?

    Code:
    if username == 'sL[' and uflags == 2:
            FL.flags = True
        elif username == 'sL[' and uflags == 18:
            FL.flags = True
    Maybe username is being 'Sl[' or '3sL[' or some other slightly-out value?

IMN logo majestic logo threadwatch logo seochat tools logo