Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 23rd, 2012, 11:48 PM
cemmac cemmac is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2012
Posts: 3 cemmac User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 m 35 sec
Reputation 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

Reply With Quote
  #2  
Old September 24th, 2012, 09:32 AM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,383 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 13 h 44 m 42 sec
Reputation Power: 383
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!

Reply With Quote
  #3  
Old September 24th, 2012, 07:17 PM
cemmac cemmac is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2012
Posts: 3 cemmac User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 m 35 sec
Reputation 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

Reply With Quote
  #4  
Old September 24th, 2012, 07:22 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,383 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 13 h 44 m 42 sec
Reputation Power: 383
You copy and paste the code you wrote directly from this forum just like others would. See what happens.

Reply With Quote
  #5  
Old September 25th, 2012, 01:44 PM
cemmac cemmac is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2012
Posts: 3 cemmac User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 m 35 sec
Reputation Power: 0
Quote:
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

Reply With Quote
  #6  
Old September 25th, 2012, 02:25 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,383 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 13 h 44 m 42 sec
Reputation Power: 383
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Quick Help for true or false output

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap