I have updated this code with modifications suggested by Reticality. I would like to access the value of hands_count which resides within the array of packets[] and or the array type[] below.
def history2packets(self, history, game_id, cache):
game_index = 0
player_list_index = 7
packets = []
for event in history:
self.event = event
type = event[0]
if type == "game":
(type, level, hand_serial, hands_count, time, variant, betting_structure, player_list, dealer, serial2chips) = event
if len(serial2chips) > 1:
nochips = 0
for (serial, chips) in serial2chips.iteritems():
if serial == 'values':
continue
packets.append(PacketPokerPlayerChips(game_id = game_id,
serial = serial,
bet = nochips,
money = chips))
packets.append(PacketPokerInGame(game_id = game_id,
players = player_list))
if self.previous_dealer == dealer:
previous_dealer = -1
else:
previous_dealer = self.previous_dealer
packets.append(PacketPokerDealer(game_id = game_id,
dealer = dealer,
previous_dealer = previous_dealer))
self.previous_dealer = dealer
packets.append(PacketPokerStart(game_id = game_id,
hand_serial = hand_serial,
hands_count = hands_count,
time = time,
level = level))
and use that value in another function like so:
def autoDeal(self):
self.cancelDealTimeout()
if not self.allReadyToPlay():
for player in self.game.playersAll():
if player.getUserData()['ready'] == False:
for avatar in self.avatar_collection.get(player.serial):
if self.factory.verbose > 1:
self.message("Player %d marked as having a bugous PokerProcessingHand protocol" % player.serial)
avatar.bugous_processing_hand = True
if self.event[2] != 0:
self.beginTurn()
self.update()
else:
reactor.callLater(10, self.beginTurn)
self.update()
I am still getting an error but a different one.
2015-02-19 22:10:11-0500 [-] Unhandled Error
Traceback (most recent call last):
File "/usr/lib/python2.6/dist-packages/twisted/application/app.py", line 445, in startReactor
self.config, oldstdout, oldstderr, self.profiler, reactor)
File "/usr/lib/python2.6/dist-packages/twisted/application/app.py", line 348, in runReactorWithLogging
reactor.run()
File "/usr/lib/python2.6/dist-packages/twisted/internet/base.py", line 1170, in run
self.mainLoop()
File "/usr/lib/python2.6/dist-packages/twisted/internet/base.py", line 1179, in mainLoop
self.runUntilCurrent()
--- <exception caught here> ---
File "/usr/lib/python2.6/dist-packages/twisted/internet/base.py", line 778, in runUntilCurrent
call.func(*call.args, **call.kw)
File "/usr/lib/python2.6/dist-packages/pokernetwork/pokertable.py", line 738, in autoDeal
if self.event[2] != 0:
exceptions.AttributeError: PokerTable instance has no attribute 'event'
Both function are within the same module and class. What else could be wrong?