Civ4 Python/import

From Civilization Modding Wiki
Revision as of 12:39, 17 July 2010 by Duha (talk | contribs)
Jump to navigationJump to search

import allow you to add python files to you mod.


How to add popup to the event:

Bad way:
  • Insert popup code to in event.

Big files is hard to read and edit. It is not easy to customize this code and merge to others mod.

Good way:
  • Create file
  • Create function that runs popup (for example: run_popup)
  • edit
    • add string after imports: import
    • and string in event: mymod.run_popup(*args)

It is easy to add / remove this function from mod (just uncomment lines).
It is easy to share this function.
It is easy to call this function in other place. (if yon need it on some event).

import executes script in file (if you have only functions and classes loads them to memory.)

import sintax:

  • import mymod

to access functions use:

  • from mymod import *

to access functions use:

  • from mymod import foo, goo

to access functions use:
foo() or goo()
(some IDE has autocomplite feature and in this way shows only foo and goo.)

  • from mymod import this_is_long_name_function as foo

to access functions use:
(It is good idea to have functions with understandable name)

Import rules:

Use imports at the file beginning!


09 - 'Borrowing' other people's stuff (with modules)