Announcement

Collapse
No announcement yet.

Initial Python reference

Collapse
This is a sticky topic.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • #31
    You can't just change the value of YieldTypes.YIELD_FOOD though, that's just the index of the food value, not the actual food value. You can't manipulate in-game variables such as food, hitpoints, etc directly, you have to do so through functions. The onCityDoTurn event gives you a city argument, so the second line in your example would have to be something like:

    Code:
    pCity.changeFood(Pycity.getFoodRate() * (getGoodHealth() -  getBadHealth()) * 0.05)
    I took the popup code and added it in a bunch of different places: onCityDoTurn, onPlayerEndTurn, OnCultureExpansion... But they never showed up, which suggests that even a changefood command wouldn't process.
    Mylon Mod - Adressing game pace and making big cities bigger.
    Inquisition Mod - Exterminating heretic religions since 1200 AD

    Comment


    • #32
      Then you're doing something wrong, because it works for me. Can you post the exact file you're testing with?
      Administrator of WePlayCiv -- Civ5 Info Centre | Forum | Gallery

      Comment


      • #33
        Originally posted by Locutus


        You have to use attachMultilineText instead of setText or whatever is currently used. The civilopedia file (CvPedia*) have a number of examples of this.

        Thanks for the reply Locutus!

        What I mean is I'm writing text to a panel and it's clipping vertically, not horizontally... It's a list of text (in the Civolopedia actually) but it's too long to show all at once so it goes off the bottom edge...

        Comment


        • #34
          Vertical, horizontal, it's all the same with attachMultilineText, if I'm not mistaken. The two booleans you have to give when adding the panel determine the type of scroll you get, play around with those.
          Administrator of WePlayCiv -- Civ5 Info Centre | Forum | Gallery

          Comment


          • #35
            I'm taking the entire CvEventManager.py file and adding the popup to it inside one of the functions:

            Code:
            	def onCultureExpansion(self, argsList):
            		'City Culture Expansion'
            
            		popup = PyPopup.PyPopup()
            		popup.setBodyString( 'Hello World' )
            		popup.launch()
            		
            		pCity = argsList[0]
            		iPlayer = argsList[1]
            		CvUtil.pyPrint("City %s's culture has expanded" %(pCity.getName(),))
            I can't say I'm experienced with Python or object oriented language for that matter, so I don't know how to properly initialize a file, so I just used an already existing one. I also added the same popup code to other functions in the same file, such as OnEndTurn, OnCityDoTurn, ect... Just as a kind of troubleshooting to see if the commands are being processed.
            Mylon Mod - Adressing game pace and making big cities bigger.
            Inquisition Mod - Exterminating heretic religions since 1200 AD

            Comment


            • #36
              Okay, it seems that the problem is that the python files weren't updating. The cache needed to be cleared.
              Mylon Mod - Adressing game pace and making big cities bigger.
              Inquisition Mod - Exterminating heretic religions since 1200 AD

              Comment


              • #37
                Are you modifying the main game files or using a Mod folder?

                Comment


                • #38
                  I'm using a mod folder, but I'm also launching the game directly into the mod using the command line. Still, even before I did that I wasn't getting any error messages.

                  Error messages are something I'm familiar and comfortable with. Changing files and seeing no result at all is not.
                  Mylon Mod - Adressing game pace and making big cities bigger.
                  Inquisition Mod - Exterminating heretic religions since 1200 AD

                  Comment


                  • #39
                    Okay, on another note, I'm having a hard time changing the food rate of the city. I believe it's a type-casting error: My formula mixes integers and a float, and passes the result of this formula to a function expecting an integer. Typecasting really bugged the heck out of me in C, so could I get some help on this?

                    The code I'm using now is:
                    Code:
                                    HealthyFood = getFoodRate(pCity) * (getGoodHealth(pCity) -  getBadHealth(pCity)) * 0.1
                    		pCity.changeFood(HealthyFood)
                    If I use pCity.changeFood(10) it works just fine.

                    Neither does pCity.changeFood(getGoodHealth(pCity)) or pCity.changeFood(pCity.getGoodHealth()) oddly enough.
                    Last edited by Mylon; November 6, 2005, 11:36.
                    Mylon Mod - Adressing game pace and making big cities bigger.
                    Inquisition Mod - Exterminating heretic religions since 1200 AD

                    Comment


                    • #40
                      You can just cast HealthyFood to an int as you pass it into that function.
                      Code:
                      pCity.changeFood(int(HealthyFood))

                      Comment


                      • #41
                        For the onUnitMove() function... Is there any way to get both the original and destination plot locations? Obviously the destination is the value of pPlot (or pUnit.pPlot()). But I can't see any way to figure out where the unit came from.

                        Alternatively, is there any event trigger that can be called before the unit is moved (but after the move order has been issued)?

                        Bh

                        Comment


                        • #42
                          Hi Trip, is there a way of switching the Health and food values-such that Health dictates population growth and Food surplus/deficit dictates the health bonus/penalty? If so, where will I find it in the scripts?
                          Thanks a bunch !

                          Yours,
                          Aussie_Lurker.

                          P.S. In combination with that, how do I add/subtract the things which contribute to health/unhealth?

                          Comment


                          • #43
                            Another question - it's possible to add new Promotion types, yes? I haven't been able to successfully do so at this point, just want to make sure I'm not banging my head against the wall pointlessly.

                            edit: nm, got it working. Apparently if you add a new promotion type and try and load an old savegame, it'll die, but if you start a new one, it works fine.

                            Bh
                            Last edited by Bhruic; November 9, 2005, 00:56.

                            Comment


                            • #44
                              Originally posted by Bhruic
                              Obviously the destination is the value of pPlot (or pUnit.pPlot()).
                              Actually, I'm about 99% sure pPlot is the original plot and pUnit.plot() the destination.

                              Alternatively, is there any event trigger that can be called before the unit is moved (but after the move order has been issued)?
                              No, we'll have to add that ourselves when the SDK comes out.
                              Administrator of WePlayCiv -- Civ5 Info Centre | Forum | Gallery

                              Comment


                              • #45
                                Originally posted by Locutus
                                Actually, I'm about 99% sure pPlot is the original plot and pUnit.plot() the destination.
                                I'd hate to argue with you, but I'm pretty sure it's not.

                                I did a popup that displayed the getX/getY values for both, and they were always identical.

                                Bh

                                Comment

                                Working...
                                X