View Full Version : Let's learn how to mod in civIV... Today!


Pages : 1 2 [3]

Gingerbread Man
Jan 12, 2006, 10:04 PM
Welcome to CFC, Noof and borzi!

borzi, could you post the syntax error you are getting here? Just so I can see what the problem is?

Thanks.

borzi_767
Jan 13, 2006, 12:10 AM
Np, I open calculator.py from the python shell, then i run the module and it gives me a syntax error. I have tried this with comments (copy n' pasted) and i have typed it myself when i run it i get this:

Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.

The whole program shows up of course but i get a syntax error on the '4' in Python 2.4.1

I have Tried deleting the whole top bit so only the program shows, then i get a syntax error on IDLE 1.'1'.1 I have tried it with only the program and NOTHING else and i get a syntax error on 'def'. What am I doing wrong?:cry: Also is there a way to turn what you program into an executable or something so that u can acces it without python? Thanks, Borzi

Scratch that how do u run ANYTHING u program in python!?!

EDIT: What Exactly are the levels of modding in Civ4? XML modding mods what and Python Modding mods what? When is the Civ 4 based tutorial coming out?

Morred
Jan 13, 2006, 01:56 AM
Hi there, I just downloaded Snaitf's Great General Mod, and for a Mod I am working on, I need to add new Great People. I had a look at Snaitf's python file, but I couldn't pick up what was changed, what would be necessary to add new great people? Thanks.

Gingerbread Man
Jan 13, 2006, 03:44 AM
Np, I open calculator.py from the python shell, then i run the module and it gives me a syntax error. I have tried this with comments (copy n' pasted) and i have typed it myself when i run it i get this:

Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.

The whole program shows up of course but i get a syntax error on the '4' in Python 2.4.1

I have Tried deleting the whole top bit so only the program shows, then i get a syntax error on IDLE 1.'1'.1 I have tried it with only the program and NOTHING else and i get a syntax error on 'def'. What am I doing wrong?:cry: Also is there a way to turn what you program into an executable or something so that u can acces it without python? Thanks, Borzi
looks like you are getting some wires crossed there. I'm assuming that you're opening a python file by just double clicking on it? What will happen, is that two windows will pop up - the code of the program itself in one window, and the output of the program in another. To start the program, go to the window where all the code of the program is, and press F5. It should be pretty simple, by the sound of it you've just got some things confused.

Hi there, I just downloaded Snaitf's Great General Mod, and for a Mod I am working on, I need to add new Great People. I had a look at Snaitf's python file, but I couldn't pick up what was changed, what would be necessary to add new great people? Thanks.
First, a new unit would have been added in the XML, and the changes in the python file simply figure out when a great general is spawned. You might want to ask the person who made the mod about how he did it.

Morred
Jan 13, 2006, 04:11 AM
I PMed him, no luck, I don't think it's been modified for 1.52 yet.

Thanks for the start though :)

borzi_767
Jan 13, 2006, 06:17 PM
Ok..... It worked, cool. I deleted every thing that wasnt code and ran the module and it worked (I was already cliking F5) Thanks. What eactly does python Edit?

Gingerbread Man
Jan 13, 2006, 09:20 PM
borzi: Idle, which is the thing that you opened up, edits python files (ones ending in .py). The file opens up in one window, and a shell (the thing with >>>) in the other.

borzi_767
Jan 15, 2006, 04:17 AM
Lol, I dont think I'm that dumb.... I meant what does python actually 'edit', for example what does it do in Civ4, and how does XML interact with things example being something in XML/python script could tell the comp to do what? Where would i find a good XML editor and tutorial? Thanks

stgelven
Jan 15, 2006, 05:23 AM
borzi: Idle, which is the thing that you opened up, edits python files (ones ending in .py). The file opens up in one window, and a shell (the thing with >>>) in the other.

G’day mate

you are not so drongo? aren't you?


There is a good XML and Phyton editor
http://www.context.cx/

you'll find tutorials in CFC.

(i'm learning aussie slang, tell me if i'm wrong (thx))

borzi_767
Jan 15, 2006, 11:55 PM
Merci, êtes-vous français par naissance ou vous êtes-vous déplacés là? Une chose cependant au sujet de votre argot, c'is:so vous ne sont pas un drongo?, pas: pas aussi drongo? n'êtes pas vous. Un drongo est une chose, donc vous vous référez à elle en tant qu'une. Merci pour le rédacteur de toute façon. Au cas où vous ne noteriez pas que j'apprends le français:)

I did cheat a bit though.....(I used google translate) But I am learning.

Cheers

Gingerbread Man
Jan 16, 2006, 12:28 AM
G’day mate

you are not so drongo? aren't you?


There is a good XML and Phyton editor
http://www.context.cx/

you'll find tutorials in CFC.

(i'm learning aussie slang, tell me if i'm wrong (thx))
G'day mate - most drop the 'mate' part, and just say G'day
Most wouldn't say drongo. Dipstick, drop-kick, maybe.

anyway, thanks for the heads-up on that link. Rather good. Much better than notepad ;)

