Python scripts: python installation instructions

DeletedUser

Guest
This guide is written for people who want to be actively involved in off-line grepolis maps/tools generation using Python but have no experience with the Python programming language. It tells you how to get your python programming environment up and running (based on windows XP).

edit on 12.11.2010: I have changed to python 2.6.

Installing python

Step 1: Get the python language from here. Make sure you get version 3.1.2 for your operating system, because version 3 is not backwards compatible with version 2 and the scripts are written in python version3.

edit on 12.11.2010: I have changed to python 2.6.


Step 2: install python on your PC. You now should have a python 3.1 entry in the start > programs menu(start button). One of the items in the menu is IDLE (python GUI).

Step 3: Open IDLE. A windows appears. This window is called the "python shell". It is the window in which python will display error messages and all text that is printed from a program. You can use this to debug the program.

Step 4: After the prompt (>>>) write print ('Hello world') and press the enter key. The text Hello world should now be added on the next line. If it does you have succesfully installed python.

step 5: Check if the command print is displayed in pink, and the printed
line in blue. If not, check the settings in options > configure > highlighting.


Installing pygame

This is to install additional libraries for making nice graphics. Pygame is normally used for making games, but you can use it for a lot of graphics applications.

step 1: Get pygame from here. Make sure you get pygame 1.9.1 for your operating system.

Step 2: Install pygame on your PC.

Step 3: Open the python shell and type "import pygame" (enter) after the prompt. If you get a new prompt on the following line it means that you succesfully have installed pygame.

Writing and running python programs

From the python shell select file > new window. A new window appears. This is the window you will write your programs in. You run the programs with run > run module. Try printing Hello World with your first(?) python program.


Remarks

Python programs/scripts are saved as .py files. These files are normal text files. You will notice that double clicking on a .py file will run the program. However this is not recommended because the links with pygame are not properly configured if you run the program this way. Always start with opening IDLE.


The map making program

The program consists of the following area's of code (when this changes this text will be updated):

1: Import commands. These commands add additional commands to the standard python list of commands.

2: Variables. Here the variables are defined. Variables that need to be used in definitions are defined as "global".

3: Definitions. These blocks of code start with "def". After "def" the name of the definition is written. If you use this name somewhere else in your program the piece of code with that name is executed. A definition can return a value, if so they are called a function.

4: Main program. Here the actual program starts. The first two commands are to initialise pygame (to create the map) and TKinter (to create the user interface, i.e. the window with buttons and stuff).

The next couple of lines of code are for preparing the buttons and select lists etc. Next you see the commands to initialise the map window and load the world data from local files and then the program enters a loop waiting for a button to be pressed. If so the "def" named after "command" is executed.


-----------

Remarks:

I have filed a request to make a sub-forum in order to make threads for individual program possibilities (like loading data, making world maps, making ocean maps, calculating distances etc.) At the time of this writing I do not know whether this request will be granted.

Since posts have a max limit of 10.000 characters I will post my code in separate posts. You need to copy/paste each part into the window where you write your code (obviously in the right order).

Have fun!
-----------
 
Last edited by a moderator:

DeletedUser

Guest
i have a problem....
the version 1.9.1 of pygame ask me fo the version 2.4.1 of python...
i have the 2.7.1 and 3.1.3 installed...
but cant find the 2.4.1 version...lol

any help?
 

DeletedUser

Guest
ok....found it....lol
didnt realized that t was diferent version dowload....:)
 

DeletedUser

Guest
hi...where can i find the code?
I will be one of your stdent if you dont mind:)
 

DeletedUser12950

Guest
Little knowledge

I'm beginning with this program and I still not understand how it works. Someone give me a detailed explanation please.:p
 
Top