How to make a Python mod

Yeah, and this thread isn't going anywhere (I hope).

Actually, while I wrote the tutorial with your request in mind - others will have just as much use for it as you would have. So I don't consider the full days work any kind of waste of my time, so please don't feel bad.

But I will stop harassing you now. I will also stop answering questions which I've already answered... Because I would only refer you to this tutorial anyway. :rolleyes:
 
The core of the problem with helping people who don't know what they are doing, is that you really need to do the work for them. Because this will save time for everyone, including yourself. Of course it means that the modder misses out on an opportunity to learn, but so be it. Results also count.

Like, if others had helped you by giving you random advice on how to build the Rebels mod yourself, it would surely never have been finished. And once someone else (probably me :rolleyes:) stepped in and did it for you, the collective waste of time for this community would already have been in the hundreds of unpaid work hours (mostly of your precious time, of course). Hopefully there would have been some valuable lessons along the way, but those would have been costly indeed!

Seriously, it took like 45 minutes to come up with the basic code since I already basically knew what to do. (A professional programmer would have done it on a coffee-break, for sure.) So the testing took a couple of hours - and writing the tutorial to match and develop the code for this purpose took probably a whole day.

So it helps to know some basic skills before you start, otherwise these projects will drag on for weeks and months. And you might still never get it right, as you would be missing some key information. I just can't see how it would be worth it. Not for me anyway.

But enough with the ranting already. :p
 
I am struggling with getting that boxed centered in the main screen. I have tried for the last couple of hours, mostly guessing on this.

How about another clue?
Sure, but I'm guessing you never read the tutorial then? Because there is no reason to fumble around at random, especially if you have several hours to to spare.

Code:
modPopup.setHeaderString("Tutorial")
modPopup.setBodyString("This is a Python tutorial.\n\nby Baldyr")
These are two examples of method invocation.

The PyPopup instance we're referencing with the modPopup variable has "methods" defined in its class, and we call on them with dot notation. This is a common practice in both regular and CivIV Python, and it entails putting an object (like an instance of a class - like PyPopup) first, followed by a dot, and lastly we add the method name. (In this case the names pretty much tell what they will do for the Popup.) Inside the parenthesis you put parameters, and in this case these are string values.
So the PyPopup.setPosition() method is no different than the PyPopup.setHeaderString() and the PyPopup.setBodyString() methods. So you do the same thing, just add one line of code but replace the method with another.

What differs is the parameters you feed into the method. With setHeaderString() and setBodyString() you entered a string value, right? Well, as I explained in my earlier post the setPosition() method takes two parameters. (You need to separate them with a comma.) Those would be the actual coordinates - iX and iY. But you can't enter variables called iX and iY - unless you define them first. You can just use the integer values of your coordinates directly.

I realize this is alien at first, but please do give it another try. This should actually be a good learning experience.

Also, you realize that you don't have to restart the game every time you wanna test the showPopup() function? Use the Python console and import the Rebels module after each time you save it. Then use a function call:
Code:
import Rebels
Rebels.showPopup()
 
You thought wrong, but that is OK it's often hard to teach someone something new without assuming they aren't trying.

I followed through the tutorial many times, changing what I think should be done, but either the window looked the same or it never spawned.

It is probably very easy, but I just don't know the syntax. It would be cool to have the window centered but I guess where it is at is OK.

This is one of the lines I tried to add, to no avail:

"""Displays the welcome message on game start"""
modPopup = PyPopup()
modPopup.setPosition(self, i50, i200)
modPopup.setHeaderString(popupHeader)
modPopup.setBodyString(popupMessage)
modPopup.launch()

Edit -- Actually I didn't realize I could do that. Fantastic! I was getting tired of reloading the game over, and over, and over, and over. . . .
 
You thought wrong, but that is OK it's often hard to teach someone something new without assuming they aren't trying.

I followed through the tutorial many times, changing what I think should be done, but either the window looked the same or it never spawned.

It is probably very easy, but I just don't know the syntax. It would be cool to have the window centered but I guess where it is at is OK.

This is one of the lines I tried to add, to no avail:

"""Displays the welcome message on game start"""
modPopup = PyPopup()
modPopup.setPosition(self, i50, i200)
modPopup.setHeaderString(popupHeader)
modPopup.setBodyString(popupMessage)
modPopup.launch()

Edit -- Actually I didn't realize I could do that. Fantastic! I was getting tired of reloading the game over, and over, and over, and over. . . .

OK, I'm not really a python expert, but i50 and i200 aren't actually integers as far as I know. Not even sure if you can define a value for them...
So you don't need to put that i in front of them. i, b, p, f etc. are used with python when we have a string that we assing a value so we remember what it is.
Also when you start playing with python it's usually good to enable python exeption. Go to your CivilizationIV.ini file in my games and change this:
Code:
; Set to 1 for no python exception popups
HidePythonExceptions = 1
to this:
Code:
; Set to 1 for no python exception popups
HidePythonExceptions = [B]0[/B]
or atleast enable python logging.

