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


Pages : 1 [2] 3

Gingerbread Man
May 31, 2005, 11:12 PM
Ok, I figured out that if you put the decimal point in your inputs for the div function, it does floating point math instead of the default integer math. So that 3 / 2 = 1, where as 3. / 2. = 1.5
Seems like a handy thing. I always thought you had to have something after the decimal point, but it seems not.

Ok, after reading thru lessons 8 Classes, 9 Modules, and 10 Pickles. My head is going to explode. I think what we need are some really simple game related examples and exercises. Thanks for your continued support.
It's now #1 on my next lesson list!

Conflicted!?
Jun 01, 2005, 05:32 PM
Huge Civ fan here, I'm 16, a game/computer programmer hopeful, and am dying to get my hands on civ4! very late joiner! Have done extensive modding on Red Alert 1 and 2, making big mods but haven't published them online. No programming experience.

JG99_Korab
Jun 03, 2005, 05:27 AM
Python 2.4.1 is up now. Here is the download link (http://www.python.org/ftp/python/2.4.1/python-2.4.1.msi)
Welcome Conflicted. The more modders the better :goodjob:

JG99_Korab
Jun 03, 2005, 05:32 AM
HEY GB. I was a t your website. And i was wondering if you could change your background color. I don't know if i am the only one. But that white really strains the eyes. Maybe (off-white) would be better. If it is no trouble. Thank you GB
Korey

JG99_Korab
Jun 03, 2005, 06:25 AM
Hi GB. I am doing lesson 8 on classes now. I have got to the part were it tells you to run the program then start adding code. When i run a program it goes to python shell, but then the program ends, so it won't let me add anything else. Can you try getting the new python version and testing it out? it doesn't overwrite the previous one

Gingerbread Man
Jun 03, 2005, 06:29 AM
HEY GB. I was a t your website. And i was wondering if you could change your background color. I don't know if i am the only one. But that white really strains the eyes. Maybe (off-white) would be better. If it is no trouble. Thank you GB
Korey
I understand your problem - when I got a new LCD monitor, the brightness was excellent, but often headache-inducing. I will fix it in the redesign.

I'll probably release a preview soon, but the current site is not worth changing. The reason is that in the new design, all the pages are generated from a script, so it is really easy to make site-wide changes. Currently, there is only handwritten html.

Maybe I can use a more civilization-ish colour scheme. I want to keep images to a minimum, though.

homegrown
Jun 04, 2005, 11:35 AM
Well, I've been self guiding and I came up with a game related (although, not Civ specifically) exercise that I've been working with. Basically, the game has a metalworking component, with a number of different forges, and each can make different items. I'm creating a calculator that asks the user what project they want to make, how many they want to make, and how many forges they have access to, then it returns how much of what kind of metal, how much charcoal they will consume, and the total cooling time for the whole project.

Here's what I have so far.

Gonna have to attach a text file. Look for it. :)

First, the admin function really does work, but it's not persistant across sections. I'm guessing I'm gonna pickle the new dictionary if it's changed then somehow tell the program to writeback that dictionary when confirmed, but I'm not there yet.

Also, the program part, it occurred to me that I might be better off with several small functions, getinput(), calculate(), and printoutput() might clean everything up some, but I run into problems with the class objects because they end up being created in one function but need to be used in two others.

So, I guess I finally got brain around lessons 8 Classes and 9 Importing Modules (notice the import math and the math.ceil() call in the calculations area? :) But there are still some problems I'm trying to work out.

By the way, this little made up homework exercise, has been the best experience I've had, if only because I do have a couple friends that have been making me figure stuff out on my own, but are quick with the encouragement and praise when I have a light bulb moment. Maybe a neat Civ exercise would be a Culture Calculator. If I build this, this, and this, how long until the City expands to Size 1, 2, 3, 4, etc. In case anyone needed an idea of something to do. :)

Oh, also, now I know why programmers like :beer:

Gingerbread Man
Jun 05, 2005, 02:36 AM
Homegrown - that's some really good work you've got there.

attached are the python files for my text adventure game - you could probably borrow some concepts from it.

While your program probably doesn't need multithreading and queues, as is used in the text adventure (a.k.a. pytex) game, it would be advantageous to use classes more effectively, as opposed to lots of dictionaries.

The way the pytex game works, is that there is one class that is accessable by all players - the world class. This class contains a dictionary full of classes refering to items in the game.

When the client thread (that is, the person playing the game) wants to access some data about the game world from the world class, it sends a request for information, and the world class, when it gets around to it, processess the request and returns the resulting data.

In your project, I would cut the dictionaries a_project and project, and simply input the data directly into class instances that are inside a dictionary instead. E.g. change the __init__ function of Project to this:

class Project:

def __init__(self, item,bldg,upgrade,metaltype,metalqty,waxqty,cool):

self.item = item
self.bldg = bldg
# etc etc etc

then, create a dictionary of all the projects you could have:

projects = {}
projects['iron bar'] = Project(0,0,'iron',2,1,0,15)
projects['gold wire'] = Project(2,0,'gold',1,10,0,10)
projects['steel sheeting'] = Project(2,0,'steel',2,6,0,10)
# etc etc etc

Do the same for a_charcoal. This might make the program longer, but it makes it easier to understand.

Here is my text adventure game below. Have both files in the same folder, and run pytexgame.py .

In pytexgame, all the items (which are class instances) in the game world are put into a dictionary called playerroom. At the bottom of pytexgame, we create a game world with all the items we have defined in it, then we create a player that plays a game in this world.

For one of my next exercises, I'll write some documentation for pytex, and get you people to do whatever you want with it. It still has some work to go, so it might be later on in the piece.

Poisos
Jun 07, 2005, 10:03 AM
Hello to all, hello Gingerbread Man.
First I want to say that I have been with you and this thread when I first discovered it a short time after it has been announced that cIV would offer Python scripting. I read (almost) everything. Very good work! I'm happy to see this interested community and I value your great work and your time spent here :goodjob: .
I acually bought a book the instance I heard about it :D . I came in contact with Python the first time through "Blender" a freeware-"open source"-abandoned-type 3D modeler. But I didn't do any scripting back then.

I have gathered some knowlegde in (almost chronoligical order :) ) Basic, Pascal/Turbo Pascal, HTML, C, C++, Java, C#, XML, PHP and Python (actually still working on that ... hm, more actually on ALL of them :D except the very old ones). No really great projects so far, but I am programming since I was 10 (or so) ... and as you can see: coming around a lot :) .

I'd like to a tiny piece of information to your post on classes. I became very confused when I got in contact with classes in C++ but this explanation helped me a lot to understand what they really do (this is not intended to correcting you but to make classes a little more transparent to the community):

Think of classes as your BLUEPRINTS for later manufactured objects! In your class definition you describe how you would build i. e. a car ... but since then there is no real car, right(only the pice of paper with your blueprint on it)? So you have to build a car according to this BP. This is done by making an instance of it.
In Python: myCar = blueprint_of_a_car()
Now the little "data elves" in your computer actually build a car named "myCar". Now you would be able to drive that car or accellerate it and so an (ever drove a blueprint :crazyeye: !?).

This brings us to inheritance and polymorphism.
If you would like to build a new car with special tires, seats or a different motor you wouldn't design a whole new car, now would you? Instead you would just change your motor or your tires and leave the rest as it is.
This is done by creating a new class (or blueprint) which inherits all the attributes and methods from your original car class (copy all information of your original blueprint to another) and then overrides the information i. e. of the type of motor what should be in the car (erase the data of your motor on your copied blueprint and specify another one).

I am working right now on an civ related interface mod. Remember that you had to explicitly change single leaderheads in your civ3 foreign advisor screen if too many civs were in the game!? I'm working on a demo solution for that problem in Python where the leaderheads will organize themselves on a circle and scale down when necessary.
I want to try that using Tkinter objects, canvas, simple shapes (not even real images to scale ... keeping it as simple as possible). After all they said the INTERFACE would be modable.
So I WILL come back (for support :D ) and I am also planing on posting the solution here on cfc.

(See second part) (http://forums.civfanatics.com/showpost.php?p=2830887&postcount=274)

vbraun
Jun 07, 2005, 03:02 PM
How do I pick a random variable out of something like C1-C52. Could I do something like Cvariblename or can I make a list like cards = [C1,C2,C3...,C51,C52] and then call a random card using cards[random] where random is a random number?

Also what is the function (if there is) that generates a random number?

vbraun
Jun 07, 2005, 05:05 PM
Nevermind I figured it out.

Here is a simple script that defines a deck of 52 cards and also includes a function that picks a random card. Each card is in a list like so:

[suit, cardnumber, 0]

Just rename .txt to .py It is meant to be imported. :)

Now on to Blackjack!

Poisos
Jun 08, 2005, 06:42 AM
@vbraun

Uh ... man you have to become lazy! ;)

If you want to define 52 cards, why don't you define them as a list of objects?
Example:


from random import *

class Card:
# I'm not sure if the following lines are necessary
self.type
self.value
self.reserved

# These are definetly necessary
__init__(self, type, value, reserved)
self.type = type
self.value = value
self.reserved = reserved

# 52 cards are being created according to your sample here
while i < 4
i++
while j < 13
j++
cardlist.append(Card(i, j, 0))

#Pick a random card
def pickcard(cardlist):
return cardlist[randint(1,52)]


I did not test the code yet. But it should be something like that.
Almost all of your code is done in 7 lines (not counting the class definition, which offers of course even more options, like what card defeats an other and so on).

Gingerbread Man
Jun 08, 2005, 07:22 AM
Think of classes as your BLUEPRINTS for later manufactured objects! In your class definition you describe how you would build i. e. a car ... but since then there is no real car, right(only the pice of paper with your blueprint on it)? So you have to build a car according to this BP. This is done by making an instance of it.
In Python: myCar = blueprint_of_a_car()
Now the little "data elves" in your computer actually build a car named "myCar". Now you would be able to drive that car or accellerate it and so an (ever drove a blueprint :crazyeye: !?).

This brings us to inheritance and polymorphism.
If you would like to build a new car with special tires, seats or a different motor you wouldn't design a whole new car, now would you? Instead you would just change your motor or your tires and leave the rest as it is.
This is done by creating a new class (or blueprint) which inherits all the attributes and methods from your original car class (copy all information of your original blueprint to another) and then overrides the information i. e. of the type of motor what should be in the car (erase the data of your motor on your copied blueprint and specify another one).
Excellent! Will incorporate it into the redesign. You put it in real-world terms, and most people understand cars.

I am working right now on an civ related interface mod. Remember that you had to explicitly change single leaderheads in your civ3 foreign advisor screen if too many civs were in the game!? I'm working on a demo solution for that problem in Python where the leaderheads will organize themselves on a circle and scale down when necessary.
I want to try that using Tkinter objects, canvas, simple shapes (not even real images to scale ... keeping it as simple as possible). After all they said the INTERFACE would be modable.
So I WILL come back (for support :D ) and I am also planing on posting the solution here on cfc.
As a word of advice, I don't believe that tkinter is a really good interface to work with - it is a little limited. Try something like GTK (which requires extra files to be installed) or WxPython (which is cross platform, and uses the native-style buttons, etc. of the operating system it is running on.)

Poisos
Jun 08, 2005, 07:41 AM
Try something like GTK (which requires extra files to be installed) or WxPython (which is cross platform, and uses the native-style buttons, etc. of the operating system it is running on.)

Thanks for the hint!

Gingerbread Man
Jun 08, 2005, 08:07 AM
@vbraun

Uh ... man you have to become lazy! ;)
In programming, laziness is both a vice and a virtue!

[profound-ness]Try to do as much as possible, as clearly as possible, but writing as little as possible... such is the art of the programmer...[/profound-ness]

To use a random number generator between 0 and 51:

import random
random_number = random.randint(0,51,1)

don't use whrandom - as the warning says (at least in Python 2.4), whrandom is depreciated. That is to say, it is old, probably unmaintained and may be removed some day.

The list of objects idea is good. Here's what I'd do:

from random import *
# create the definition of a card
class Card:
def __init__(self,suit,number,reserved):
self.suit = suit
self.number = number
self.reserved = reserved

# build your deck
deck = []
suit = 0
num = 0
for i in range(1,52,1):
if num > 12:
suit = suit + 1
num = 0
deck.append(Card(suit,num,0))
num = num + 1

# pick a random card
suitname = ['hearts','spades','diamonds','clubs']
cardname = ['Ace','two','three','four','five','six','seven','e ight','nine','ten','jack','queen','king']
r = randint(0,51)
print "Randomly picked, was the "+cardname[deck[r].number]+' of '+suitname[deck[r].suit]

In fact, this works rather nicely. I could set it up to simulate a real deck, where the order of cards is predetermined, and the most recently used card is found at the bottom. try using random.shuffle to shuffle the deck. that would stop, say, 21 cards of suit diamonds occuring in the space of 30 picks (sure, its truly random that way, but is physically impossible, unless you're playing against people of... questionable tactics)

vbraun
Jun 08, 2005, 02:09 PM
@vbraun

Uh ... man you have to become lazy! ;)

If you want to define 52 cards, why don't you define them as a list of objects?
Example:

My first program, give me some slack. :p I was looking at a way with classes but ended up giving up and decided to take the easy way out.


don't use whrandom - as the warning says (at least in Python 2.4), whrandom is depreciated. That is to say, it is old, probably unmaintained and may be removed some day.
I was going to mainly edit the whrandom file to get rid of that message :lol: switching to use random.

The reason I used whrandom is the documentation said vice versa! I assume the documentation was unupdated.

Time to go fix my code. :)

Edit: I copied and pasted this exactly:
import random
random_number = random.randint(0,51,1)
And now I get an error saying
TypeError: randint() takes exactly 3 arguments (4 given)

Thats really odd.

Edit2: By taking out the last argument it seems to work.

Old_Lion
Jun 08, 2005, 02:18 PM
don't forget the first argument is self.

vbraun
Jun 08, 2005, 02:45 PM
The list of objects idea is good. Here's what I'd do:

from random import *
# create the definition of a card
class Card:
def __init__(self,suit,number,reserved):
self.suit = suit
self.number = number
self.reserved = reserved

# build your deck
deck = []
suit = 0
num = 0
for i in range(1,52,1):
if num > 12:
suit = suit + 1
num = 0
deck.append(Card(suit,num,0))
num = num + 1

# pick a random card
suitname = ['hearts','spades','diamonds','clubs']
cardname = ['Ace','two','three','four','five','six','seven','e ight','nine','ten','jack','queen','king']
r = randint(0,51)
print "Randomly picked, was the "+cardname[deck[r].number]+' of '+suitname[deck[r].suit]

