Python External Libraries w/ AI, Speech

Post your own tutorials, guides and demos.

Post » Sat Mar 06, 2010 9:33 pm

This is a short tutorial series covering how to add cool features to your Construct games using Python. Specifically, by importing Python external libraries. These libraries such as Pygame, PyGTK, or PyAIML already have large amounts of code that you can import and use easily!

I decided these really don't belong in the adventure game thread, so I'm moving them permanently here.

The quick guide walks you through in about 5 pages how to import and use an artificial intelligence chat engine PyAIML. In doing it, you should be able to import most other libraries using the same steps. The other tutorials cover more in-depth use of the libraries and more advanced troubleshooting techniques.

Python Library Quickguide (concise manual on using external libraries)
http://www.box.net/shared/qe5qxdk7pf

Python External Libraries Part1 (more advanced troubleshooting and AI example)
http://www.box.net/shared/5terpm0jnp

Example screenshot:


** New ** Python Libraries Part2: Taking Screenshots with PyQT and PyGTK
http://www.box.net/shared/9vv23rujfm


Future tutorials will cover things like joystick control, speech recognition (tbd).
B
8
S
3
G
7
Posts: 835
Reputation: 5,313

Post » Sun Mar 07, 2010 1:18 am

Damn, It hink this is awesome. I have yet to try it but it sounds really great.
B
16
S
10
G
5
Posts: 255
Reputation: 3,934

Post » Sun Mar 07, 2010 1:57 am

[quote="scidave":1q9zuqbs]
networking (tbd).[/quote:1q9zuqbs]
This. Is. Awesome.
B
2
S
2
G
2
Posts: 372
Reputation: 1,794

Post » Tue Mar 16, 2010 1:42 am

I've added another short tutorial, this one on using PyGTK to take screenshots. It is quite a bit overkill using PyGTK for this, but still a cool feature to show how easy it is to add the library support. :D The .cap was made in Construct .99.82.

Screenshot generated by the tool:



Part2: Taking Screenshots with PyQT and PyGTK
http://www.box.net/shared/9vv23rujfm
B
8
S
3
G
7
Posts: 835
Reputation: 5,313

Post » Fri Mar 19, 2010 4:01 am

Do you think it's possible to implement an encryption library made in Python to encrypt things like save files outputted to a text file?

Since I'm going to learn Python soon, I was thinking of creating a plugin which created a virtual text file incorporated inside the executable which data can be saved to. But instead of waiting a year before I could even attempt that, using an existing library to encrypt save files and not making them easily editable will be pretty neat.

http://www.freenet.org.nz/ezPyCrypto/
B
2
S
2
G
3
Posts: 143
Reputation: 1,536

Post » Fri Mar 19, 2010 10:36 pm

Yes, it is possible and shouldn't be that hard. Probably around 25-30 lines of Python code to do the encrypting and decrypting.

I'd recommend Pycrypto (get the 2.6):
http://www.voidspace.org.uk/python/modu ... l#pycrypto

An alternative would be Ncrypt (get 2.6...):
http://tachyon.in/ncrypt/

Here is an example of how you would use PyCrypto:
http://www.codekoala.com/blog/2009/aes- ... -pycrypto/

p.s. Feel free to let me know if you have any questions as you try it out. Sometimes there is some trickiness in converting a pure Python solution to a hybrid Python/Construct solution!
B
8
S
3
G
7
Posts: 835
Reputation: 5,313

Post » Tue May 18, 2010 5:36 pm

So i'm going through your tutorial part one, coding Python through IDLE, but i can't seem to get the "setup.py" script to work. I made the "hello.py" script, got it to work through IDLE, made the "setup.py" script and typed in "setup.py py2exe" in the command window but get nothing. No output, no dist directory.

Could it be that i'm running Windows 7? For some reason the py2exe installer wouldn't work unless i made it compatible for WinXP.
B
2
G
3
Posts: 52
Reputation: 954

Post » Thu May 20, 2010 5:27 pm

Unfortunately, I don't have Windows 7 handy to test this out. It sounds like a path problem and somehow Py2exe is not being detected from the path you are trying to run everything from.

I did a quick internet search and couldn't find anybody posting with issues with Windows 7 and py2exe so no help there.

Have you tried running the samples in the py2exe directory? They are typically installed to python26/lib/site-packages. If you cannot get the samples to run right then you definitely have a path problem and need to fix that first.
B
8
S
3
G
7
Posts: 835
Reputation: 5,313

Post » Fri May 21, 2010 3:15 pm

Weird. I solved the path problem...kind of.

I realized that my python path was python2 instead of python26 like it's supposed to be, so i reinstalled python to the new directory. I tried the "setup.py py2exe" in my "c:\pythonery" directory where i have hello.py and setup.py, and as soon as i hit enter, Windows7 pops up the "what program would you like to use to open setup.py?" window. I tried selecting the exe in the py2exe directory but it doesn't do anything.

Not sure where i should go with this. I'd really like to get Python with Construct up and running.

EDIT: Holy hell this is annoying. For some reason, i cannot associate .py files with the Python executable. I think that's why it's not working. If anyone has any ideas, i'm all ears.
B
2
G
3
Posts: 52
Reputation: 954

Post » Fri May 21, 2010 5:19 pm

Okay, so i installed ActiveState which came with PythonWin something or other and now it seems i can actually run .py files from the command prompt. I think that is a step in the right direction. But now, when i run "setup.py" i get this:



GAH! Why can't it just work?

EDIT: Great. So, apparently py2exe is just not working with Python 2.6. Check out the bug tracker here.
B
2
G
3
Posts: 52
Reputation: 954

Next

Return to Your tutorials & example files

Who is online

Users browsing this forum: No registered users and 1 guest