And awesome work Baldyr! :goodjob: I wish I had this tutorial when I started to edit python. :D
 
Yes, he is a super-duper dude. I am lucky to have someone so patient with me, because it is very hard for me to learn anything (I dread going back to school this fall).

I tried it a couple of times without the "i" and put in some wild numbers, but no change :mad: According to the Python logging, I have to somehow define the self in the syntax. :cry:

I also turned on the python logging -- it really shows all the little errors in the game. Very interesting for testing purposes.
 
There is something you've overlooked in this post. Also, integer values are basically numbers (like 1) - but not floating point numbers (like 1.0).

Since you are clearly trying :goodjob: I feel that I have to apologize. Sorry for assuming you didn't even wanna learn. Now I know better.

Actually I can't blame you for not figuring this particular problem out, since it involves Object-Oriented Programming - the more advanced style of programming. So this is probably not any kind of entry-point for getting into Python. (Changing any of my own functions would probably be that much easier, like the conditions for the actual event, or some parameter involving the units spawned.)

The solutions is actually:
Spoiler :
Code:
modPopup.setPosition(50, 200)
Because the self part refers to the class instance (modPopup, which points to a PyPopup instance) so we don't enter that as a parameter. And the integer values should speak for themselves.
 
wow that is too easy.

I knew it was something very straight forward -- I can't wait until I can get home and try it. I may have to play with the numbers because I have no idea what the center of the screen really is (i just fed in some numbers). Is the X and Y coordinates based on any particular point on the pop-up window (center, upper left, upper right)?


Also, assuming I can get that done, will that work for different resolutions? I have several testers that run the game at much lower resolutions than what I have the game set on? Perhaps that is for an advance learning tutorial -- I remember seeing some python code that actually fetched the values of the current screen size and that may be the clue I need to solve this new riddle.
 
I would actually know nothing about the coordinates of the game interface (because that would be very CivIV specific and not covered in any textbook), but I do believe that you are on to something. :goodjob:

Also, look in the API under classes like CyGInterfaceScreen (or something cryptic like that) for methods to fetch the values for the actual screen size.

Remember that in order to use any class method (like those in the API) you need a class instance to invoke it on. So look for one in your code, or CyMakeOne(). That last bit was a whimsical example of a class constructor which crates an instance of a class.
 
What about CyGInterfaceScreen.getXResolution() and CyGInterfaceScreen.getYResolution()?

Just like in the tutorial, you look these entries up in the API. First of all: What kind of values do these methods return? Secondly: What parameters (if any) do they take?

Once you have your X and Y coordinates for the screen, you need to assign them to a pair of variables. Then apply some math to them, to get the desired coordinates for the popup (you need integer values, by the way). Then you use these adjusted variables as the parameters in the Popup.setPosition() method.

I haven't tried this myself, but at least it sounds logical to me. :D
 
I didn't have allot of time to work with the mod last night because I hosted a Lan Party for some friends (we were testing the last beta release before Extreme goes live hopefully this Friday), but the box now does move around!

I hope to add code to center it on any screen resolution, but may just settle for it to be somewhere around the center of the screen.

Edit: Went to the library today and picking up some simple Python textbooks (I am old school I guess in that I like a book to study from rather than all the online stuff; yeah I know its weird).
 
I hope to add code to center it on any screen resolution, but may just settle for it to be somewhere around the center of the screen.
The way to center it is probably to first find a method for setting the size of the popup, which you would find in the Popup module. (I haven't checked, but I'm rather assuming this.)

So you get the width of the screen - iScreenWidth - and you set the width of the popup - iPopupWidth - and the you subtract iPopupWidth from iScreenWidth - and divide the reminder with 2. That should be center screen by the power of math.
Code:
iXCoord = (iScreenWidth - iPopupWidth) / 2
You know math, right?
Edit: Went to the library today and picking up some simple Python textbooks (I am old school I guess in that I like a book to study from rather than all the online stuff; yeah I know its weird).
Good for you! Otherwise the textbook I was referring to is also available in PDF if you wanna print it out - or as an actual textbook for purchase online (I believe). But any textbook should be able to teach you the basics - because thats what you need.

But don't shy away from Object-Oriented Programming once you get to that hurdle. Learning the basics of that will give you in-depth understanding of how the game works - and how you go about modding it. Then all the options will be readily available to you.
 
Programming is basically applied mathematics. Because the computer knows nothing else than how to do computation (duh).
 
I was joking, of course, but mathematics was never my strong point.

It is fun to experiment with this and the more I research about Python, it isn't simply a language used in games but as applications throughout the world in all markets.

As I learn this for Civilization IV, I am improving my skills for other applications and uses too.

Does anyone know if Civ V uses python as well, or is there a different method of modding?
 
Lua is just another scripting language, I dunno if its a "high-level" language like Python, but it does seem somewhat simplified in comparison. (The similarities are probably grater than the differences.) As in easier to learn and less to know about, but at the same time you lose some precision and probably also performance.

But it could be better for modding than Python, for all I know...

And I'm not looking to get into CivV modding myself. Or the game for that matter...
 
Top Bottom