In fact, this works rather nicely. I could set it up to simulate a real deck, where the order of cards is predetermined, and the most recently used card is found at the bottom. try using random.shuffle to shuffle the deck. that would stop, say, 21 cards of suit diamonds occuring in the space of 30 picks (sure, its truly random that way, but is physically impossible, unless you'r playing against people of... questionable tactics)
It fills deck with this: (doing a print deck)
[<__main__.Card instance at 0x2a955da050>, <__main__.Card instance at 0x2a955ec098>, <__main__.Card instance at 0x2a955ec0e0>, <__main__.Card instance at 0x2a955ec128>, <__main__.Card instance at 0x2a955ec170>, <__main__.Card instance at 0x2a955ec1b8>, <__main__.Card instance at 0x2a955ec200>, <__main__.Card instance at 0x2a955ec248>, <__main__.Card instance at 0x2a955ec290>, <__main__.Card instance at 0x2a955ec2d8>, <__main__.Card instance at 0x2a955ec320>, <__main__.Card instance at 0x2a955ec368>, <__main__.Card instance at 0x2a955ec3b0>, <__main__.Card instance at 0x2a955ec3f8>, <__main__.Card instance at 0x2a955ec440>, <__main__.Card instance at 0x2a955ec488>, <__main__.Card instance at 0x2a955ec4d0>, <__main__.Card instance at 0x2a955ec518>, <__main__.Card instance at 0x2a955ec560>, <__main__.Card instance at 0x2a955ec5a8>, <__main__.Card instance at 0x2a955ec5f0>, <__main__.Card instance at 0x2a955ec638>, <__main__.Card instance at 0x2a955ec680>, <__main__.Card instance at 0x2a955ec6c8>, <__main__.Card instance at 0x2a955ec710>, <__main__.Card instance at 0x2a955ec758>, <__main__.Card instance at 0x2a955ec7a0>, <__main__.Card instance at 0x2a955ec7e8>, <__main__.Card instance at 0x2a955ec830>, <__main__.Card instance at 0x2a955ec878>, <__main__.Card instance at 0x2a955ec8c0>, <__main__.Card instance at 0x2a955ec908>, <__main__.Card instance at 0x2a955ec950>, <__main__.Card instance at 0x2a955ec998>, <__main__.Card instance at 0x2a955ec9e0>, <__main__.Card instance at 0x2a955eca28>, <__main__.Card instance at 0x2a955eca70>, <__main__.Card instance at 0x2a955ecab8>, <__main__.Card instance at 0x2a955ecb00>, <__main__.Card instance at 0x2a955ecb48>, <__main__.Card instance at 0x2a955ecb90>, <__main__.Card instance at 0x2a955ecbd8>, <__main__.Card instance at 0x2a955ecc20>, <__main__.Card instance at 0x2a955ecc68>, <__main__.Card instance at 0x2a955eccb0>, <__main__.Card instance at 0x2a955eccf8>, <__main__.Card instance at 0x2a955ecd40>, <__main__.Card instance at 0x2a955ecd88>, <__main__.Card instance at 0x2a955ecdd0>, <__main__.Card instance at 0x2a955ece18>, <__main__.Card instance at 0x2a955ece60>]

Poisos
Jun 08, 2005, 04:38 PM
My first program, give me some slack.
Didn't mean to push you. For that reason I added a smiley :) .

It fills deck with this: (doing a print deck)
Code:

[<__main__.Card instance at 0x2a955da050>, <__main__.Card instance at 0x2a955ec098>, <__main__.Card instance at 0x2a955ec0e0>, <

That is correct? Where is your problem?
It only tells you that an actual Object of type "Card" is at memory position "0xa955da050" (hexadecimal) and so on.
Can you not print your card values? I tested GBM's Code and it works with me!?

And now I get an error saying
Code:

TypeError: randint() takes exactly 3 arguments (4 given)



Thats really odd.

Edit2: By taking out the last argument it seems to work.

See documentation for randint below:
http://www.python.org/dev/doc/devel/lib/module-random.html

vbraun
Jun 08, 2005, 05:19 PM
That is correct? Where is your problem?
It only tells you that an actual Object of type "Card" is at memory position "0xa955da050" (hexadecimal) and so on.
Can you not print your card values? I tested GBM's Code and it works with me!?

I couldn't get the card values to show. I fixed it by changing deck.append(Card(suit,num,0))
to
deck.append([suit,num,0])
thus making the class unnecssary, and it works how I want it.

I also have each time a card is selected make it disapear from the deck so it can't be called again, untill I shuffle the deck with this:
for i in range(1,len(deck)+1,1):
deck.pop(0)
suit = 1
num = 1
for i in range(1,53,1):
if num > 13:
suit = suit + 1
num = 1
deck.append([suit,num,0])
num = num + 1

Right now my game of Blackjack selects 4 non-same cards (2 for the player and 2 for the dealer) and will check for a Blackjack/Bust/Under 21. Now I need to work on being able to hit/stay. :)

Edit: Got a basic hit system down
Here is some sample game ATM:
You have 7d Qd
Dealer has 2h Xx
What would you like to do?
h
You now have:
7d Qd 9h

Gingerbread Man
Jun 09, 2005, 12:41 AM
import random
random_number = random.randint(0,51,1)
And now I get an error saying
TypeError: randint() takes exactly 3 arguments (4 given)

Thats really odd.

Edit2: By taking out the last argument it seems to work.
Sorry, that was my mistake. I thought you could give it a parameter telling the steps between integers... :blush:

By the way, your blackjack game is a really good way of making simple AI. I'd encourage other people to make a text-based card game, and make an AI to go with it.

Keep the card game simple, like blackjack, so that you don't have to worry too much about the finer details of rules.

JG99_Korab
Jun 09, 2005, 10:40 AM
Hello again, I am now making my own program. Can someone tell me how to make a list of options(menu) for one of the things i have made. the one i want is self.girlfriend. I would like to make list of possible answears for this and if you choose one then the answear comes up in the finally part. I have attached two files. The main program and a module. You have to have both in the same folder, and run only the module

vbraun
Jun 09, 2005, 02:59 PM
I'd like you guys to give comments on my blackjack game so far. Right now it won't reconize Aces properly and the Dealer can't hit yet. Type h for hit and s for stay. Also if it says "Blackjack!!" it still asks you wether you want to hit or stay.

There is some comments so you can have some kind of idea whats going on.

Poisos
Jun 09, 2005, 03:37 PM
Seems like my post would become too big if I'd add my polymorphism description. So I post it here:
(See first part) (http://forums.civfanatics.com/showpost.php?p=2824723&postcount=259)

So where is polymorphism used?
I' ll try to make it simple at first. In my opinion the simplest thing you can do which can be described as polymorphism related is overriding functions and defining functions with the same name but a variable number of parameters.

For example you have a function which assigns RGB (RedGreenBlue) color values to object attributes. You can define two functions as follows:

def assignRGB(r, g, b):

or

valueList = [r, g, b]
def assignRGB(valueList):

This might seem not so overwhelmingly useful at first but that 's just because a program context is missing. In fact constructs like these can become very convenient during programming.
This technique is also called "overloading functions".

Overriding a function works differently. Imagine you created a class "Car" with a function crankCar(). In that function you would then call a function turnKey(), because that would be the first step for cranking your car.
Now you create a new class "ModernCar" which inherits "Car". You would already be able to use:

myCar = ModernCar()
myCar.crankCar()

But crankCar() would still turn a key. :nono: We don't like that for our new car. So we override that function through redefining it and calling pressStartButton() in this new version.

class Car:
def _turnKey(self):
print "Key turned"

def crankCar(self):
self._turnKey()

class ModernCar(Car):
def _pressStartButton(self):
print "Startbutton pressed"

def crankCar(self):
self._pressStartButton()

So we only have to know that we want to crank our car. How that actually works is defined in the crankCar() function of each class type :) (Aaahh .. "ignorance is a bliss" :D ).

You might wonder why I used "_" as first character in my function names. That describes a low private status of that funtion. "__" describes a high private status. What that means is that low private functions can not be used from outside the class unless you now their name and call them explicitly. (See Python documentation) (http://docs.python.org/ref/id-classes.html) As the Python documentation states, they're not imported by:from module import * In my example I just want to protect my "_"functions from easy external access so that an object user is only able to crank the car but not to turn the key or press the start button.

High private functions can not be called from outside the class at all. (By the way ... nothing that we realy HAVE to use right now! It's just for education ;) .)

However, I would say polymorphism is really about "morphing" types of objects into base types of their own class hierarchy or vice versa (which can get a litle bit dangerous in terms of program stability). But until now I'm not sure how this can be accomplished in Python :( .
Perhaps GBM can help us out!?

PS: @GBM ... I wonder if it is a good idea to link both posts on inheritance and polymorphism in your starting post. After all they are both almost a complete lesson :) . I will gladly edit them where necessary.

Old_Lion
Jun 10, 2005, 01:31 AM
great post, Poisos :goodjob:
I find your explanation very clear.

I do have a question anyway about the private status.
high private : understood. Very useful in my view to prevent users to deal inadvertently with the inner mecanisms of your class.

But I'm not sure about low private status....
You have to know the name and call it explicitely... but what is the difference with the default status of classes elements ?

Meleager
Jun 10, 2005, 02:22 AM
Hi. Only joined the forum a few days ago and have already posted almost 100 posts. I'm interested in this. I am a first year Uni student studing for a batchelor of information technology. I know:
DrScheme (training language they use at Uni), some JavaScript, HTML, ActionScript (yes I know these are not REAL programing languages). I am very good at the logic of coding and creating some really high quality flash games (at least at the code level) is one of my fovorite past times. And My Dad programs for a living.

I will try to start tommorow but I might not get a chance to really go through these till after my exams are done (a few weeks). Once I get into them though I should be up to scratch pretty quick.

Gingerbread Man
Jun 10, 2005, 08:40 AM
Hello again, I am now making my own program. Can someone tell me how to make a list of options(menu) for one of the things i have made. the one i want is self.girlfriend. I would like to make list of possible answears for this and if you choose one then the answear comes up in the finally part. I have attached two files. The main program and a module. You have to have both in the same folder, and run only the module

In the lesson on functions, there is a menu function that is created. I think there are some other versions of it later in the tutorial. Either way, dig it up, and adapt it to fit your solution.

Posious - Excellent work! I'll be away for the (in Australia) long weekend, but will be able to help you later.

I could make space for contributed tutorials/HOWTOs on my site, but just remember that anything up there has to be clear, and leads off from what is already there (that is, assumes that the only knowledge the reader has is what they got from the site).

Old Lion - Again, I'll be able to help you in 3 or so days, after I get back from the break.

Meleager - thanks for dropping in :) . If you find any part difficult, let me know, because if the lessons are too difficult, then they aren't good enough to be for beginners.

JG99_Korab
Jun 10, 2005, 09:01 AM
In the lesson on functions, there is a menu function that is created. I think there are some other versions of it later in the tutorial. Either way, dig it up, and adapt it to fit your solution.

I tried. I have the menu function but I can't figure out how to do it. Not really a menu. But just a yes or no option. and if answer is yes print "......." and if answear is no print.... Can you at least look when you have the time?

Meleager
Jun 11, 2005, 02:19 AM
You link on the first page for the 2nd lesson goes to the wrong place.

And I've done lesson 1 :)

matthewv
Jun 11, 2005, 04:03 AM
Hello all,
Good work on the tutorial Ginderbread Man.
Its nice to see someone willing to spend their valueable to help other potential cIV modders.

I have been working through the tutorial and got up to GM's mini adventure game. I was going through it to figure out how it worked and noticed a couple of interesting things.

Code from GM's Adenture game
location = objects
loop = 1
lastinput = []
while loop == 1:
noprint = 0
location = objects
input = command(">")
if input [-1] not in actions:
print "Sorry, I don't understand the command \'" + input[-1] + "\'."
continue
if input[0] == "exit":
print objects['exit']
loop = 0
noprint = 1
break
newcommand = lastinput
for word in input:
newcommand.append(word)
if len(input) <= 1:
newcommand = input
try:
for entry in newcommand:
location = location[entry]
except:
location = objects #not in original program
for entry in input:
try:
location = location[entry]
except:
print "Sorry, I don't recognise the object \'" + entry + "\'."
noprint = 1
break
if noprint == 0:
print location
lastinput = input[:-1]

In this program code(exluding code in italics) the code in bold is rather useless and can be removed without affecting how the program runs in the least way.

However, if you insert the code in italics, the code in bold serves a purpose(does what it was likely originaly intended to).

before the code in italics was inserted the program would run like this:

> touch roof rust
The rust pokes through and water trickles from the hole you made.
Have a nice drink.

> touch roof rust
Sorry, I don't recognise the object 'roof'.

After code in italics was inserted:

> touch roof rust
The rust pokes through and water trickles from the hole you made.
Have a nice drink.

> touch roof rust
The rust pokes through and water trickles from the hole you made.
Have a nice drink.

If anyone want a better explanation :confused: on what I am talking about just say so and I will try explain what is going on.(I will never make a good teacher :( )

Meleager
Jun 12, 2005, 03:06 AM
Just so you know I have finished up to lesson 4.
Its very simple when you know other languages.

I'll get as much done as I can between uni exams. Look foward to the prospect of modding civ 4.

Gingerbread Man
Jun 13, 2005, 07:21 AM
Ok, I'm back to answer your questions:

Korab: Try this function for a menu. It uses a really cool feature that you can use with strings - use the % symbol to act as a placeholder for changing values inside a string. For example, "%i is an integer"%(number) would replace %i with the value held inside number. %s is used for strings, and you can probably guess the rest.

Simply give the function an array of options for 'options', and the question you want to ask for question. I will give an example output:

# THE FUNCTION
def menu(options,question):
count = 0
# print your menu options
for menuitem in options:
count = count + 1
print "%i) %s"%(count,menuitem)
# use question to ask the user to enter a number
response = input(question+' ') - 1
# return the user's answer
return response

# EXAMPLE OUTPUT
# options = ['one','two','three','four']
# question = '>'
1) one
2) two
3) three
4) four
>
Try it out. it will give the index of the array number that the user picked. By the way, it has no error checking - I'll leave that up to you ;)

