The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Python Programming
|
Quick Help for true or false output
Discuss Quick Help for true or false output in the Python Programming forum on Dev Shed. Quick Help for true or false output Python Programming forum discussing coding techniques, tips and tricks, and Zope related information. Python was designed from the ground up to be a completely object-oriented programming language.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

September 23rd, 2012, 11:48 PM
|
|
Registered User
|
|
Join Date: Sep 2012
Posts: 3
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
|

September 24th, 2012, 09:32 AM
|
 |
Contributing User
|
|
|
|
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!
|

September 24th, 2012, 07:17 PM
|
|
Registered User
|
|
Join Date: Sep 2012
Posts: 3
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
|

September 24th, 2012, 07:22 PM
|
 |
Contributing User
|
|
|
|
|
You copy and paste the code you wrote directly from this forum just like others would. See what happens.
|

September 25th, 2012, 01:44 PM
|
|
Registered User
|
|
Join Date: Sep 2012
Posts: 3
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
|

September 25th, 2012, 02:25 PM
|
 |
Contributing User
|
|
|
|
|
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.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|