Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8341665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T05:33:05+00:00 2026-06-09T05:33:05+00:00

I’m trying to make Battleship for practice, and single player was a success…when there

  • 0

I’m trying to make Battleship for practice, and single player was a success…when there was only one player and one set of ships and a board 😛

Any idea why this is giving me an ‘int object is unscriptable’ error???

Here is the Board class. Well, some of it anyway:

class Board:
    'Game Board'
    topMarkers = list('ABCDEFGHIJKLMNOPQRSTUVWXYZ')
    sideMarkers = list(range(0, 26))


    def __init__(self,h,w): #Makes the map
        self.height = h
        self.width = w

        self.xMarkers = []
        self.yMarkers = []
        self.hitList = []
        self.hitListCopy = []

        self.boardSpace = '         '

        wave = '~'
        self.row = []
        self.column = []
        #self.column = wave * self.width # If width is 4, column is now '~~~~'

        for c in range(self.width):
            self.column.append(wave)
            self.xMarkers.append(Board.topMarkers[c])

        for r in range(self.height): #
            self.row.append(self.column[:]) #Use the slice to make copies
            self.yMarkers.append(Board.sideMarkers[r])



    def showGrid(self):
        print self.boardSpace + '  ' +  ' '.join(self.xMarkers)
        for i in range(self.height):
            print self.boardSpace + str(self.yMarkers[i]) + ' ' + '-'.join(self.row[i])

And here’s the code that actually runs it, the part of the code that is causing it is in the bottom while and for loop, where it says in the comment to show the grid of YOUR map.

p1 = [[Board(7,7), Board(7,7)], Move(), Connection(1, netEnable)]
p2 = [[Board(7,7), Board(7,7)], Move(), Connection(2, netEnable)]
#p3 = [[Board(7,7), Board(7,7)], Move(), Connection(3, netEnable)]

#Like this p1 = [[theirBoard, attackBoard], Moves, Connection]



#p = [p1,p2,p3]
p = [p1,p2]


ships = [Ship(0),Ship(0),Ship(0)]
ships2 = [Ship(0),Ship(0),Ship(0)]

numOfPlayers = len(p)


youPlayer = int(raw_input('Which player are you? 1,2,3:   '))

youPlayer -= 1



boardr = p[youPlayer][0][1].getRowData()
boardM = p[youPlayer][0][0].getMarkerData()
#raw_input(boardr)
raw_input(boardM)



#Set Ships Dialog.
for i in range(len(ships)):
    p[youPlayer][0][1].showGrid() 
    ships[i].setShip(boardr, boardM)


shipPosAll = [[],[],[]]    

for i in range(len(ships)):
    shipPosAll[youPlayer].append(ships[i].getShip()) #USE THIS INFO TO FEED TO THE BOARD TO TELL IT WHERE SHIPS ARE SO YOU KNOW WHERE HITS ARE.

print 'shipPos at line 382 : %s' % (shipPosAll[youPlayer])




#INIT, DO ONLY ONCE

for i in range(numOfPlayers): 
    print p[i][2].GetTime()

#MAIN LOOP
while gameNotOver:

    for i in range(numOfPlayers):
        playersCheck = [0,1]
        del playersCheck[youPlayer]

        print 'Player %s turn' % (i)
        print 'Here are your ships'
        #raw_input (p[i][0][1])
        p[i][0][1].showGrid() #Show the grid of the player (TheirShips) HERES WHERE THE PROBLEM IS!!!!

        print 'Where do you want to attack?'
        p[i][0][0].showGrid() #Show the grid of the player (AttackShips)

        hits = p[i][0][0].getHitList()
        alreadyMade = False
        while alreadyMade == False:
            coords = p[i][0][0].chooseMove()
            alreadyMade = p[i][1].addMove(coords) #Returns true if move accepted, otherwise false

        lastMove = p[i][1].getMove()
        print 'The move you made was %s' % (lastMove)
        p[i][2].Send(lastMove)
        changeCoords = p[i][2].Check()
        p[i][0][0].changeRow('B')

        for p in playersCheck: #Check every player who is not you. You were deleted at teh beginning.
            checkForSunk(shipPosAll[p], hits)
            print 'Current Attacked Players shipPos: %s' % (shipPosAll[p])
        #p1Site.Send(coords)
        #print 'Thing %s' % (shipPos[i])
            if isGameOver(shipPosAll[p]): #PROBLEM.
                gameNotOver = False
                break

    for i in range(numOfPlayers):
        print p[i][1].getAllMoves()


print 'All Ships Sunk. The End. Wat more you want from mme its 3:48am'

Thanks

Here’s the exact message I get.

Traceback (most recent call last): File “name/battleship_wClasses.py”,
line 431, in p[i][0][1].showGrid() #Show the grid of the
player (TheirShips) TypeError: ‘int’ object is unsubscriptable –

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T05:33:08+00:00Added an answer on June 9, 2026 at 5:33 am

    You have two (overlapping) contradictory definitions for p:

    p = [p1,p2]
    

    and

        playersCheck = [0,1]
        for p in playersCheck:
    

    p[i][0][1].showGrid() works with the first definition, but fails when p is assigned an integer value from the second definition.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I am trying to render a haml file in a javascript response like so:
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.