Old lion: I won't pretend that I know a reason for low private status - from what I've read of the python documentation, methods (that is, functions in a class) aren't imported by default by the import command.

Matthewv - I see where you are coming from with my program. Indeed, you seem to be right. Remember that what makes this tutorial great - that it was written from the perspective of a beginner - is also a bit of a curse - the code can sometimes be a bit problematic. I could rewrite it, or I could leave it as an example for bugfixing practice - whatever works best.

This feedback is helpful - I want my site to be a useful resource for modders of all skill levels, and problems like this need to be weeded out. If I knew how to make a wiki, I could start a wish-list...

JG99_Korab
Jun 14, 2005, 02:15 AM
so then i won't be able to put in in a class?

Gingerbread Man
Jun 14, 2005, 08:53 AM
so then i won't be able to put in in a class?
Put what in what class? :confused:

If you mean the menu function, you can use it wherever you can use a normal function (i.e. pretty much everywhere).

If you mean hidden objects (that start with a _), then I'd say one of their main uses is to use them in classes.

Hope that answers your question.

JG99_Korab
Jun 14, 2005, 09:40 AM
can you just look at the file?

vbraun
Jun 14, 2005, 08:05 PM
Any comments on my Blackjack game?

JG99_Korab
Jun 15, 2005, 03:25 AM
Make a how-to text file. Then i will play it :D

Gingerbread Man
Jun 17, 2005, 01:03 AM
can you just look at the file?
Ok, sorry for the misunderstanding. I assume that you want to run the menu in the __init__ part? ok, here is my take:

#Myprogram.py

#My First attempt to make my own program

### PUT THE MENU FUNCTION DEFINITION HERE:
def menu(options,question):
count = 0
for menuitem in options:
count = count + 1
print "%i) %s"%(count,menuitem)
response = input(question+' ') - 1
return response

#define a class#Myprogram.py
#My First attempt to make my own program
### PUT THE MENU FUNCTION DEFINITION HERE:
def menu(options,question):
count = 0
for menuitem in options:
count = count + 1
print "%i) %s"%(count,menuitem)
response = input(question+' ') - 1
return response

class yourself:
def __init__(self):
### When you use the menu fuction; do this:
# define your options
# ask the user to give their answer
# then put the answer into a variable
self.name = raw_input("What is your name? ")
self.age = raw_input("How old are you? ")
# GENDER
genders = ['male','female']
self.sex = genders[menu(genders,"What sex are you?")]
self.height = raw_input("How tall are you(In feet and inches)? ")
self.eyes = raw_input("What color are your eyes? ")
self.live = raw_input("Where do you live? ")
# BF/GF
bfgf = ['boyfriend','girlfriend','single']
self.girlfriend = bfgf[menu(bfgf,"Do you have a boyfriend/girlfriend?")]

def printdetails(self):
print "Your name is " + self.name + " and you are" + self.age + "years old,",
print "You are a " + self.sex + " and are " + self.height + " tall." ,
print "You have " + self.eyes + " eyes and you live in " + self.live,

I haven't had a chance to test this... give me 60 seconds...

EDIT - old one was a bogey. Bugs have been fixed

JG99_Korab
Jun 17, 2005, 03:16 AM
okey. Thanks. I edit it still a bit. Wasn't completely satisfied. i am still not but i am going to work on it. is it possible that when you have a list of options like 1) Male and 2)female, i can just make it have to type male or female for the answer and not 1 or 2?

JG99_Korab
Jun 17, 2005, 04:38 AM
can you look at this again. I have tried to make a dictionary out of the details printed at the end. if i run the class and printdetails it will add the name to the dictionary and the details. you will probably see what i want to do just by looking. can you? i think it should be something like if name.has_key(self.name) then print the dictionary entry.

Gingerbread Man
Jun 17, 2005, 06:47 AM
Hmm, I see what you are trying to do, however I think it is the wrong approach. remember that the class 'yourself' defines one person, and shouldn't hold a dictionary of everyone in existence - that isn't defining simply one person anymore...

What you want to be doing is putting the instances of your class inside a dictionary or list. for example:

listofpeople = {}
listofpeople['John'] = yourself()
listofpeople['Pete'] = yourself()

listofpeople['John'].printdetails

Also, in your use of the menu function:

question = ("Would you like to make another entry?")
choice = menu(options,question)

you need to define both the options AND the question. For example:
[code]
question = "Would you like to make another entry?" # get rid of the brackets - they muck things up a little
options = ['yes','no'] # define what options the user has
choice = menu(options,question)

Gingerbread Man
Jun 17, 2005, 06:47 AM
Hmm, I see what you are trying to do, however I think it is the wrong approach. remember that the class 'yourself' defines one person, and shouldn't hold a dictionary of everyone in existence - that isn't defining simply one person anymore...

What you want to be doing is putting the instances of your class inside a dictionary or list. for example:

listofpeople = {}
listofpeople['John'] = yourself()
listofpeople['Pete'] = yourself()

listofpeople['John'].printdetails

Also, in your use of the menu function:

question = ("Would you like to make another entry?")
choice = menu(options,question)

you need to define both the options AND the question. For example:

question = "Would you like to make another entry?" # get rid of the brackets - they muck things up a little
options = ['yes','no'] # define what options the user has
choice = menu(options,question)

EDIT: The other thing is, is that you are treating a class as if it were a function. Think of an instance of a class as a place of storage for information about an instance of something, and the functions inside that class simply act on the values contained.

I'll write an example of what you want to do, if you would like. Just to give you an idea of what I mean (It's hard to explain these things just by talking about them - seeing is learning).

Either way, I probably need to expand on my lessons about classes. It is such an important thing in python, that it probably deserves two lessons. In the meantime (and as always), I'd be happy to help anyone with questions.

JG99_Korab
Jun 17, 2005, 07:45 AM
what i want it to do is save the information i give it. if i tell it my name is korey it is going to put korey into the dictionary. and when i want to open the dictionary it will ask what my name is. i will say it is korey. it will look if it is in the dictionary, if it is it will print "printdetails()"

Flintlock
Jun 18, 2005, 10:23 PM
Just a quick question about python - how do you get it to interpret values in a list as a number instead of as a word?

I want it retrieve the second number in a list, 12, and multiply it by 10, but it keeps giving me '12121212121212121212' instead of 120.

edit: Well, nevermind I just put the values as seperate variables instead of in a list

homegrown
Jun 20, 2005, 04:11 AM
Just a quick question about python - how do you get it to interpret values in a list as a number instead of as a word?

I want it retrieve the second number in a list, 12, and multiply it by 10, but it keeps giving me '12121212121212121212' instead of 120.

edit: Well, nevermind I just put the values as seperate variables instead of in a list

I think you're seeing the difference between L= ('11','12','13') and M = (11,12,13). L[1]*10 should print '12121212121212121212' and M[1]*10 should print 120.

>>> l = ('11','12','13')
>>> m = (11, 12, 13)
>>> print l[1]*10
12121212121212121212
>>> print m[1]*10
120
>>>

Gingerbread Man
Jun 20, 2005, 06:56 AM
Just a quick question about python - how do you get it to interpret values in a list as a number instead of as a word?

I want it retrieve the second number in a list, 12, and multiply it by 10, but it keeps giving me '12121212121212121212' instead of 120.