stgelven
Jan 16, 2006, 02:02 AM
Merci, êtes-vous français par naissance ou vous êtes-vous déplacés là? Une chose cependant au sujet de votre argot, c'is:so vous ne sont pas un drongo?, pas: pas aussi drongo? n'êtes pas vous. Un drongo est une chose, donc vous vous référez à elle en tant qu'une. Merci pour le rédacteur de toute façon. Au cas où vous ne noteriez pas que j'apprends le français:)

I did cheat a bit though.....(I used google translate) But I am learning.

Cheers
i am french. thank you to correct me.
why are you learning french?
if you need some help in french, just pm me.


G'day mate - most drop the 'mate' part, and just say G'day
Most wouldn't say drongo. Dipstick, drop-kick, maybe.
Cheers

thanks for the lesson
just a question, is it unpolite to speak like that ?

did you try Context? i really like this editor, simple and can be used with so many languages...

borzi_767
Jan 16, 2006, 06:57 PM
Read the one below, the stupid comp double printed my message

borzi_767
Jan 16, 2006, 06:58 PM
It really depends on how you say it and in what situation, the way you said it to me was like a joke. When people call someone a drongo it is usually with a smile on their face.:) I'm learning French in school to let u know, your English is quite good but then again they teach you from a very young age dont they?

The Editor is gr8 thanks.!

Does anyone know how to program a boot program that runs something you want at startup?

G'day, Salut, Ciao, Sionara and Goodbye!:)

P.S: 'Mate' is the Australian term for friend, just like the Mexicans say 'Amigo', we say it a lot though ex: 'Don't worry about it mate' or 'How's it going mate?'

stgelven
Jan 17, 2006, 01:37 AM
I'm learning French in school to let u know


the best to know people is to leave with. But anyway, i'm pleased to know that aussies learn french. :D


your English is quite good but then again they teach you from a very young age dont they?


in france we start learning english at 11 y o not that much young.


Does anyone know how to program a boot program that runs something you want at startup?


at the startup of the computer you mean? before your os? which os have you got?

borzi_767
Jan 17, 2006, 01:58 AM
By reffering to a boot program i meant something that operates at startup so in a sense yes, but more like something that starts aftert my system has booted and is on the actual access screen. I am using Windows XP Proffesional (Madly awating Windows Vista in the 2nd half of :D :goodjob: :D ) And I would like to program something that starts after I have logged in to my comp and Windows has done the generic bbbrrriiinnnngggg wake up sound. How would I get my program to boot itself and run something else?(I'm trying to run a soun file: .wav in win media)

Cheers

P.S: I almost forgort the Aussie Slang lesson: One of the MOST used aussie slang words is: 'wanker', I dont think i really need to explain what it means or i'll get reported for a bad post(Check an online dictionary), but one of the most common sayings is: 'You wanker!' or 'What a Wanker' etc etc.... If you ever muster the courage to go to an aussie cricket game then you will see the culmination of 200 years of self developed slang. There might be a game on T.V although you can never really hear them chanting and you'd have to wait too long for something to happen.

P.P.S: Ah..... Almost forgot, you French extremely dislike the English, so u wouldn't really be caught dead watching a cricket game would you?.......

stgelven
Jan 17, 2006, 04:15 AM
if it's what i understood, it's really simple. just put your wave reader in the start up menu.

borzi_767
Jan 17, 2006, 04:38 AM
I think you misunderstood me just a little bit. I meant i wanted to program something via python or XML, dunno watever that would run a .wav music file at startup (.wav=Windows Audio Video file) Where exactly is the startup menu? And what text would i Hvae to program to make it run something else?

Also can some1 explain 2 me what the difference is between XML and Python script. What does each edit and how does what they edit interact with my comp/game??????:cry: :cry: :cry: :cry: :cry: :nuke: :nuke: :cry: :cry: :cry:

stgelven
Jan 17, 2006, 05:44 PM
I think you misunderstood me just a little bit.

my stupid!!! of course!!! too stupid! damn!!!

well it's clear you don't know what are xml and python.

http://en.wikipedia.org/wiki/XML


http://www.python.org/doc/Summary.html

Gingerbread Man
Jan 18, 2006, 12:28 AM
P.S: I almost forgort the Aussie Slang lesson: One of the MOST used aussie slang words is: 'wanker', I dont think i really need to explain what it means or i'll get reported for a bad post(Check an online dictionary), but one of the most common sayings is: 'You wanker!' or 'What a Wanker' etc etc.... If you ever muster the courage to go to an aussie cricket game then you will see the culmination of 200 years of self developed slang. There might be a game on T.V although you can never really hear them chanting and you'd have to wait too long for something to happen.
I'd be careful where you say that word. Go to its article in wikipedia (http://en.wikipedia.org/wiki/Wanker), and you will understand the sexual references behind it...

As for startup/shutdown events, you'd have to have your program run in the background from startup, and receive windows events. A different kettle of fish from what we're learning here (i.e. Aussie slang ;))

stgelven
Jan 18, 2006, 03:05 AM
I'd be careful where you say that word. Go to its article in wikipedia (http://en.wikipedia.org/wiki/Wanker), and you will understand the sexual references behind it...


in french we have the same expression, and the sexual reference is there to. "branleur"

kettle of fish i have to remember this one

borzi_767
Jan 18, 2006, 05:18 AM
Gingerbread has it right, exactly the reason I didn't want to quote the dictionary reference to the English version of "branleur". Although I might be able to incorporate branleur into my vocab. You never know when you might use it...;)

As to the Kettle of Fish, never heard the saying, understand the meaning. Good one though, gotta quote it sometime.

Thanks for the Wikipedia ref Stgelven. Does your name 'stgelven' mean something in French or is it just random type?

stgelven
Jan 18, 2006, 09:55 AM
Does your name 'stgelven' mean something in French or is it just random type?

"stgelven" is in fact "saint gelven", the name of a very little village in bretany (250 persons) where we lived in bretany 1 years and 6 month ago



Almost forgot, you French extremely dislike the English


why did you say that? i didn't know that frenchmen doesn't like english peoples.

borzi_767
Jan 18, 2006, 05:37 PM
Your right, probably not a lot of Frenh dislike the English but I heard that there was a sort if enmity between the 2 nations? SOmething about he English chopping off 2 the frenchmans fingers ages ago. Ah well, i wouldnt know, shoukld have asked when I was there shouldnt I!

stgelven
Jan 19, 2006, 02:36 AM
i never heard about any problem age ago. and be sure that french people don't dislike english people. infact there is not a people we dislike. :D

Pckering
Jan 19, 2006, 01:13 PM
Hiya all. I have been a Civ Fanatic since the beginning. I have never really gotten involved with the boards here or multiplayer because I just love to play. I download maps and read posts, get advice etc.

I am quite the moron when it comes to modding and would like to learn how. I have some really cool Ideas that I would love to see played out on CIV IV. I understand that Civ 4 is supposed to be a modders dream and that for the first time even I could possibly create a scenario or maybe even a completed mod pack.

I have enormous respect for all of you guys who have given your all to this game. Day after day coming up with new Ideas, mods, skins, maps, scenarios, etc. Because of you guys I can totally enjoy one of the main constants in my life since The CIV Franchise has been around.

I would like to attempt to give something back. I would like to learn how to create a scenario to offer up to others for their enjoyment. Unfortunatly My handicap strikes me... (the moron factor) I have read some of the Python tutorial and I kind of get it. Is there a hands on tutorial somewhere that will actually walk me through creating an actual scenario? I learn well by doing.

My final point is this even if I am never able to overcome my programming handicap (moronism LOL) I would like to at least share some of my Ideas with y'all so that maybe I could offer something back. I may not understand how to mod, but I do have some pretty neat Ideas, for some scenarios.

Anyway I want to thank y'all from the bottom of my heart for all of the work you have done for this Fantastic Game I have enjoyed it to no end.

borzi_767
Jan 19, 2006, 08:31 PM
Hello and Welcome Pckering,

This thread is about learning Python Script and troubleshooting when you come to a problem using it, Python is the third level of modding available to CIV users, the tiers being:1: World Builder, 2: XML editing 3: Python Editing and 4: The soon to be availiable SDK (Software Developers Kit) The whole ideas of all of these levels of modding is to give the player the ability to create something loosley based on Civilization. If you learn the tutorial and ask a few questions as you delve into trying to mod CIV then you should have no problems. Other Threads deal with learning XML script.

Gingerbread Man is in the process of creating a CIV based Python tutorial.

I don't know if we post ideas on this thread, so Gingerbread Man will have to answer that.

Howdy!

P.S: Don't worry about the moroninism, after a while it will wear off (I've still got the remnants of it)

Chris85
Jan 24, 2006, 10:48 AM
I was wondering around in the Civ4 Forums when I discovered this thread and it really gave me an interest to learn Python. I know QBasic, VisualBasic, C++, HTML, and XML. So far I find that Python is a versatile but simple language with an easy learning curve. I don't have Civ4 so don't expect any Civ4 mods from me anytime soon, but I can see why Firaxis decided use Python for the game.

I can't believe I didn't find this thread earlier, I appreciate the work you put into this Gingerbread Man! :thumbsup:

Pckering
Jan 24, 2006, 08:46 PM
THanks BOrzi.. I have found the manual for world builder and will start there. Then move on to the more difficult stuff. Like Python, XML, etc. Just giving you guys a warning I will be picking brains. LOL


Pickering

Gandhi
Jan 28, 2006, 04:10 PM
I know Python well, based on use outside of Civilization IV modding. However, I do not know how to actually use Python in Civilization IV. Is there a tutorial for a sort of "Hello, World!" program? What I mean is, though I know the syntax and semantics, where can I find out how to create and run the modifications?

I am sorry if this question has already been answered, but I have been searching through the stickies in this forum to no avail.

Bismarck II
Jan 28, 2006, 05:48 PM
Hey this looks good, I have Windows and found Python, did a few lessons, taught my computer how to "talk" to me....

>>>Hello="Have a nice day"

Considered that is far as I want to get, now about editing with Python, how do I do that?

stgelven
Jan 29, 2006, 03:31 AM
here is what you need :

http://forums.civfanatics.com/showthread.php?t=154130


now you have just to work and make good stuff for the civ community . lol ;)

