Python (civ4 scripting language) tutorial thread

Gingerbread Man said:
IslandFox - just the lessons are enough to get started. Go to www.sthurlow.com (my website) if you want all lessons in one spot. They are also more up-to-date.

As for your raw_input issue, have you kept the quotation marks? Give me an example of what isn't working, and I'll have a look.

Yep, quotation marks, I even tried keeping a colon at the end of the text before the quotation marks. Just any text put in there makes it stop working. I'll post an example later today (I should probably get to school >.>), but just think of what you posted, but with different text.
 
Great tutorial, Gingerbread Man. Very useful!

You might want to change something in your index, though. The link to Lesson 2 doesn't link to lesson 2. :) And a second link for the second part of the lesson 8 would be helpful too.
 
I apologize if this has been asked and answered.

Do we know if the playtesters at Firaxis, who have been tweaking CivIV for months and months, have been testing the scripting and events features?
 
ARR, trying to show images in my window with the Python Imaging Library, but I cant get it to work...

I give up for today...
 
I thought I should upload my progress on my Blackjack game so far. I havnt polished the code yet, so theres no classes and maybe not as many functions as it should be. But it works!

My goal is to make it window based in the future, so you can see the images of the cards.

Anyways, just rename the textfile to .py and run it in IDLE.
 

Attachments

A little Cosmetic thing: It's way to wordy and at the speed it appears on the screen you lose track of where you are. Also the whole three of spades is not easily reconqisable, I would reccomend changing it to numbers and letter. (3s)

Also you can clean up all the print "" lines into one by making it

print "", "Sorry you are bust. You lose this round.", ""

So it doesn't take up so many lines of code.

Also you should use the try: except Error: so if someone were to input a wrong thing it doesn't die.


Also I shouldn't be allowed to bet 0 or a negative number. ;)
 
Hi. I never taught my Civ fanatism would awaken my old hobby for programming. Well, there it is: i stumbled on this thread and went thru lesson 1 to 8...

I used to program all kind of stuff on Quick Basic when i was 12 or so and was really into it. I mean, i made really advanced stuff for what QBasic could do at the time. I made fighting games, point-n-click games (kind of a Syndicate clone) and, of course a kind of Civ-Sim City mix. And then lost interrest in programming at about 16, bout the same time i had my first girlfriend. Makes you wonder, huh.

Anyway, all this to say that i'd really like to join you guys, and the future modding community for Civ4 ;)

I wanted to thank a lot GingerbreadMan for the cool tutorials!
 
Ok, i've been messing with python for a few hours and i just can't seem to
create a good and organised card deck. Not that vbraun's blackjack game isn't good it isn't clear and logical enough for me. Having the program analyse a card's value based on a number from 1 to 52 seems to me complicating things for nothing.

So, i first tried to create a Card class with the two variables (value,type) but then it seemed too complex as i'm not too confident in my python skills yet.

here's what i did:

value = 0 ---> do i have to do this? initialize variables first?
type = 0
card = (value,type)
import random
card = (random.randint(1,13),random.randint(1,4))

OK, so far i've got one card. Then i tought the rest would be a joke, creating a list "hand" with five times "card" inside, i wouldn't even need to create a deck, but i was wrong...

handstart = 5
hand = []
for i in range(0, handstart):
hand = hand.append(random.randint(1,13),random.randint(1,4))

i tought i would have a nice something like that:
hand = [(x,y), (x,y),(x,y),(x,y),(x,y)] where x and y are random numbers.
but no.
TypeError: append() takes exactly one argument (2 given)

Anyone can help and explain me the meaning??
Thanks!
 
bobbobjack said:
Ok, i've been messing with python for a few hours and i just can't seem to
create a good and organised card deck. Not that vbraun's blackjack game isn't good it isn't clear and logical enough for me. Having the program analyse a card's value based on a number from 1 to 52 seems to me complicating things for nothing.

So, i first tried to create a Card class with the two variables (value,type) but then it seemed too complex as i'm not too confident in my python skills yet.

here's what i did:

value = 0 ---> do i have to do this? initialize variables first?
type = 0
card = (value,type)
import random
card = (random.randint(1,13),random.randint(1,4))

OK, so far i've got one card. Then i tought the rest would be a joke, creating a list "hand" with five times "card" inside, i wouldn't even need to create a deck, but i was wrong...

handstart = 5
hand = []
for i in range(0, handstart):
hand = hand.append(random.randint(1,13),random.randint(1,4))

i tought i would have a nice something like that:
hand = [(x,y), (x,y),(x,y),(x,y),(x,y)] where x and y are random numbers.
but no.
TypeError: append() takes exactly one argument (2 given)

Anyone can help and explain me the meaning??
Thanks!

if you want your list to look like this
hand = [(x,y), (x,y),(x,y),(x,y),(x,y)]

change this line
hand = hand.append(random.randint(1,13),random.randint(1,4))

to this
hand = hand.append((random.randint(1,13),random.randint(1,4)))
 
I know my AnalyzeCard function isnt the best in the world. I was first going to create a list in a list, but I had a hard time working with that list afterwards, so I did what I did.
 
Yea, i know what you mean. It's really hard to work with lists, classes, and lists in classes, etc. The best way is to probably write like Gingerbread Man your program on paper first an then translate it into code, but i hate doing that.
By the way, you blackjack game was real cool, but it keeps beating me ;( i won only 1 time hehe
 
weakciv, it still doesn't work. gives me this error:
AttributeError: 'NoneType' object has no attribute 'append'

the thing i'm trying to find out is how do you get a variable (or something else) hold pairs of information, like the "hand" list i tried to work with?
Thanks!
 
bobbobjack said:
weakciv, it still doesn't work. gives me this error:
AttributeError: 'NoneType' object has no attribute 'append'

the thing i'm trying to find out is how do you get a variable (or something else) hold pairs of information, like the "hand" list i tried to work with?
Thanks!

Im sorry i forgot to remove part of the line. use this.
hand.append((random.randint(1,13),random.randint(1,4)))

(append is a function specificly for the object that uses it.)
 
I should pop in here more often...

How close is civIV to release, now? I just can't wait to see what we can do with the modding system :D

Here are last calls for lesson requests: is there anything that people are struggling with? It should be great if we can get right into modding as soon as possible - by the sound of it there'll be a lot that we'll be able to do! If you are not sure of anything in python, ask away.
 
Im struggling with working with the image modules of Python (when trying to show a image in a window, so I could make my blackjack game with windows interface ;) ), but I guess we wont be using those with Civ4.

But do you work with python combined with xml in civ4? But that should just be opening a text file (the xml file) and fetching the information.
 
Hey guys, I stumbled across this forum and topic not to long ago and got interested in what you guys were doing here. So I decided to try your beginners tutorial (which is very good by the way) and have just finished chapter 7 (am still a little confused on the "for" loops). Hope you don't mind me coming in here so late but I would like to be part of this discussion.

Thanks :)

P.S. "I'm a huge civ fan :goodjob: "
 
Its never too late to join, Python (what a fitting name, BTW). And welcome to CFC!

Ok, how about I write a tutorial on WxPython? It is a cross-platform GUI (Graphical User Interface, for the rest of us, or what it is you click on), and is very popular. From what I've seen of other GUI programming interfaces, they share a lot in common, and civIV will probably have something like it.

I'll start right away.
 
Back
Top Bottom