Python Scripting Tips Offered

EDIT: Doh, I suppose this should be in Game Engine Resources…

Anyway, hello. I thought I’d try posting some tips for scripting in Python. If others have tips, contribution is appreciated.

  • Learn how to use dictionaries; they are invaluable in python. Dictionaries can be used for object positions, for inventories, for a lot of things. Try to learn about dictionaries and lists (splitting and separating lists are also incredibly useful). For example, list[:] makes a copy of the specified list (actually, it’s copying all elements to another variable). Dictionaries can be used as inventories because objects in the person’s inventory can have a name and a specified value (doesn’t even have to be a number, could be a whole other inventory!). For an example of this, inventory[‘Potion’] could give you the number of potions in the inventory, and inventory[‘Money’] -= 1000 would deduct 1000 money from the inventory.
  • If you have objects that are similar, it would be best for them to share resources (namely, functions). For example, rather than giving the Goomba and the Koopa completely different scripts, it would be best for them to share similar behavior. The Goomba and the Koopa can both share a ‘MoveAroundRandomly’ script until they spot Mario, and then the Goomba can run towards him, while the Koopa shoots towards him in a shell. The Flying Koopa and the Flying Goomba can share functions as well.
  • If you have multiple enemies, perhaps you should consider putting them into a single script file (like This way, you can share functions (like MoveTowardsTarget, etc.).
  • Looping through objects given to you in a list (like bge.logic’s getSceneList() or a near sensor’s getObjectList()) is as simple as:
for object in list:     print (

Any other tips?