jabot
Feb 01, 2006, 12:11 AM
Hello. I'm new here to this site and everything. I just got Civ 4 for Xmas and haven't even had that much time to play it. (I had to upgrade my computer to play and so didn't get to start till after the new semester began). Anyway, I'm pretty excited about the modding options even though I like many others I see here don't have almost any programming experience. I did basic years ago and I have done some very limited HTML. I guess I have a couple of soft questions to start off. 1) What exactly is the difference as far as modding goes between the XML stuff and the Python stuff? 2) Is there a separate thread for XML stuff related to Civ 4? 3) It looks like there is alot of info in the thread and all the new people ask for intro so I will try to look around myself but if there's anything in particular it would be good to know, I would appreciate the pointers. In that vein, at the beginning this thread looked more directly interactive with a kind of "teacher" "class" format, etc. Is that still how things are now, or is more like it's all been done, read for yourself and we're here to help and answer questions model? 4) I'm looking to go slow as I just started getting into the game, and I've got plenty of other stuff to keep me busy, so I'm not in a hurry with the modding though I might download something to try out. One question that may seem silly, but I just want to make sure that if I download some of these mod packs etc. that I am only adding something, not actually changing the core game I have installed? (I know that will be a possibility, I just want to make sure it's on my terms :)
Ok, thanks for any feedback!

borzi_767
Feb 02, 2006, 03:35 AM
Hey Jabot!:)

Welcome to the thread. In regards to your questions about XML and Python Stgelven posted Wikipedia shortcuts to the defenitions of both. They can be located on this page. There are seperate threads for XML editing. At the beggining of the thread there are links to Gingerbread Mans tutorial for Python. Although you would be better off going through the links on his posts as the tutorial and version of python it offers on the first post are now out of date. As of the moment the tutorial only covers python modding in general while gingerbread man is working on a CIV based tutorial of it.

When you download a mod it needs no installing and changes no system files. Most good mods will contain readme's on how to place the included files but after a while you will learn what to do. When we edit Python and XML script we simply copy the CIV files we want to edit and edit them as something seperate. They do NOT replace normal CIV files. I'm not sure exactly how the next step functions so you will have to ask a more experienced person on the matter, but what I think happens is that you package your mod and place it in the MOD section of the CIV files. When you next run CIV you can go into the menu:

Main Menu>>>Advanced>>>>Load Mod>>>> (Example Mod)

If you have done it correctly CIV will restart and load the changed files so it plays differently. If you read the post I welcomed pckering with it explains the levels of modding available and what you will be able to do eventually. But for now, my fingers hurt so I'm going to say:
Welcome to the Club

P.S: When I got the game my computer wouldn't run it correctly either but after installing the patch which was specifically designed for lower spec comps i was able to run it correctly. (I have a 32mb graphics gard, what was yours? And what wasnt supported?)

I hope I didn't miss any of your questions!!!! If so tell me!!!!!

jabot
Feb 03, 2006, 03:21 AM
Thanks for the reply Borzi. :) I've started to find my way around the forums more now. I think I realized it's probably better for me to start of with the simpler level of modding at this point and then work up to the python if I'm able! It's pretty amazing all the things that people are doing! Thanks again and see you around!

matthewv
Feb 04, 2006, 02:16 AM
@ borzi
If you want a mod to runs every time you load civ without having to choose load a MOD in civ there is also a customassests folder under mygames/Civilization4. When you runs civ4 in will as a first proriety use any of the files that are in this folder and if it cant find the file it will use the defalt file loacated in the assets folder where you installed civ. When you mod civ4 the typical aproach is to make a copy of the file you want to cange and then place it in the appropriate place in the custom assets folder. Then you can easily change the new file.

Shqype
Feb 10, 2006, 10:08 AM
Gingerbread Man, I read post number 120 (lesson 6) about dictionaries, which The Great Apple was helpful enough to direct me to.

My next question is: how do you assign multiple values to the same key? In the phone book example, is it possible to give each entry multiple phone numbers? And is it possible to give each key multiple values of different types? For example, let's say I wanted to give each member of the phone book 3 phone numbers, plus the names of 2 emergency contacts. If this can be done, how can it be done?

vbraun
Feb 10, 2006, 05:56 PM
Have the key assigned a list.

d = {'key': ['list1','list2','list3']}

d['key'][1] would return 'list2'. :)

Shqype
Feb 11, 2006, 12:22 AM
Thanks vbraun, that helps. :)

vbraun
Feb 11, 2006, 12:50 AM
And don't be afraid to stop there, you can nest dictionaries, lists, and tuples as far as you want. The more you have, the more confusing it could get.

Gingerbread Man
Feb 16, 2006, 02:59 AM
Hi all!

Welcome to all the new posters here, and thank you to all those who answered their questions.

Again, Real-Life time constraints restrict me from doing the modding/writing about modding that I would like to do. I don't have any predicted time in which I may release any more material, but needless to say I haven't forgotten about it all, and I do intend to (eventually) recommence contributing to the modding community.

Thanks for your patience.

Sto
Feb 22, 2006, 11:35 PM
Hello!

I try to import tkinter in my script but that doen't work !

In PythonDbg.log there is: EntryPoint module:tkinter
but no : load_module tkinter

Is there a way to import tkinter in civ IV ?

Tcho !

mikezang
Mar 23, 2006, 07:13 PM
Do you have DOC or PDF format files for this lessons?

HP_Ganesha
Apr 15, 2006, 07:53 AM
wow... you do a realy good work here... hey man you are my hero!!!... I can translate this tutorial to Portuguese??? My "contarreaneos" need learn about this... tks!!!

babakahmadi
Apr 23, 2006, 12:19 PM
Tanx much -- I'm an old programmer with little patience for reading wiki or manuals -- this was a great intro and I'm off and running. Tanx again

Eusebius
Jul 04, 2006, 08:11 PM
Hi; I have a module which gets imported into CvGameUtils.py. The module defines a new class and declares some global variables of that class. However, in the cannotConstruct method of CvGameUtils, the global is not properly initialized the first time it is accessed. What's up?

Thanks,
Eusebius

Eusebius
Jul 04, 2006, 08:25 PM
Hi; I'm working on my world religions mod and ran into an odd case of inheritance not working as I expect it to. {Doubtless because I am a Python newbie.} I think that the following code ought to work purely through inheritance, but instead I had to overload the method name 'getSpreadFactor'. Can anyone set me straight?

foo = ewrReligionInfo(1)
bar = foo.getSpreadFactor()

Thanks,
Eusebius

PS. Mod forum is http://forums.civfanatics.com/showthread.php?p=3950103


class ewrReligionInfo(CvReligionInfo):
def __init__(self, iReligionIndex):
self.parent = CvReligionInfo
self.parent.__init__(self)
self.iReligionID = iReligionIndex
self.CvReligionInfo = CvReligionInfo
self.iTempleID = gc.getInfoTypeForString('BUILDING_TP_PAGAN_TEMPLE' )
self.iMonasteryID = -1
self.iCathedralID = -1
self.iShrineID = -1
self.iMissionaryID = -1
self.iFoundingID = -1
self.bSingleCiv = False
self.bIsWorldview = True
self.bAdvancedPaganism = False
self.bHatesIdols = False
self.bHasIdols = False
self.bHasMovie = False
if (iReligionIndex >= 0):
self.CvReligionInfo = gc.getReligionInfo(iReligionIndex)
<code...>


################################################## ####################
# I can't figure out why these shouldn't work through inheritance,
# but it always returns zero if I don't do it this way.
################################################## ####################
def getSpreadFactor(self):
return self.CvReligionInfo.getSpreadFactor()

Civkid1991
Jul 27, 2006, 05:52 PM
i've looked at your first 4 lessons and i think they're great! I was wondering though is there going to be a lesson on drawing using python(or maybe functions that are related to makeing graphics or placing them on the screen) . I know its a bit advanced but i would like to see a lesson on this in the near future.

Civkid1991
Aug 03, 2006, 06:50 PM
Just wondering... Is this thread still alive???

Gingerbread Man
Aug 04, 2006, 01:27 AM
Just wondering... Is this thread still alive??? Not really... I don't have much time in my life to play around with python anymore.

Norseman2
Aug 05, 2006, 05:24 AM
After I read up to lesson four, I tried to make a small program, but I got a syntax error. Can anyone tell me where I screwed up? Edit, see below.

#Eat twinkies, pal!

NumberOfTwinkies = 10


while twinkies >= 0
print "We still have", NumberOfTwinkies, "twinkies! Must devour!"
NumberOfTwinkies = NumberOfTwinkies -1
print "Munch!"
if NumberOfTwinkies == 1
print "Oh no, the last twinkie!"
NumberOfTwinkies = NumberOfTwinkies - 1
print "Must... devour... last... twinkie!!! Munch!"

Edit: Ok, I think I found the first problem. When Gingerbreadman used multiple prints in the same line, he put a + before them. I've now done the same, but I'm still getting a syntax error.

#Eat twinkies, pal!

NumberOfTwinkies = 10


while twinkies >= 0
print "We still have", + NumberOfTwinkies, + "twinkies! Must devour!"
NumberOfTwinkies = NumberOfTwinkies -1
print "Munch!"
if NumberOfTwinkies == 1
print "Oh no, the last twinkie!"
NumberOfTwinkies = NumberOfTwinkies - 1
print "Must... devour... last... twinkie!!! Munch!"


Another edit, oh boy. When I switched from twinkies to NumberOfTwinkies as my variable, I forgot to make the while thing switch too. I've fixed that now as well, but I'm still getting a syntax error. I must have screwed up royally on this little peice of code.

#Eat twinkies, pal!

NumberOfTwinkies = 10


while NumberOfTwinkies >= 0
print "We still have", + NumberOfTwinkies, + "twinkies! Must devour!"
NumberOfTwinkies = NumberOfTwinkies -1
print "Munch!"
if NumberOfTwinkies == 1
print "Oh no, the last twinkie!"
NumberOfTwinkies = NumberOfTwinkies - 1
print "Must... devour... last... twinkie!!! Munch!"

Gingerbread Man
Aug 05, 2006, 06:45 AM
Lets see if I can help... Here's my take on it:
NumberOfTwinkies = 10


while NumberOfTwinkies > 0:
if NumberOfTwinkies == 1:
print &quot;Oh no, the last twinkie!&quot;
print &quot;Must... devour... last... twinkie!!! Munch!&quot;
else:
print &quot;We still have&quot;, NumberOfTwinkies, &quot;twinkies! Must devour!&quot;
print &quot;Munch!&quot;
NumberOfTwinkies = NumberOfTwinkies -1 There were a few issues:

The way you structured the program was a bit confused. Try writing out what each line of code will do in plain english first, if that helps. For example, I approached it this way:
While there's twinkies left:
If its the last twinkie:
Print the &quot;Oh noes&quot; message
otherwise:
print the normal message
take away one twinkie
You need to put colons at the end of if, else and while statements. It pretty much works like this:

if this happens:
Do this
else:
Do this
while this is true:
Do this
Where you had the following:
print &quot;We still have&quot;, + NumberOfTwinkies, + &quot;twinkies! Must devour!&quot; you were confusing a couple of things. First of all, you don't need a comma and a plus sign. One or the other. Second thing, you can only use the plus sign when all of the things you are adding or joining are of the same type, e.g. adding a string to a string, adding a number to a number. Think of a comma as indicating yet another print statement, but putting it on the same line as the previous one.

Norseman2
Aug 05, 2006, 07:04 AM
Thank you! Ok, you did say to put colons after ifs and elses, so that was just me being stupid. However, I didn't see anything about how to use + and commas in the section where you used them. I would suggest putting something there about it, or linking to a later article if you do explain that somewhere. Edit: After looking around, I noted a few places where you did say that, that I had already read. You should make a bigger point of that when you use it in an example though.) Once I did both of those, I got:

#Eat twinkies, pal!

NumberOfTwinkies = 10


while NumberOfTwinkies > 0:
print "We still have", NumberOfTwinkies, "twinkies! Must devour!"
NumberOfTwinkies = NumberOfTwinkies -1
print "Munch!"
if NumberOfTwinkies == 1:
print "Oh no, the last twinkie!"
NumberOfTwinkies = NumberOfTwinkies - 1
print "Must... devour... last... twinkie!!! Munch!"

We still have 10 twinkies! Must devour!
Munch!
We still have 9 twinkies! Must devour!
Munch!
We still have 8 twinkies! Must devour!
Munch!
We still have 7 twinkies! Must devour!
Munch!
We still have 6 twinkies! Must devour!
Munch!
We still have 5 twinkies! Must devour!
Munch!
We still have 4 twinkies! Must devour!
Munch!
We still have 3 twinkies! Must devour!
Munch!
We still have 2 twinkies! Must devour!
Munch!
Oh no, the last twinkie!
Must... devour... last... twinkie!!! Munch!


:D

You were also right about using the greater than, instead of greater than or equal to (it went to "0 twinkies left, must devour!"). It wasn't a syntax problem though (just me being stupid), so at least it would have worked enough for me to see the problem and fix it.

And now I can get a program to do 99 bottles of beer on the wall. :)

Gingerbread Man
Aug 05, 2006, 07:27 AM
Glad I could help :)

When I next have free time in my life (possibly never), I might get around to updating my website. I've currently put it on my own server which I have full control over, so there's quite a lot more I can do.

Norseman2
Aug 07, 2006, 10:24 AM
Ok, one more quick question. I'm trying to use the read/write stuff from lesson 10. Here's the code I wrote:

#Readwrite.py
#Attempting to read Rw.txt (doc), add "This is a string", then read it again
#to confirm that it was added
doc = open('C:\Documents and Settings\Dimitri\Desktop\Rw.txt', 'r+')
print doc.read()
doc.write('This is a string')
print doc.read()
doc.close()


When I ran it I got:

>>>
If you can read this you have found Rw.txt

Traceback (most recent call last):
File "C:/Program Files/Python 2.3.4/test", line 6, in -toplevel-
doc.write ('This is a string')
IOError: (0, 'Error')

I know I screwed up with writing, but I don't know what to do to make it work.

Edit: Ok, someone else spotted some syntax errors for me, so I corrected that. I'm still getting the same error though.

ggganz
Aug 09, 2006, 06:23 PM
I'm not sure if this counts as modding, but...
How do all the people that do unit reskins do it? Where are the .dds files? I have a converter and and have reskinned one (http://forums.civfanatics.com/showthread.php?t=181018) that I found, but that's the only one! WHERE ARE THEY???

Gingerbread Man
Aug 09, 2006, 10:09 PM
ggganz - Hmm, I only really know about python programming, and even then, I'm only really useful for beginners. Maybe try asking somebody else?

ggganz
Aug 11, 2006, 06:46 PM
There is more than one person answering questions, right?

Gingerbread Man
Aug 12, 2006, 04:11 AM
ggganz - on this thread, there's only me, and maybe a couple of other pythoneers. I'm sure there's plenty of graphics experts who will be able to help you, in another thread.

ggganz
Aug 12, 2006, 10:49 PM
I have already PMed two people that I know that reskinned some units I liked, Feanor and bhiita. Deleting subscription for this thread.

ooo6ooo
Aug 18, 2006, 09:47 AM
One question, HOW can I immediately see the changes of the python files in game without restarting it? thx

Eusebius
Aug 18, 2006, 01:12 PM
One question, HOW can I immediately see the changes of the python files in game without restarting it? thx

It already happens that way. I often have an editor window open, make a change, save and ALT-Tab back to Civ 4. There is a debug message that says "Reloading python modules..." and the results are there immediately.

If you do this too often, your environment can get corrupted, so it pays to restart from time to time especially if you start to see really weird stuff.

Eusebius

Gingerbread Man
Aug 19, 2006, 03:05 AM
Thankyou Eusebius! I vaguely remember that to be the case, and you've very right.

I really need to get back into this.

ilovecurrry
Aug 19, 2006, 07:04 PM
youve lost me...

proconsul
Sep 15, 2006, 05:00 AM
This is a bit off civ4 but Oblivion uses the same principles and tools so the fix is likely to be the same. I've added a new anim to the game of a violinist playing his instrument. The anim plays fine however I need to somehow tack the end of the violin which is a seperate item to the bipeds left hand so that when the animation plays the violin tacks to the hand and moves with the body. At the moment the violin hangs in the air and stays still. The biped is a kf file, the violin a nif.

Grey Fox
Sep 15, 2006, 06:59 AM
This is a bit off civ4 but Oblivion uses the same principles and tools so the fix is likely to be the same. I've added a new anim to the game of a violinist playing his instrument. The anim plays fine however I need to somehow tack the end of the violin which is a seperate item to the bipeds left hand so that when the animation plays the violin tacks to the hand and moves with the body. At the moment the violin hangs in the air and stays still. The biped is a kf file, the violin a nif.

This thread is only about Python Programming. You should start a new thread in the Customization forum or find another thread to ask your question.

REJS7
Sep 17, 2006, 05:31 PM
I have used your tutorials, and they all come up smelling of roses :). I must add that they are a lot more clear than some that I have come across.

