#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    3
    Rep Power
    0

    Quick Help for true or false output


    Hi All,

    I have the below script working for me as part of larger scripts and need just a little help with one thing.

    Here is the script

    # add claim
    if text.find('!mine') > -1 and chatroom == 'rivatein':
    # check within alliance table
    db = database.get_db()
    d = db.execute('select player from alliance_names where player=?',(sender,))
    p = None
    for r in d:
    p = r[0]
    bot.output('/whisper '+sender+' Available commands.. !fight, !shoot, !tickle and !parp.','C')
    if p !=None:
    try:
    data = text.split()
    coord = data[1]
    arrival = data[2]

    xy = coord.split(':',1)
    x = xy[0]
    y = xy[1]
    if len(x) > 3 or len(y) > 3:
    raise IndexError

    player, baron_arrival = database.check_claim(x,y)



    if player:
    bot.output('/whisper '+sender+' City claimed by ' + player + '. Baron arriving at ' + baron_arrival + \
    ' reclaim if you feel you can get their first')
    else:
    database.add_claim(x,y,sender, arrival)
    bot.output('/whisper' +sender+ x + ':' + y + ' successfully claimed! But it belongs to whoever gets it first')

    except (IndexError, ValueError, TypeError, KeyError):
    # bot.output('Get cemmac to check claims or the format of how to claim.')
    bot.output('/whisper '+sender+' e.g. /w Floss1e !claim [city-coords] [arrival time]', 'C')
    return

    This is a script used within an online game and as you can see its to make claims while whispering to an ingame bot.

    Basically the bot is connect and waits for the key word !mine whispered (chatroom == 'rivatein') to it from a player with the x:y coords of a city.

    It then checks to see if that player name is in the DB table list and then processes the request.

    My problem is if a player is not in the list it will show this bot.output('/whisper '+sender+' Available commands.. !fight, !shoot, !tickle and !parp.','C') and not go any further.

    If the player is in the DB list then to goto the bot output below if player: telling them they have sucessfully claimed that city.

    ATM it just shows the first part and does allow them to claim it as they are on the DB list.

    We have a similiar script to check the city as well with the same issue. It allows the player to check if in the DB list who has claimed it, and if the player is not in the list it just shows the 1st part.

    Basically I am getting the same response for players who are on the DB list and players who are not.

    Any help would be great and thanks in advance.

    i hope i have explained this so you are able to understand.

    Cemmac
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,709
    Rep Power
    480
    Your program gives me IndentationError. Please follow the link at my signature and fix your post. Thanks.
    Code:
    $ ( cd /tmp && python p.py )
      File "p.py", line 4
        db = database.get_db()
         ^
    IndentationError: expected an indented block
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    3
    Rep Power
    0

    if then else


    # add claim
    if text.find('!mine') > -1 and chatroom == 'rivatein':
    # check within alliance table
    db = database.get_db()
    d = db.execute('select player from alliance_names where player=?',(sender,))
    p = None
    for r in d:
    p = r[0]
    bot.output('/whisper '+sender+' Available commands.. !fight, !shoot, !tickle and !parp.','C')
    if p !=None:
    try:
    data = text.split()
    coord = data[1]
    arrival = data[2]

    xy = coord.split(':',1)
    x = xy[0]
    y = xy[1]
    if len(x) > 3 or len(y) > 3:
    raise IndexError

    player, baron_arrival = database.check_claim(x,y)



    if player:
    bot.output('/whisper '+sender+' City claimed by ' + player + '. Baron arriving at ' + baron_arrival + \
    ' reclaim if you feel you can get their first')
    else:
    database.add_claim(x,y,sender, arrival)
    bot.output('/whisper' +sender+ x + ':' + y + ' successfully claimed! But it belongs to whoever gets it first')

    except (IndexError, ValueError, TypeError, KeyError):
    # bot.output('Get cemmac to check claims or the format of how to claim.')
    bot.output('/whisper '+sender+' e.g. /w Floss1e !claim [city-coords] [arrival time]', 'C')
    return

    the code is correct and works well...

    I am using pyscripter to check indention errors..

    cem
  6. #4
  7. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,709
    Rep Power
    480
    You copy and paste the code you wrote directly from this forum just like others would. See what happens.
    [code]Code tags[/code] are essential for python code and Makefiles!
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    3
    Rep Power
    0
    Originally Posted by b49P23TIvg
    You copy and paste the code you wrote directly from this forum just like others would. See what happens.
    Code:
    # add claim     if text.find('!mine') > -1 and chatroom == 'rivatein':     # check within alliance table         db = database.get_db()         d = db.execute('select player from alliance_names where player=?',(sender,))         p = None         for r in d:            p = r[0]         bot.output('/whisper '+sender+' Available commands.. !fight, !shoot, !tickle and !parp.','C')         if p !=None:             try:              data = text.split()              coord = data[1]              arrival = data[2]               xy = coord.split(':',1)              x = xy[0]              y = xy[1]              if len(x) > 3 or len(y) > 3:                 raise IndexError               player, baron_arrival = database.check_claim(x,y)                 if player:                 bot.output('/whisper '+sender+' City claimed by ' + player + '. Baron arriving at ' + baron_arrival + \                         ' reclaim if you feel you can get their first')              else:                 database.add_claim(x,y,sender, arrival)                 bot.output('/whisper' +sender+ x + ':' + y + ' successfully claimed! But it belongs to whoever gets it first')              except (IndexError, ValueError, TypeError, KeyError):           #  bot.output('Get cemmac to check claims or the format of how to claim.')              bot.output('/whisper '+sender+' e.g. /w Floss1e !claim [city-coords] [arrival time]', 'C')         return
    I have just inserted the database check on the first catch.

    Thanks again

    Cemmac
  10. #6
  11. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,709
    Rep Power
    480
    You found the code tags. Much closer.

    Please read your posted code. If you still think it's readable you'd best start your own forum for special people.

    Many others, most, in fact, manage to post code that's readable. I'm sure you can too.

    mmmmmm,

    Practice with the "Preview Changes" button.
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo