Python (civ4 scripting language) tutorial thread

wow, those are hard!

I was just wondering: how do you implant a random number generator into python.
 
@thescaryworker
put the following line at the top of your module:
import random

then where you want to generate the random number (ie between 1 and 100) insert:

variable_name = random.randint(1,100)
 
i join late but someone said it's never too late, isn't it?
well, i'm not aprogrammer, i made some programs in clipper 5 (a long time ago) for high scholl and clubs, i learn delphi 6 since this winter, i think i must stop this to lurn the much possible python, i will see later for xml.

this thread is a great idea!
 
i see where you change your monsterstatus from 0 to 1 and from 2 to 3. But i dont see anywhere in there for it to go from 1 to 2 or from 3 to (other).
 
Ah i would love to start learning, i know of HTML and Turing (I know both prehistoric).
I will try my best to learn but i understand that the people here will be future moders.

If i can not help in the modding process i would certianly be able to use my history studies to help the modders build really nice historically acurate games :)
 
Welcome, ThePersian. Feel free to work at your own pace. And yes, people with many different skills can make very good mods. There is no reason why you have to know any programming language, but even just a basic understanding makes communication between people of different skills much easier.

There haven't been any lessons posted recently, but never worry. I'll be waiting until we are given more info about the modding system before I do any more about python, and anybody with a familiarity with HTML could easily understand XML. While we wait for more info, feel free to ask anything about python or XML.
 
input is used for Numbers and raw_input is used for strings.

Example:
input would return the value of 1
raw_input would return the string '1'
 
Timeeee4 said:
I've been wandering for a little while what the difference is between input and raw_input.

Thanks for any help.
What weakciv said, but there's more...

with input, you can refer to variables inside the code, and other objects. This is generally a bad idea.

What I do, is use raw_input, which returns a string, then use the int, float, etc function to convert it to the desired type. e.g.:
number = int(raw_input('Gimme an integer > '))
raw_input will return the string, and int will turn it into an integer. a bit wordy, but cuts down on errors.

Confused? :confused:

In short, what weakciv said :)
 
Doing some house cleaning of forgotten posts... sorry for the lateness...
JG99_Korab said:
does anyone here use a unix based OS while programming in python? I here there are alot more libraries and that it is soo much more portable in unix
I've been using linux virtually 100% of my time at home. If you use the module index, you can see any modules which are specific to a platform.

Oh, and Linux rocks ('cept for commercial windows games, e.g. civ :( )
vbraun said:
No comments on my updated Blackjack game?
I did download it and play around with it a bit, but neglected to comment. So, here are my comments: great fun, has been working without too many problems. I even tried stuffing it up with negative numbers, but you've dealt with that too!

Oh, and I love this bit:
Code:
vbraun = "cool"
while vbraun == "cool":
I will play blackjack as long as you are cool, but when you get really really cool? No more blackjack for me :lol:
though, as a comment, I found the game a tad laggy on my Amd64 3200+ - you may want to check that a loop isn't over-doing something.
 
Gingerbread Man said:
Oh, and I love this bit:
Code:
vbraun = "cool"
while vbraun == "cool":
I will play blackjack as long as you are cool, but when you get really really cool? No more blackjack for me :lol:
I had to-do something for variables. :crazyeye: q = 1 is no where as cool as saying vbraun = "cool" :p
Gingerbread Man said:
though, as a comment, I found the game a tad laggy on my Amd64 3200+ - you may want to check that a loop isn't over-doing something.
Are you sure? I have a few time.sleep commands in there to pause for a second or 2. So after you hit it will take a second to get a new card and when the deck shuffles it takes a couple seconds to shuffle. It's really a cosmetic thing that I added. :)

I'm glad you enjoy it! :)
 
vbraun said:
Are you sure? I have a few time.sleep commands in there to pause for a second or 2. So after you hit it will take a second to get a new card and when the deck shuffles it takes a couple seconds to shuffle. It's really a cosmetic thing that I added. :)
Ahh, that explains. I never thought blackjack would be too hard for a modern processor :confused:
 
Please go onto XML, I want to be able to store how much money you have so that when you reload it you don't have to start all over. :)
 
here is a link to an online book about Python. Between GBM's work and this book I think we have most if not all of the pieces we need.

Dive Into Python
 
Back
Top Bottom