Levon
Oct 11, 2006, 02:28 PM
Thank you. I really wanted to learn how to make mods in Civ IV and now I can make my own civilizations.:)

HulaLoula
Nov 17, 2006, 01:42 PM
I recently downloaded thelopez's cultural influence MOD and improved civics Mod.Problem is I don't know how to run both simultaneously.I go to the config. screen and change Mods=0 to Mods\cultural influence.How do I add additional mods in that screen?Thank you to whomever could help me here.

Mereik
Nov 17, 2006, 07:45 PM
Thank you. I really wanted to learn how to make mods in Civ IV and now I can make my own civilizations.:)

are you armenian????????

Mereik
Nov 17, 2006, 07:45 PM
oh and can anyone here tell me where to put the files after you download a mod?

Ikael
Dec 07, 2006, 05:16 AM
Hi guys! I am new to the modding scene, even if I edited the .txt files in civ 2 and used the civilization 3 editor extensively, I am finding that this is the hardest civ to mode ever.

I have tried to open the .xml files with a XML editor, and it says that "the XML entry can't be readed with the XSL style sheet". I have tried it to open it with python and it is useless. I have tried to open the .xml files with the txt and it is a mess, same with the Dreamweaver MX. The only program that seemed to open it "properly" was Excel. However, once I saved the modified documents and tried to run the mod, it gave me an error.

Does anyone here knows how am I suppoused to edit them?

Gingerbread Man
Dec 07, 2006, 06:31 AM
Hi guys! I am new to the modding scene, even if I edited the .txt files in civ 2 and used the civilization 3 editor extensively, I am finding that this is the hardest civ to mode ever.

I have tried to open the .xml files with a XML editor, and it says that "the XML entry can't be readed with the XSL style sheet". I have tried it to open it with python and it is useless. I have tried to open the .xml files with the txt and it is a mess, same with the Dreamweaver MX. The only program that seemed to open it "properly" was Excel. However, once I saved the modified documents and tried to run the mod, it gave me an error.

Does anyone here knows how am I suppoused to edit them?
If you're daring: notepad.
There was also rather recently an XML or technology tree or whatever editor released recently. Check the last few weekly mod summaries posted on the main page.

Eusebius
Dec 07, 2006, 09:20 AM
Hi guys! I am new to the modding scene, even if I edited the .txt files in civ 2 and used the civilization 3 editor extensively, I am finding that this is the hardest civ to mode ever.

I have tried to open the .xml files with a XML editor, and it says that "the XML entry can't be readed with the XSL style sheet". I have tried it to open it with python and it is useless. I have tried to open the .xml files with the txt and it is a mess, same with the Dreamweaver MX. The only program that seemed to open it "properly" was Excel. However, once I saved the modified documents and tried to run the mod, it gave me an error.

Does anyone here knows how am I suppoused to edit them?