edit: Well, nevermind I just put the values as seperate variables instead of in a list
This is happening because you are multiplying a string by 10, as opposed to a number by 10. When you multiply a string, it simply repeats itself (e.g. 'hello'*3 becomes 'hellohellohello'). Remove the quotation marks, and it will work.

JG99_Korab
Jun 22, 2005, 01:35 PM
what i want it to do is save the information i give it. if i tell it my name is korey it is going to put korey into the dictionary. and when i want to open the dictionary it will ask what my name is. i will say it is korey. it will look if it is in the dictionary, if it is it will print "printdetails()"

vbraun
Jun 24, 2005, 10:55 PM
Can I get any feedback on how I'm doing on my blackjack game that I posted a whille back?

I have not worked on it since I posted it, and now I pretty much have forgotten where I am and what I'm doing... :(

vbraun
Jun 25, 2005, 05:12 PM
Here is my updated game of Blackjack. You can now play one full hand of blackjack vs the dealer. The only thing that needs to be fixed is the value of the Ace. So if you get an Ace treat it as a one even if it says Blackjack!! and you have an Ace.

There is also a display issue with your hand. Once you hit you will see a few zero's after your actuall cards. I fixed this with the dealer's hand but haven't gotten around to adding it to the player's. Also there are a few cosmetic pauses and print "" to make it seem more organized.

I really would like some comments on my code. Most of it has been commented to tell you what's going on.

Here is a what a sample game might look like:
You have 6s 8d
Dealer has 9h Xx

What would you like to do? (h/s)
h
You now have:
6s 8d 5s 00 00


What would you like to do? (h/s)
s

Dealer has:
9h 10s

You lose
We are done


Enjoy!

Chieftess
Jun 26, 2005, 05:46 PM
GBM - here's one to add to your loops section. (I've been teaching myself a bit)

"How to make Python's for "loop" act like a real loop."
Simple answer: Use Range()


b = int(raw_input("How many times do you want to run this?: "))
for i in range(b):
c = int(raw_input("Input Number: "))
if b == 0:
print 'Zero'
if b < 0:
print 'Less than zero'
else:
print 'Greater than zero'


Or, you can use range(num1,num2), as well.

for i in range(2,10): # This goes from 2 to 10

t3h_m013
Jun 29, 2005, 04:55 AM
hi, if I spent a while catching up, would i be ok to join, i've worked through the first 3/4 lessons messing around here and there (making a program to work out factors of a number, then failing to make a program to work out common fators of 2 numbers :P)

i have a few questions here and there, but as im so behind should i PM them to you gingerbread man?

i hope thats ok and ill spend a fair amount of time getting up to speed in the next couple of weeks.

btw, my programing experience is: tiny bit of html :S:S and a year of "decision maths" at college... heh, i.e. prettyn much nothing.

Gingerbread Man
Jun 29, 2005, 05:40 AM
t3h - anyone of any skill level can join at any time. At the moment there are no structured lessons, rather people go through the lessons, and ask questions when they need help.

No question is too simple or too obvious to ask! No need to PM me, just post all your questions here.

Thanks for dropping in, and most of all have fun.

t3h_m013
Jun 30, 2005, 05:06 AM
the 2 questions i had from the first few lesson were...
a) is there a way of stopping the entire calculator program thing crashing when you devide something by 0?

b) is there a way of making the program assume a .0 at the end of an integer, as on the calculator program it rounds, i assume unless you tell it to devide by .0 integers?

other than that, ill let you know when ive got a fair way through the lessons

Chieftess
Jun 30, 2005, 06:01 AM
the 2 questions i had from the first few lesson were...
a) is there a way of stopping the entire calculator program thing crashing when you devide something by 0?

b) is there a way of making the program assume a .0 at the end of an integer, as on the calculator program it rounds, i assume unless you tell it to devide by .0 integers?

other than that, ill let you know when ive got a fair way through the lessons

1 - Sort of. Us an if statement to say if divisor == 0
2 - From what I've seen, I'm not sure. I really don't like how Python automatically handles datatypes. :)

t3h_m013
Jun 30, 2005, 01:38 PM
thanks... yea, i guess i couldve worked out the == 0 thing really, damn my poor problem solving skills :P

btw, love the fact that i dont post for about a year then when i get back your avatars... the same but a lot more out of date :P

t3h_m013
Jun 30, 2005, 06:53 PM
just a quick question (im having another go at the common factors program:P) can you have an if that is dependant on more than 1 statement...?

vbraun
Jun 30, 2005, 08:36 PM
So no one has tried my blackjack game?

warpstorm
Jun 30, 2005, 08:46 PM
1 - Sort of. Us an if statement to say if divisor == 0


Or a try statement, it is faster in Python (but not in most languages)

Gingerbread Man
Jun 30, 2005, 09:52 PM
a) is there a way of stopping the entire calculator program thing crashing when you devide something by 0?
This is something I haven't actually taught. Python has inbuild error handing, using try and except:

try:
num = input("Divide 7 by what? ")
print 7/num
except ZeroDivisionError:
print "That division is impossible"

You can replace ZeroDivisionError with the name of the error that you want to respond to, just type except: to deal with all errors, or you can put multiple errors in a tuple if you want more than one (e.g. except (NameError, ZeroDivisionError):).

b) is there a way of making the program assume a .0 at the end of an integer, as on the calculator program it rounds, i assume unless you tell it to devide by .0 integers?

I haven't taught this either. use the float function, which turns a string or integer inside the brackets into a floating point (i.e. a number with fractions). e.g.:

float(56) # will return 56.0
float("5677568.678") # will return 5677568.678 as a number instead of a string

this is useful, because the input function lets the user refer to variable names, etc inside the program, which is not what you want when they should be typing in a number. you could use int(raw_input("give me an integer: ")) to return an integer, and not work on anything else. Again, use try and except to deal with times when a number is not typed in.

Gingerbread Man
Jun 30, 2005, 09:53 PM
So no one has tried my blackjack game?
doing it now.

EDIT: Its great! comments coming...

vbraun
Jun 30, 2005, 10:11 PM
Just to let you know, that isn't my most up to date file. This one (that's attached) fixes a few problems (mainly cosmetic things) and also adds an early betting system.

Gingerbread Man
Jul 01, 2005, 06:07 AM
I like it a lot. A few comments, though:
[list]
Put a comment at the beginning of every function or class definition, briefly saying what it is/does, what the inputs are, and what it outputs at the end of it. this can be as simple as:

def shuffledeck(deck, times):
# returns: shuffled deck
# inputs: deck - list of cards; times - num of times to shuffle

Also, it is great to see that you are using everything that you've learnt to acheive this game. I do think, however, that you could slice off up to 100 lines of code by using more simple methods. I'll post my attempt at a blackjack game eventually, and demonstrate that good programming technique is where you never have to write the same thing twice.

Aphex_Twin
Jul 01, 2005, 06:26 AM
how good is Python at math functions? Is it capabile of reading/writing files in binary form? Can it memory map files? Perhaps a little too much to ask ;)

Jamesds
Jul 02, 2005, 12:54 PM
This is very good! I have amateur/intermediate experience in Java, VB, JavaScript, BASIC and C/C++ (though not so good on the latter). I cannot guarantee that I can come on regularly, but I will learn this in my own time when I can.

Thanks GBM for the cool lessons!

warpstorm
Jul 02, 2005, 03:36 PM
how good is Python at math functions? Is it capabile of reading/writing files in binary form? Can it memory map files? Perhaps a little too much to ask ;)

Python is a full powered language. Of course it can do all or those trivial things.

JG99_Korab
Jul 04, 2005, 04:58 AM
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

vbraun
Jul 04, 2005, 12:07 PM
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 used Linux. But I can't back up that claim.

Timeeee4
Jul 07, 2005, 09:25 PM
I just got python today, and am new to programing.

I was messing around and wrote a program for the qaudratic formula. At first the results were way off and I realised I forgot to put the "a" in the denominator of "2a" but when I put the a in it says I have an invalid syntax. Any advice would be appreciated.

Works, but answers are wrong:
a = input ("A?")
b = input ("B?")
c = input ("C?")
d = b**2-4*a*c
if d < 0:
print "No Real Solutions"
else:
print "x=",(-b+((b**2-4*a*c)**.5))/2," , ",(-b-((b**2-4*a*c)**.5))/2




Doesn't work:
a = input ("A?")
b = input ("B?")
c = input ("C?")
d = b**2-4*a*c
if d < 0:
print "No Real Solutions"
else:
print "x=",(-b+((b**2-4*a*c)**.5))/2a," , ",(-b-((b**2-4*a*c)**.5))/2a

vbraun
Jul 08, 2005, 12:28 PM
Try changing "2a" to "(2*a)" also make sure you indent properly.

vbraun
Jul 08, 2005, 03:53 PM
Here is a new version of my Blackjack game.
Fixes:
1. Dealer now plays correctly
2. When you get a blackjack you will get 3/2 of the money you bet.
3. Several repeditive things have been made into a function
4. It will no longer give you an error if you enter an invalid character.

Also it's about 30 lines shorter then my last version. There is still some shrinking to do though.

I'd say it's almost done. :)

Timeeee4
Jul 10, 2005, 01:09 PM
Thanks, you are right!

