Modding help

fattythefat

Chieftain
Joined
Feb 4, 2010
Messages
39
Anybody know some superb guide on how to learn to mod? I would really want to learn to mod. Know this aint the perfect forum for this thread, but i especially want to learn how to mod stability and spawn dates and such... It would be great if somebody could post a link or two:)
 
Well there aren't any tutorials specifically for modding RFC or for replicating its features as far as I know. I think your best bet, assuming you're starting from scratch, would be to read a general introduction to Python syntax and then dive right in and see if you can figure out Rhye's code. I find learning by doing is always better when it comes to programming.
 
Yeah, you should learn a programming language, and continue from there. Python would be a very good place to start. :D

I've found that this is a great start for basically learning the all there is to know. Its a textbook and not in any way CivIV specific, but most of the stuff still apply. Also, the CivIV API will start to make a whole lot of sense if you know Object-Oriented Programming, as it's called. Here's another beginners guide.

Once you know Python you can move up to C++ and actually modify the DLL file. This is a step I'm yet to take myself, as I'm still learning Python.
 
Thanks! Ill start reading now :)

EDIT: how do i create a python file?

Edit2: Downloaded a Python 3.1.2. In the guide it says that i shall type this:
print "Hello, World!"

and this should come out:
Hello, World!
But when i press enter the last " glows red and it says synthax error... what am i doing wrong?
 
Thanks! Ill start reading now :)
Good for you! :goodjob: It will take some time and effort, but it will be worth it in the end. Don't get bogged down but try to get through the textbook - there will be those eureka! moments down the line, when you suddenly realize how - or why - something works. So don't worry about everything not being crystal clear at first.

Also, if you're any good at math - that helps a lot. Partly because computer programming is basically logics and applied mathematics. And partly because textbooks on the subject will be written by computer scientists, and these people know math and use it in examples. :rolleyes:

Personally I'm no good at math, so this is quite hard for me. :p

EDIT: how do i create a python file?
First of all, there are two ways to program a computer. The first option is what the textbook will start with, and that is using an interpreter and write your code into the command line, line by line and get the results immediately. This method should be good for learning and experimenting with code.

The second option is scripting, and at least in Python you create Python files, or "modules". You can use any text editor of your choice and by convention you don't name modules ".txt" but ".py". You will be using modules once you make your own mods - or when you mod other people's mods.

Edit2: Downloaded a Python 3.1.2.
I believe CivIV uses Python v2.4 so you could pick that up instead...

In the guide it says that i shall type this:
print "Hello, World!"

and this should come out:
Hello, World!
But when i press enter the last " glows red and it says synthax error... what am i doing wrong?
I'm yet to use Python outside of CivIV as I never bothered with the basics when I started modding RFC. This was a mistake but this also means that I'm yet to use the Python interpreter myself (except the built-in interpreter in CivIV).

I guess I should do that now. :rolleyes: If I can figure out where to download and how to install...
 
How do i open the Built-in python... Somebody told me it was the ~key but it didnt work... Im using a danish keyboard, and i know that it is different... As an example:
When i tried to start modding Medieval TW 2 it wasnt the ~ but the Æ key... The Æ key doesnt work here...
 
Update: I installed Python 2.6 and tested the tutorial program ("Hello World!"). It works, so I wouldn't know what the issue could be. A "Syntax Error" occurs when you don't follow the syntax of the programming language, like if you fail to include a second quotation or parenthesis, misspell a command or not make any sense the to interpreter in some other way. The interpreter will only interpret - it will not try to guess what you're trying to say.

If you haven't solved this problem yet, post a screen caption and we'll have a look at what's happening. (Hit the "Print Screen" key and paste the captured image into Paint or any other application like that. Save the image and attach to a post.)