Any text editor will do. I think the style thing works better if you copy the entire XML tree--which is against the point of modding only the files you need! I use Context (www.context.cx (http://www.context.cx)) a freeware editor for almost all of my editing. I occasionally use the free version of XMLSpy because it will do syntax checking.

Eusebius

tonyf12
Dec 17, 2006, 01:08 PM
i know a little HTML because i made websites but mostly i used frontpage and dreamweaver, would it be difficult to learn how to mod.

Gingerbread Man
Dec 17, 2006, 04:38 PM
i know a little HTML because i made websites but mostly i used frontpage and dreamweaver, would it be difficult to learn how to mod.
Python is a really accessible language, so hopefully that aspect of modding shouldn't be too difficult for you.

As for graphics and SDK editing, well, that you'd have to ask people who know more of it.

Anthropoid
Feb 02, 2007, 09:50 PM
Hey fellas, I got a fairly simple question. I'd like to act as "host" for a Civ4 PBEM for some buddies. What I'd like to do is:

1. Generate a random multiplayer map with the settings they want, and their names for the tribe leaders (4 human, 5 AI, Large map)

2. Then open the file in the Worldbuilder as the admin, and make sure nobody is getting hosed on their starting location, as well as add one settler and one worker to all the human players locations.

3. Save the file, send it to the player 1, and off they go!

I've tried generating a single player map, but when I generate it with the difficulty level they want to play the AI at (Warlord) the map is entirely unbalanced for all the 2nd through 9th positions. I have managed to make changes to this initial random SP file, save it in the Public Maps, then open it as a Scenario in the MP games startup, but then the player one fellow has a huge advantage cause his starting location is so much better than the other guys.

Maybe a jury-rigged fix would be to generate the map on Noble or Prince difficulty, and then maybe all the "AI" players would have relatively better starting locations?

Anthropoid
Feb 03, 2007, 03:40 PM
One thing a buddy and I have figured out is that it is possible to play a game as an online (non-simultaneous turns) match, then to open it up as a PBEM, and resume playing it as a PBEM! It seems that, the next human following the host of the original online game must open the final .save from the online game in order for it to get going properly.

My buddy hosted it, he was France, I was America. We played (with 2 AI on a small map) up to about 225 BC. We both saved it. When he opened either his or my .sav file, it opened to Americans, and same thing for me. When I opened it as a PBEM, then saved it to my PBEM folder and sent it to him, it worked properly for him! opened for him as France, he played his turn, sent it back to me it opened as Americans, I played my turn, sent it back to him and it opened fine for him.

Only problem is, it did not ask for passwords after we changed it to a PBEM from an online match.

Gordon Farrell
Mar 15, 2007, 02:46 PM
I am currently using your superb tutorial to teach myself Python, GB Man! This self-help tool really is an extraordinary accomplishment + a great gift to the gaming community. Thanks a million!

woodelf
Apr 11, 2007, 07:30 AM
This is a super beginner tutorial GBM. Combined with TGA's CivIV specific tutorial I've learned a ton. :thumbsup:

netrom
Apr 17, 2007, 10:11 PM
I dont know if im posting this in the right thread, but I need some assistance.

I have downloaded so many mods, yet only about at third of them work. I have installed them exactly as instructed. The game begins to restart when i go to load the mod, but about half way through starting up I get various error messages and it shuts down.

Can someone please help?

Thanks
Netrom

White Elk
Jun 24, 2007, 08:45 PM
Thank you very much for this tutorial Gingerbread Man!! Thanks to you I have written my first Python program. Its been over twenty years since I have dabbled in programming (very simple BASIC programs in high school). Thanks to you I have finally taken my first step into Python programing. It was both easier and more difficult than I had imagined. The simple program below took me hours to write. And I couldn't do everything I had wanted to do with it.

But I had fun and look forward to learning more. http://i22.photobucket.com/albums/b318/WhiteElk/yltype.gif

Knock Knock... v2
http://i22.photobucket.com/albums/b318/WhiteElk/misc/tyv2.jpghmmm The program runs as intended from the GUI.
But from Command Line it exits before displaying the final print line??

marthinwurer
Jul 29, 2007, 05:51 PM
id like to join. i have minor experiance with basic

oioisamarai
Aug 01, 2007, 03:25 AM
I'll have a go although I'm a bit older than most/all of you. Started my IT career in 78. Mostly RPG (no, not role playing games) and don't regard HTML as a language at all 'cos it's too easy. Mostly HLL so Python will be a learning experience.

T_F
Aug 15, 2007, 12:23 PM
I tried the first one, but encountered a problem. When you say to type 'python -V' on the command line, I do that and get this message:
NameError: name 'python' is not defined

Zhuge_Liang
Sep 23, 2007, 10:05 AM
Include me. I had just read your posts and I tried it........ It's awesome!!!!

jcfire236
Oct 17, 2007, 01:31 AM
im in...i had some C++ in high school as well as a little bit of HTML

Soneji
Oct 23, 2007, 06:04 AM
Whats everyone in for?

Is this a gang? :D

I done a year or so of C, then C++. Little bit of basic, and cobal. Touch of mark up.

Never tried this though...

Edit: Looked at the python, looks quite nice high level to me! So.. where are the lessons about actually starting to learn how to MOD... (not code!) ;p

cfkane
Dec 08, 2007, 04:59 PM
Is it possible to combine mods? For example, I was going to make a custom mod that combines ActualQuotes, Dynamic Civ Names and Varietas. Could I just throw all the files into the same mod folder or is it more complicated than that?

black baron
Mar 30, 2008, 12:37 AM
i need help i made it so that i could view the python in note pad now i cant use any civics in civ4

leoncalvin
Jul 16, 2008, 03:32 PM
I am serious distress here. I don't know where to start with this (XML or Python?) I am trying to make each of my civs have their own tech trees. Each with it's own techs and requirements. What kind of python would I use or do I need to work this into XML? (or SDK- don't have any knowledge of SDK at all).

black baron
Jul 17, 2008, 04:42 AM
both xml will allow you to say what it does or is and python will effect how the tech,civ,civic,ect. will work as for sdk i don't know(idk) and don't forget about c++(i still don't know about that)

leoncalvin
Jul 17, 2008, 07:41 AM
HEy I figured it out. All i have to do is merge a mod by classic thuinder that does exactly this using python. Then all I have to do is specify which chanel each civ can research in.

Thanks! :)