I_pity_the_fool
Jul 11, 2005, 04:35 PM
http://www.pythonchallenge.com/

I think some people here might enjoy this series of puzzles - the first few require simple logic. The rest programs...

thescaryworker
Jul 15, 2005, 11:08 AM
wow, those are hard!

I was just wondering: how do you implant a random number generator into python.

weakciv
Jul 15, 2005, 07:37 PM
@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)

thescaryworker
Jul 16, 2005, 07:06 AM
thanks alot! :)

stgelven
Jul 16, 2005, 10:48 AM
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!

thescaryworker
Jul 22, 2005, 12:15 PM
I'm making a simple combat game, and was wondering why it doesn't work. Plz help.

weakciv
Jul 22, 2005, 12:27 PM
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).

ThePersian
Jul 24, 2005, 05:10 PM
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 :)

Gingerbread Man
Jul 24, 2005, 10:57 PM
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.

Timeeee4
Jul 27, 2005, 10:15 AM
I've been wandering for a little while what the difference is between input and raw_input.

Thanks for any help.

weakciv
Jul 27, 2005, 12:11 PM
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'

Gingerbread Man
Jul 28, 2005, 12:00 AM
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 :)

vbraun
Jul 28, 2005, 09:41 AM
No comments on my updated Blackjack game?

Gingerbread Man
Jul 28, 2005, 09:34 PM
Doing some house cleaning of forgotten posts... sorry for the lateness...
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 (http://www.python.org/doc/2.4.1/modindex.html), you can see any modules which are specific to a platform.

Oh, and Linux rocks ('cept for commercial windows games, e.g. civ :( )
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:
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.

vbraun
Jul 28, 2005, 10:11 PM
Oh, and I love this bit:
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
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! :)

Gingerbread Man
Jul 30, 2005, 11:52 PM
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:

vbraun
Jul 31, 2005, 01:41 AM
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. :)

weakciv
Aug 05, 2005, 09:34 AM
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 (http://diveintopython.org/toc/index.html)

vbraun
Aug 07, 2005, 12:12 AM
@weakciv- Thanks for the link! :)

Gingerbread Man
Aug 07, 2005, 11:16 PM
http://www.pythonchallenge.com/

I think some people here might enjoy this series of puzzles - the first few require simple logic. The rest programs...
Just going through these the other day :eek: They are a real brain workout until you get the gist of the puzzles, and then they slam you with in-depth python knowledge!

This ain't no beginner challenge - but still fun, even with my limited experience.

TyranusBonehead
Aug 09, 2005, 12:43 PM
I'll think about this. I have a ton of coding experience (21+ years), plus some dabling in Python, but not recently. In other words, my Python is one dead snake at this point. Any ideas on what modding projects you guys want to do?

Gingerbread Man
Aug 16, 2005, 12:51 AM
Sorry I missed your post, TB (same initials as a bad disease? Just a coincidence). I hope you enjoy learning about python, as civIV's release approaches.

An interesting quote:
Our team is working around the clock to put the final polish on Sid Meier’s Civilization IV, scheduled for release this November. We’ve truly reinvented this classic game, while keeping true to what you and millions of gamers like you have grown to love. With a brand new 3D engine, built from day one to include dramatically improved multiplayer, modding capabilities that will break new ground in the strategy game world, and the introduction of religion and Great People, Civ IV represents the biggest leap forward in the series. The improvements are many: years of planning and design, evaluation of invaluable feedback from our incredible fans, and our own Civ wish list ensured the implementation of hundreds of significant improvements to the A.I., interface, and game flow. If you don’t mind us saying so, Civ IV looks better than ever, plays as intuitively and impeccably as you’d expect, and lives beyond the box like never before.
Breaking new ground? Can't wait to see what that means!