You could alternatively try this little program on for size. First line:
Code:
x = 42
Second line:
Code:
print x
The interpreter should now tell you the meaning of Life, the Universe and Everything. ;) In that case the problem is most likely the quotation marks themselves - try simple quotation (') instead. ('Hello World!')
 
it works with the 2.4 version... but still cant find the key to open the inbuilt python
I find that beast to have a less than useful interface, but on my (Swedish) keyboard I think the key is "ö" or "ä" or something like that. Also know that there are two different interpreters (or whatever) and only one works. :rolleyes: You might have to hold down the shift key or something to open up the right one. (The working one states "Python v2.4" or something like this above the command line.)

Sorry for being able to be any more helpful on this. :(
 
A quick note on the print command:

Since CivIV is a non-text-based game you can't use "print" to show any kind of text in the game interface. Instead you can use it to write stuff into the Python Debug Log, which is very handy while designing your mod.

Disclaimer: This way of printing out debug messages work at least in the RFC modules/files, and you can find many examples of this in Rhye's code. (I don't know if you need to use parenthesis or not, though. I've used then myself, even if they might not be required for simple messages or messages only containing a string.)

edit: If you're experimenting with the built-in interpreter you can of course use "print" to get readouts inside the interpreter.
 
A quick one on whitespace:

Python is very particular about indentation. You organize your modules into blocks of code, and each block makes up a "level" in the indentation. I've learned that CivIV code mostly uses tabs as whitespace for indentation, but note that Rhye only uses blank spaces! (8 blank spaces to be exact - nothing more and nothing less.) So if you're adding code to any of his work you must also use blank spaces. You can't alternate between different types of whitespace in a single module, or so I believe.

Also, whitespace (blank spaces) in code is mostly optional and you can get away with a lot. But it is prudent to follow one single format in your code, so that the code is easier to read. So you could write this bit of code:
Code:
x = 42
if x == 42:
        return x - 1
Or format it like this:
Code:
x=42
if x==42:
        return x-1
I think that the first example is more readable, though.
 
If you don't like the eight-space mode, try a global search/replace of that to tabs. In the text editor I've been using, those show up as the exact same size.

The one feature my editor doesn't have that I wish it did? Line numbers. When debugging, the error log includes line numbers, and making those easier to find would be nice.
 
The print command worked... But now the guide says i should try to add a note to a function ( like hour = minute*60) and it says i should add a # and then the note, but the note and the # just turns red... Tried ALL the keys on my keyboard none opened the inbuilt python in civ...
Edit: your return function doesnt function either... im doing something wrong but im making progress :)
 
Uh- the # is a comment marker; anything after it on the line is ignored by the parser. It has nothing to do with how the program works, and comments are only there for human readability.
 
The print command worked... But now the guide says i should try to add a note to a function ( like hour = minute*60) and it says i should add a # and then the note, but the note and the # just turns red...
Its a bit unclear what the actual instruction said, but unless you get a error message I'd say everything is peachy. As jmerry said, the # sign isn't really a part of the programming language, so that would probably explain why the interpreter marks it red. (It does so on my copy of the IDLE interpreter also.)

Tried ALL the keys on my keyboard none opened the inbuilt python in civ...
Then its a sign that requires shift or alt, but refer to the page on keyboard layouts on Wikipedia (I didn't bookmark the link back when I was having the same issue) to figure out what key replaces what key. Note that you also need to figure out what keys are the parenthesis, brackets, quotations and so on - because they most likely won't be the keys displayed on your keyboard... :rolleyes:

If you plan on using the built-in interpreter you could just as well get a English/US keyboard... :p

Edit: your return function doesnt function either...
Ah, that was just to illustrate the difference in syntax. :D The return statement is used to override the default return value of a function (or method, as they are known in Object-Oriented Programming) and thereby exit the function. If the textbook haven't covered functions yet it should do so shortly.

im doing something wrong but im making progress :)
Keep the questions coming so that you don't get bogged down. :king:
 
in the guide it said i should use the sin function... There aint any...
Edit: I also tried with alt gr and shift
 
in the guide it said i should use the sin function... There aint any...
I'm not sure what you mean... Maybe you could post a link to or a quote to the passage in the textbook you're trying to decipher. Otherwise it can be hard to know what the issue could be.

If you mean a mathematical function in Python, then I believe that you need to import a math module and use dot notation when you use the function/method, like:
Code:
import math
math.sin(value)
(The variable "value" would be a numerical value.)
 
yeah it was written some lines below...
Now i have this problem. it says thisHere is an example of a user-defined function that has a parameter:

def printTwice(bruce):
print bruce, bruce

This function takes a single argument and assigns it to a parameter named bruce. The value of the parameter (at this point we have no idea what it will be) is printed twice, followed by a newline. The name bruce was chosen to suggest that the name you give a parameter is up to you, but in general, you want to choose something more illustrative than bruce.

The function printTwice works for any type that can be printed:

>>> printTwice('Spam')
Spam Spam
>>> printTwice(5)
5 5
>>> printTwice(3.14159)
3.14159 3.14159

In the first function call, the argument is a string. In the second, it's an integer. In the third, it's a float.

The same rules of composition that apply to built-in functions also apply to user-defined functions, so we can use any kind of expression as an argument for printTwice:

>>> printTwice('Spam'*4)
SpamSpamSpamSpam SpamSpamSpamSpam
>>> printTwice(math.cos(math.pi))
-1.0 -1.0
I did like this :
def printTwice (bruce) :
print "bruce", "bruce"
printTwice ("bruce")
then it says this:
bruce bruce
then i do this:
printTwice ("spam")
it shows this:
bruce bruce
 
Finally progress came over the printTwice thing by doing this
printTwice (bruce) :
print bruce, bruce
printTwice ("bruce")
def printTwice (spam)
print spam, spam
printTwice ("spam")
and then it showed:
spam spam
:)

Edit:Cant understand this...:
The order of the stack shows the flow of execution. printTwice was called by catTwice, and catTwice was called by __main__, which is a special name for the topmost function. When you create a variable outside of any function, it belongs to __main__.

Each parameter refers to the same value as its corresponding argument. So, part1 has the same value as chant1, part2 has the same value as chant2, and bruce has the same value as cat.

If an error occurs during a function call, Python prints the name of the function, and the name of the function that called it, and the name of the function that called that, all the way back to __main__.

For example, if we try to access cat from within printTwice, we get a NameError:

Traceback (innermost last):
File "test.py", line 13, in __main__
catTwice(chant1, chant2)
File "test.py", line 5, in catTwice
printTwice(cat)
File "test.py", line 9, in printTwice
print cat
NameError: cat

This list of functions is called a traceback. It tells you what program file the error occurred in, and what line, and what functions were executing at the time. It also shows the line of code that caused the error.

Notice the similarity between the traceback and the stack diagram. It's not a coincidence.
how do i use the traceback function? He doesnt explain how...
 
Top Bottom