Announcement

Collapse
No announcement yet.

Python - Can't get player start plot

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Python - Can't get player start plot

    I'm working on a mod where I need the starting plot for the human player.

    For some reason I am having a lot of trouble getting the player starting location to work.

    Here is the code I am using to get the StartPlot - this piece seems to compile just fine:

    # get human player starting location
    tStartPlot = pHuman.getStartingPlot()

    The trouble I run into is when I try to get the X and Y for tStartPlot (so I can create a unit at that location) - every single line of code I have tried doesn't compile.

    Anyone have any suggestions on how to work with getStartingPlot to generate an X and Y that can be used in initUnit?

    Thanks!

  • #2
    According, to the API Locutus posted, tStartPlot.getX(), and tStartPlot.getY() should work... What's the specific error message you get when trying those?

    Vovan
    XBox Live: VovanSim
    xbox.com (login required)
    Halo 3 Service Record (I fail at FPS...)
    Spore page

    Comment


    • #3
      When I add the tStartPlot.getX() and getY() I get an error while it tries to load the mod.

      Here's more of the surrounding code (everything worked before adding the getX() and getY()):

      def setup(self):
      # find human player
      bComputer = True
      iCount = 0
      while bComputer:
      pPlayer = gc.getPlayer(iCount)
      if (pPlayer.isHuman()):
      bComputer = False
      pHuman = pPlayer

      # get human player starting location
      tStartPlot = pHuman.getStartingPlot()

      # add additional units to the human player's civ
      self.makeUnit(iSettler, pHuman, tStartPlot, 1)
      self.makeUnit(iScout, pHuman, tStartPlot, 1)
      self.makeUnit(iWarrior, pHuman, tStartPlot, 1)
      else:
      iCount = iCount + 1




      #################
      ### Utilities ###
      #################

      def makeUnit(self, iUnit, pHuman, tStartPlot, iNum):
      # display welcome message
      self.displayWelcomePopup()
      #Makes unit type iUnit for player pHuman at tStartPlot
      iX = tStartPlot.getX()
      iY = tStartplot.getY()
      # pHuman.initUnit(iUnit, tStartPlot[0], tStartPlot[1], UnitAITypes.NO_UNITAI)

      Comment


      • #4
        When I say it worked I mean the mod loaded - it's not actually generating the units.

        Comment


        • #5
          Originally posted by webryder
          Here's more of the surrounding code (everything worked before adding the getX() and getY()):
          EDIT: Ooops, my bad. Wrong comment on an error I thought you had, but you don't actually.

          Vovan
          XBox Live: VovanSim
          xbox.com (login required)
          Halo 3 Service Record (I fail at FPS...)
          Spore page

          Comment


          • #6
            Make sure you have HidePythonExceptions = 0 in your ini file so Python error messages are displayed.

            The correct code to create the units is pHuman.initUnit(iUnit, iX, iY, UnitAITypes.NO_UNITAI). This works for me.

            If you want to test if certain code is reached, you may find it useful to generate popups at strategic points in your code, like this:

            popup = PyPopup.PyPopup()
            popup.setBodyString( 'Got Here.')
            popup.launch()
            Administrator of WePlayCiv -- Civ5 Info Centre | Forum | Gallery

            Comment


            • #7
              For some reason the

              iX = tStartplot.getX()
              iY = tStartPlot.getY()

              prevents the module from even loading.

              Any ideas on what I'm doing wrong there?

              Comment


              • #8
                Originally posted by webryder
                For some reason the

                iX = tStartplot.getX()
                iY = tStartPlot.getY()

                prevents the module from even loading.

                Any ideas on what I'm doing wrong there?
                Well, just a guess, but if the setup function is called when the mod is loaded instead of when the game is started, then your pHuman would be null, and that would cause a exception on the lines you indicated when the mod is loaded.

                Vovan
                XBox Live: VovanSim
                xbox.com (login required)
                Halo 3 Service Record (I fail at FPS...)
                Spore page

                Comment


                • #9
                  I had to go back and check my event manager. :-)

                  The setup function is called from the EventManager onGameStart

                  Comment


                  • #10
                    Originally posted by webryder
                    I had to go back and check my event manager. :-)

                    The setup function is called from the EventManager onGameStart
                    Hmm, what if you try to do it onBeginGameTurn for the first turn?

                    EDIT: Wait, the mod doesn't even load, so that prolly wouldn't help. Are there any logs anywhere that would indicate a problem? Or maybe you get any meaningful error popups when you try to load the mod?

                    Vovan
                    XBox Live: VovanSim
                    xbox.com (login required)
                    Halo 3 Service Record (I fail at FPS...)
                    Spore page

                    Comment


                    • #11
                      I don't see any - is there a way to make it generate a log?

                      Comment


                      • #12
                        Can you post all your files here?

                        If I can take a look at it hands-on I should be able to figure it out pretty quick.

                        Comment


                        • #14
                          Couldn't put them all in a .zip file?

                          Comment


                          • #15
                            hehe - took me a while to figure out how to upload multiple files.... :-)

                            Comment

                            Working...
                            X