Zorn
Aug 18, 2005, 04:08 PM
Thanks a lot for this tutorial, GB!
I am currently working on lecture 5.
So far, I have allready written a program that lists all primes up to a number that you can chose. Nothing fancy or special, but the first program I ever did, and I am glad it worked.
I`ll try to work something from every lecture in, what an awesome prime-number finder it will be in the end. :p

Gingerbread Man
Aug 19, 2005, 07:10 AM
Taking the example from Zorn, I have a challenge for you all (if you choose to accept it):
1) Make a program that prints all multiples of a given number
2) create a timer to see how long the operation takes (HINT - import timer)
3) try to make your multiples program faster.
fastest program wins. I'll dig up some nice numbers to test it on - primes, few multiples and many multiples, big and small.

vbraun
Aug 19, 2005, 04:52 PM
Taking the example from Zorn, I have a challenge for you all (if you choose to accept it):
1) Make a program that prints all multiples of a given number
2) create a timer to see how long the operation takes (HINT - import timer)
3) try to make your multiples program faster.
fastest program wins. I'll dig up some nice numbers to test it on - primes, few multiples and many multiples, big and small.
I'll give it a try. :)

IslandFox
Aug 21, 2005, 01:09 AM
Just a quick question-

I'm just reading through the single posts that are linked to in the first post, is this enough, or should I read through this entire topic?

EDIT: :( I can't get this to work at all:

# this line makes 'a' equal whatever you type in
a = raw_input("Type in something, and it will be repeated on screen:")

# this line prints what 'a' is now worth
print a

It works if I copy it in, but as soon as I change "Type in something etc etc" to anything else, it stops working, even if I change it back. What the heck is going on?

Gingerbread Man
Aug 21, 2005, 06:54 AM
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.

SonicX
Aug 21, 2005, 08:33 AM
Taking the example from Zorn, I have a challenge for you all (if you choose to accept it):
1) Make a program that prints all multiples of a given number
2) create a timer to see how long the operation takes (HINT - import timer)
3) try to make your multiples program faster.
fastest program wins. I'll dig up some nice numbers to test it on - primes, few multiples and many multiples, big and small.I made my first program that does just that, but I don't know how to include a time.

Can I post the code or should I pm the code to you ?
I'm a rookie, so it ain't that good, I just have all the multiples sorted and printed and an endline stating how many there were.
On a larger number like "86925841319772000" nothing happens though :(

vbraun
Aug 21, 2005, 11:12 AM
On a larger number like "86925841319772000" nothing happens though :(
Try waiting longer, that is a very large number and will take ahille to process.

SonicX
Aug 21, 2005, 11:20 AM
Ah ok.
Thanks...
Can you please explain how to include a timer ? I know my programm won't win it for sure, so I'm willing to share it :)

vbraun
Aug 21, 2005, 11:23 AM
This page might help: http://www.python.org/doc/2.4/lib/module-timeit.html

BTW, when I said awhille I meant a halfhour plus depending on your system and how you have it coded. :eek:

SonicX
Aug 21, 2005, 11:27 AM
I'll PM the code :)

vbraun
Aug 21, 2005, 11:55 AM
Did you mean to pm it to me? I think pming it to GM would be better. ;)

SonicX
Aug 21, 2005, 12:11 PM
Yea, but he's offline and I think you know enough to judge whether this was a reasonable attempt ;)
So yes, PM'd it to you :)

vbraun
Aug 21, 2005, 12:33 PM
Well yours is a whole lot cleaner and shorter then mine. Then again my variables arn't simply labeled "a". For example "current_number" is equal to the number that the loop is on.

Also there are a bunch of things you could do to make it faster. :)

SonicX
Aug 21, 2005, 12:38 PM
Ok thanks ... well, I ain't getting into "class" subjects yet, so I'll have to try something else then :)

vbraun
Aug 21, 2005, 12:47 PM
Ok thanks ... well, I ain't getting into "class" subjects yet, so I'll have to try something else then :)
Actually to make it faster just requires some basic math and basic knowledge of multiples.

SonicX
Aug 21, 2005, 02:39 PM
I know what you mean. If you checked divisability by 2 and 3, you can leave 6 out.
If only I could come up with a way to implement that without doing the lost list of numbers over and over for different checks :)

Poisos
Aug 21, 2005, 02:49 PM
Wohooa ... has been a long time since I visited this thread. I had to complete my job training and became occupied with WoW :D.
I will try to catch up with all the "new" posts :blush:.

Anyway ... I started to play with python again and I came across problem. I want the user to choose a directory and a file with a file/directory chooser dialog. I expected a standard implementation at least in Tkinter but I only found some information which at least sounds as if I could use it in connetion with Tcl(-script) ... I don't get it. This does not even seem to be python-code but it's documented in python-documentation:
http://www.python.org/doc/2.2.3/lib/node528.html
http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixDirSelectDialog.htm

In the python-doc shipped with python 2.4 I've red that tixDirSelectDialog is deprecated and that tk_chooseDirectory should be used. But I didn't find a documentation of that class in python-doc.

GBM do you know more about this?? Can somebody help me out?

IslandFox
Aug 21, 2005, 03:22 PM
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.

Supa
Aug 22, 2005, 07:06 AM
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.

wotan321
Aug 25, 2005, 11:53 AM
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?

I_pity_the_fool
Sep 09, 2005, 06:57 PM
Another question:

Is there a python equivalent of PEAR (for PHP) or CPAN (for perl)?

I'd like to see if I can actually read the code.

I_pity_the_fool
Sep 11, 2005, 04:38 PM
Vaults of Parnassus, I suppose. That could easily have been googled.

Grey Fox
Sep 14, 2005, 05:02 PM
I was just popping in to say Ive started the lessons again. Well I started from the begining since I didnt come very far before. (Never took the time)

Anyways, heres a tip for everyone. A list of Python Editors;

http://wiki.python.org/moin/PythonEditors

Grey Fox
Sep 15, 2005, 01:00 PM
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...

Grey Fox
Sep 15, 2005, 11:28 PM
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.

vbraun
Sep 15, 2005, 11:40 PM
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. ;)

bobbobjack
Sep 16, 2005, 11:48 AM
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!

bobbobjack
Sep 16, 2005, 02:23 PM
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!

weakciv
Sep 16, 2005, 02:53 PM
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)))

Grey Fox
Sep 16, 2005, 03:10 PM
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.

bobbobjack
Sep 16, 2005, 06:14 PM
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

bobbobjack
Sep 16, 2005, 06:22 PM
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!

weakciv
Sep 16, 2005, 06:30 PM
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.)

Gingerbread Man
Sep 19, 2005, 09:38 PM
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.

Grey Fox
Sep 19, 2005, 10:13 PM
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.

Python
Sep 20, 2005, 01:00 AM
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: "

Gingerbread Man
Sep 20, 2005, 01:31 AM
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.

I_pity_the_fool
Sep 20, 2005, 08:05 AM
I'll start right away.

Well, before you do, Python presumably has some kind of module to access the XML files, yes? Ought we not to learn about that, if you could spare time to put something together?

Gingerbread Man
Sep 20, 2005, 08:42 AM
Well, before you do, Python presumably has some kind of module to access the XML files, yes? Ought we not to learn about that, if you could spare time to put something together?
Python certainly does have modules to access XML (known as parsers). The problem is that there are two different types! There's the event based one (E.g. do this when this is found), and then there's the heirachial one (like the folders on your computers). Without knowing which approach is taken, to write a lesson for one method could prove a waste of time if the other method is used.

Graphical User Interface (GUI) programming, however, generally shares many concepts, regardless of how it is implemented. I feel it would be less prone to wasted effort and time. If somebody knows some more details on how civIV will work with XML, I'd be happy to write something about it.

Weasel Op
Sep 21, 2005, 08:37 PM
Sweet, we have a team already?
*slaps self*
Count me in :D

btw I know HTML, Java, C, and TI-83 programming :lol: No Python, but I'll fix that soon enough

Python
Sep 23, 2005, 01:25 AM
I'm just looking for a little clarification in this "for" loop(from lesson 7):

for entry in list:

Okay so "for" and "in" always have to be part of every specific loop you write like this, right?

So really I'm just wondering what exactly "entry" and "list" do and what else you could possibly substitute for them to make the "for" loop do something different then arrange, if thats possible?

If someone could clarify this for me that would be great thanks.

Grey Fox
Sep 23, 2005, 01:30 AM
I'm just looking for a little clarification in this "for" loop(from lesson 7):

for entry in list:

Okay so "for" and "in" always have to be part of every "for" loop you write, right?

So really I'm just wondering what exactly "entry" and "list" do?

If someone could clarify this for me that would be great thanks.

Entry means it will step through every Entry in the List, from 0 to X, where X is the last Entry in the List.

For example this list; List = [1, 67, 33, 90, 5, 7]

Every item has an index;

0:1
1:67
2:33
3:90
4:5
5:7

And in the first Lap of the for-loop it will go to index 0, next run to index 1, etc up to the last index which is index 5.

Atleast thats how I think it works.

Python
Sep 23, 2005, 01:41 AM
Okay, so does it look for the first list it see's after it? What I mean is the list doesn't have to be called "list" does it?

e.g.

for entry in list:

(code in between)

countries = ["Canada", "USA", "Mexico"]

or does it have to be

list = ["Canada", "USA", "Mexico"]

for it to recognize what list its sorting out?

Grey Fox
Sep 23, 2005, 01:42 AM
You write it:

countries = ["Canada", "USA", "Mexico"]

for entry in countries:

....nation = countries[entry]
....print nation


and it will print:

Canada
USA
Mexico

Python
Sep 23, 2005, 01:44 AM
Alright I see, thanks.

Gingerbread Man
Sep 24, 2005, 05:41 AM
For the for loop, the only required words are for and in.
entry can be called anything you want. Example:

#create a list of some sort:
year = ["jan","feb","mar","april","may","june","july","aug","sept","oct","nov","dec"]
#then put in in a for loop:
for month in year:
print "month now equals",month

So, as grey fox said, the first time the loop runs, 'month' equals the first item in 'year'. The second time, 'month' equals the second item in 'year', etc. The process is repeated until the loop has been through all items in 'year'.

grumbler
Sep 24, 2005, 06:30 AM
You write it:

countries = ["Canada", "USA", "Mexico"]

for entry in countries:

....nation = countries[entry]
....print nation


and it will print:

Canada
USA
Mexico

Small nitpick, but to avoid confusion, I think it's better to mention: Grey Fox's example should read:

countries = ["Canada", "USA", "Mexico"]

for entry in countries:

nation = entry
print nation

Weasel Op
Sep 24, 2005, 01:21 PM
Lessons 1-3 complete. :cool:
edit:
Lessons 4-5 complete. :cooool:

Gingerbread Man
Sep 25, 2005, 08:15 AM
Small nitpick, but to avoid confusion, I think it's better to mention: Grey Fox's example should read:

countries = ["Canada", "USA", "Mexico"]

for entry in countries:

nation = entry
print nation
actually, more concisely:
for nation in countries:
print nation
mess around with it, and you'll get the gist.

I'll be gone for the next 10 or so days, on a holiday, so sadly that GUI tutorial will have to wait, but that's not to say it won't be coming.

How long is it now, 'till civ? About a month? This is getting exciting!

Weasel Op
Sep 25, 2005, 07:05 PM
Lesson 6 complete :D

vbraun
Sep 26, 2005, 09:32 PM
I've been playing with XML using the Dive into Python book. I now have a simple flashcard program that gets the cards from an XML file.

Right now all it really does is:
1. Can use as many cards as you add.
2. Custimizable labels (for each column)
3. Choose wether you want the first or second column given in the quiz thing.

Later I hope to make it so you can add card within the program so you don't get stuck editing the XML all by your self.

A little note about the XML:
<card id="1">
<Spanish>Hola</Spanish>
<English>Hi</English>
</card>
It really doesn't matter what you call the Spanish and English tabs. If you look at the xml file you will see that there is one like this:
<card id="4">
<a>perezoso</a>
<b>lazy</b>
</card>
It really doesn't make a diffrance.

Anyway here are the files:

Rename flashcards.txt to .py and card.txt to .xml make sure both files are in the same directory. :)

KingSponge
Sep 27, 2005, 03:11 PM
Nice job! I'm really liking the lessons and appreciate the effort. However, I got a bit confused in Lesson 5 with this so I wanted to bring it to your attention for a fix:

#Below is the function
def hello():
print hello
return 1234

#And here is the function being used
print hello()

Which gave me an error. I *think* you wanted: Print "hello" inside the function, with the quotes.

The following also needs to be changed to When the line "Print hello()" was run... because it looks like you're talking about the 'print hello' command inside the function instead of the line actually calling the function.

So what happened?
1) When the line 'print hello' was run, the function 'hello' was executed.


Thanks again and good job!

sekong
Sep 27, 2005, 04:14 PM
Do we have a clue about which part of the game we could mod?
Does python gives us a power of changing the game behaviour, or
just changing some parameters... or I may ask how is a python
toll enable us to change the game more than a EDITOR do?( I assume so,
otherwise, why not just give us an editor?)

Amesjustin
Sep 27, 2005, 04:23 PM
Do we have a clue about which part of the game we could mod?
Does python gives us a power of changing the game behaviour, or
just changing some parameters... or I may ask how is a python
toll enable us to change the game more than a EDITOR do?( I assume so,
otherwise, why not just give us an editor?)

http://www.civfanatics.com/civ4/info/#Customization

chriseay
Sep 29, 2005, 10:31 AM
Really late adopter here. I started last night and finished up through lesson 4, and am most of the way through lesson 5. This really is an excellent tutorial, well written and easy to understand. Thank you!!

My programming knowledge is in C++ (two years in high school, over 5 years since I used it), basic (elementary school!!), a little dabbling in html and something else in elementary called logo, though I remember none of it and am not even sure if that was the real, or commonly used name.

Python seems very much like C++ and basic so far, so I'm having a pretty easy time. We'll see how I progress though.

Weasel Op
Sep 29, 2005, 11:13 AM
My programming knowledge is in C++ (two years in high school, over 5 years since I used it), basic (elementary school!!), a little dabbling in html and something else in elementary called logo, though I remember none of it and am not even sure if that was the real, or commonly used name.
:dubious: High school? ELEMENTARY????? I had to wait til college! :mad:

Welcome to CFC!!! [party]

chriseay
Sep 29, 2005, 11:23 AM
:dubious: High school? ELEMENTARY????? I had to wait til college! :mad:

Welcome to CFC!!! [party]

Yeah, elementary school. I was in the gifted program. We did bunches of crazy stuff that most people didn't get to do in school. I actually got to play Civ 1 and Simcity 2000 as projects. A friend of mine made a paper and pencil game loosely based off of civ. It was a great program. Then our high school had both intro, and then AP computer science. No programming in college though, as I have my B.A. in History.

Thanks for the welcome!! :beer:

Amesjustin
Sep 29, 2005, 11:54 AM
I am with you Weasel Op. I was in the GATE program as well, but I am so old they didn't offer any programming classes when I was a wee tot. I did take keyboarding and office computing in HS, but that was all they had. I also had an old Tandy keyboard/computer you hooked up to a TV when was about 12 or so. Took some programming classes in college - the rest I taught myself or learned on the job. Been doing it professionally for over 7 years now.

Gosh I feel old now :(

Oh, and back on topic - started the lessons myself. Hope to have them done as well as a side project in it by Civ4, but I am getting hitched on 10/16, and will be in Hawaii for the remainder of the month, so time will be short.

I_pity_the_fool
Sep 29, 2005, 02:14 PM
No programming in college though, as I have my B.A. in History.

That's a co-incidence - so does Soren Johnson.

Modifiable
Sep 29, 2005, 03:01 PM
My last programming experience was BASIC on my Apple IIC. I use computers all the time, I just got away from programming. I don't know why you'd want to provide a free tutorial in programming for me, but thank you very much. I find Python to be very easy to learn. What about XML? Where do I go to learn that?

weakciv
Sep 29, 2005, 03:39 PM
My last programming experience was BASIC on my Apple IIC. I use computers all the time, I just got away from programming. I don't know why you'd want to provide a free tutorial in programming for me, but thank you very much. I find Python to be very easy to learn. What about XML? Where do I go to learn that?

www.w3schools.com

KingSponge
Sep 30, 2005, 10:02 AM
I am with you Weasel Op. I was in the GATE program as well, but I am so old they didn't offer any programming classes when I was a wee tot. I did take keyboarding and office computing in HS, but that was all they had. I also had an old Tandy keyboard/computer you hooked up to a TV when was about 12 or so. Took some programming classes in college - the rest I taught myself or learned on the job. Been doing it professionally for over 7 years now.

Gosh I feel old now :(



You and me both. I actually wrote programs on a punch card system (http://en.wikipedia.org/wiki/Punched_card) in HS until my senior year when we finally got a DEC mainframe. We used to have to walk around with these big stacks of cards held together by rubber bands and if the thing ever fell and got out of order....ouch!

Of course, I had my faithful Atari 400/800 at home to mess with BASIC if I wanted to. The old Atari magazines would print complete games in pages and pages of code that you could type in for a free game. :crazyeye:

Anyway, still working on this excellent Python tutorial. Just started with lesson 8, Classes. :)

Modifiable
Sep 30, 2005, 02:36 PM
Thank you for the link to XML tutorial. It is excellently helpful. I'm working on lesson 7 and have just completed creating a text adventure. This actually worked! So, I've completed lesson 7 now and I'm moving on to lesson 8. I can't remember when I was last this excited to be learning something. Again my thanks to the Gingerbread Man for taking all the time and effort to post these tutorials and to the rest of you for helping out as well.

Modifiable
Oct 02, 2005, 03:44 PM
I completed lessons 8 & 9, and while I can't say that I'm completely comfortable with classes, I get the idea and think with practice I'll be alright. I'm having problems on lesson 10. I'm trying to use the open() function. Everytime I try it returns an error saying there's no such file. Obviously I'm doing something wrong. Here's the way I've done it (though I've tried pretty nearly every combination I could think of.)

openfile = open('c:\python23\bard.txt', 'r')

Now I've tried leaving out the .txt, the c: the ' ' s I'm not sure what I'm doing wrong. If anyone can enlighten me I would appreciate it.

grumbler
Oct 02, 2005, 04:32 PM
Modifiable, double the backslashes, i.e.

openfile = open('c:\\python23\\bard.txt', 'r')

The backslash (\) character is used to escape characters that otherwise have a special meaning, such as newline, backslash itself, or the quote character. (http://www.python.org/doc/current/ref/strings.html)

Hope that helps. :)

Modifiable
Oct 02, 2005, 05:11 PM
That worked perfectly. Thanks for the help! :)

bundy
Oct 04, 2005, 08:38 AM
I don't know much about moding, but would be able to mod resource to be countable. (so that with one oil resource you can have 20 modern armors or 5 carriers) That would be amazing! It does not seems to hard to mod.

Would you be able to mod that only town with airport can hold airplanes

Weasel Op
Oct 04, 2005, 08:49 AM
Those should be fairly simple to do.

Grey Fox
Oct 04, 2005, 09:39 AM
I don't know much about moding, but would be able to mod resource to be countable. (so that with one oil resource you can have 20 modern armors or 5 carriers) That would be amazing! It does not seems to hard to mod.

Would you be able to mod that only town with airport can hold airplanes

Even tho this is probably gonna be pretty simple to do, I think you will need the SDK to do it. And know some c++.

warpstorm
Oct 05, 2005, 07:17 PM
Even tho this is probably gonna be pretty simple to do, I think you will need the SDK to do it. And know some c++.

And you may have a major job on your hands getting the AI to do something useful with your changed rules.

Gingerbread Man
Oct 05, 2005, 07:22 PM
Yeah, I reckon that adding features won't be too hard by the sound of what Firaxis will be giving us control over.

Getting the AI to work with it, however, is another story. Python is probably too slow for AI purposes, meaning we need to wait for the SDK.

Gingerbread Man
Oct 05, 2005, 10:58 PM
For those who are interested, and haven't seen it yet, I found a link to this article on slashdot:
http://www.gamecloud.com/article.php?article_id=1614
Can't wait for this SDK to come out! We'll be able to mod everything but the graphics engine and the basic civ core, so the article tells us.

I wonder what they mean by the core civ part? As in the map and grid, units, and turns? Or is it more/less? What form will this SDK be in? Hopefully Firaxis has a fan-chat when they release the game, because I'll be trying to leech as much information off them as possible...

Modifiable
Oct 09, 2005, 04:16 PM
So, I've finished the 11 tutorials posted here. I want to again say thanks for the obvious work that went into creating them. I've also been researching Python programming and I have a question. Nothing I've seen gives any indication of how graphics are handled with Python. I know cIV will have its own graphics engine, do we have any idea of how to use Python to address those graphics? What about sounds? How do I make Python do the fun multimedia stuff in other words?

vbraun
Oct 09, 2005, 04:22 PM
I'll be gone for the next 10 or so days, on a holiday, so sadly that GUI tutorial will have to wait, but that's not to say it won't be coming.

Its coming just wait. :)

Weasel Op
Oct 09, 2005, 04:28 PM
So we can do graphical programming in Python? :drool:
I thought that would have to be done in the SDK.

Grey Fox
Oct 09, 2005, 06:12 PM
So we can do graphical programming in Python? :drool:
I thought that would have to be done in the SDK.

Yup, I tried doing some myself, but I couldnt get the images to show. :P

But I did create windows with buttons and title etc.

vbraun
Oct 09, 2005, 06:14 PM
But I did create windows with buttons and title etc.
Tutorial Link? :D

Grey Fox
Oct 09, 2005, 06:19 PM
Tutorial Link? :D

I think I used the help in IDLE, or a link I got from the Help file. Was a while ago.

Ginger_Ale
Oct 09, 2005, 06:21 PM
I searched through this thread - I didn't find a clear cut answer. For a small text game I am making, how do I get a random number (I want a random number between -.5 and .5)?

I tried "import random" in the beginning and then my line is "number = random.randrange(-.5,.5)" (according to Python.org's docs), but that didn't work.

vbraun
Oct 09, 2005, 06:26 PM
Try random.randint(-0.5,0.5,0.1)

Where -0.5 is start, 0.5 is stop, and 0.1 is the step.

EDIT: NVM, This won't work...

Edit2:
Try ((random.randint(1,10)/2.0)-0.5)

Edit: Its actually: ((random.randint(0,10)/10.0)-0.5)

Weasel Op
Oct 09, 2005, 06:40 PM
He will get it right eventually... :p
That last one looks right, if it works like Java.

Ginger_Ale
Oct 09, 2005, 06:52 PM
The last edit #3 worked, thanks. Almost done with it. :)

JG99_Korab
Oct 10, 2005, 02:57 AM
Well, What is exactly python going to be good for? I don't think it is fast enough for graphics. I guess there will be some people here who know and are learning C++ which I am one of them who will be able to help with more of the graphics part.

Weasel Op
Oct 10, 2005, 10:08 AM
I'm learning C, so I should be able to learn C++ easily enough.

vbraun
Oct 10, 2005, 12:24 PM
Well, What is exactly python going to be good for? I don't think it is fast enough for graphics. I guess there will be some people here who know and are learning C++ which I am one of them who will be able to help with more of the graphics part.
The entire interface will be written in Python...