Python External Libraries w/ AI, Speech

This forum is currently in read-only mode.
0 favourites
From the Asset Store
Units do not overlap each other and use different ways if there are several free ways.
  • 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)

    Python External Libraries Part1 (more advanced troubleshooting and AI example)

    Example screenshot:

    <img src="">

    ** New ** Python Libraries Part2: Taking Screenshots with PyQT and PyGTK

    Future tutorials will cover things like joystick control, speech recognition (tbd).

  • Damn, It hink this is awesome. I have yet to try it but it sounds really great.

  • networking (tbd).

    This. Is. Awesome.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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. The .cap was made in Construct .99.82.

    Screenshot generated by the tool:

    <img src="">

    Part2: Taking Screenshots with PyQT and PyGTK

  • 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.

  • 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): ... l#pycrypto

    An alternative would be Ncrypt (get 2.6...):

    Here is an example of how you would use PyCrypto: ... -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!

  • So i'm going through your tutorial part one, coding Python through IDLE, but i can't seem to get the "" script to work. I made the "" script, got it to work through IDLE, made the "" script and typed in " 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.

  • 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.

  • 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 " py2exe" in my "c:\pythonery" directory where i have and, and as soon as i hit enter, Windows7 pops up the "what program would you like to use to open" 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.

  • 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 "" i get this:

    <img src="">

    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.

  • Do you have setuptools installed?

  • Yeah, it comes with the ActivePython install, i believe.

    At least, when i downloaded the package you linked to and i tried installing it, it gave me an error like: "cannot create a directory when one exists already".

  • Err...okay i figured it out. Somehow. This is how i did it.

    So, i had installed ActivePython which set up my file dependancies properly (which the normal distro of python did NOT do, much to my frustration) and it gave me PythonWin, a GUI Python editor.

    I made and for py2exe as per stated in the tutorial, then i made into setup.pyc by opening in PythonWin and clicking "import" which gave this output in PythonWin:

    [quote:2fsxuk02]File "C:\Python26\Lib\site-packages\pythonwin\pywin\framework\", line 427, in ImportFile

    exec codeObj in __main__.__dict__

    File "<auto import>", line 1, in <module>

    File "C:\Pythonery\", line 4, in <module>


    File "C:\Python26\lib\distutils\", line 140, in setup

    raise SystemExit, gen_usage(dist.script_name) + "\nerror: %s" % msg

    SystemExit: usage: [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]

    or: --help [cmd1 cmd2 ...]

    or: --help-commands

    or: cmd --help

    error: no commands supplied

    Then, i could use the command "setup.pyc py2exe" (instead of " py2exe" like it says in the tutorial) and it compiles properly!

    I'm completely new at Python and i kinda feel like i stumbled on this solution, so if someone can explain why it worked, i will be happy.

  • Very bizarre solution! I'm glad it is working.

    When you ran the import command in PythonWin that actually generated an error, but at the same time it byte compiled the file. All a .pyc file is, is a byte-compiled version of the .py file. A byte-compiled version will load faster the next time because the compiling step will be skipped and the code will just be interpreted at runtime. There are some optimization flags that can be used to give a potential speedup in execution as well. If you are interested in massive speedups then look at Psyco which Just-In_Time (JIT) compiles Python code (but it only works on 32-bit systems currently).

    Somehow, by byte-compiling it helped resolve the odd path issues so when you ran the full "setup.pyc py2exe" everything worked fine!

    At some point in the future when I get a Windows 7 system setup properly I'll look into the best way to get this stuff to work.

  • Even though it works better than it did before--even managing to get the AIML example working perfectly as a .py script--i can't seem to get it to compile with py2exe properly. When i compile it and try to run the AIML exe, it says "WARNING: No match found for input: load aiml b" and anytime i try typing, it says the same thing but with whatever i typed in the prompt.

    Mostly, i wanted to learn how to import python into Construct so i can import Pygame and be able to use a joystick with my games. If you can point me in the direction of the libraries i need for that, i would be happy. I would definitely be MORE happy if i could get this whole py2exe thing to work myself, but so it goes.

    I think i may take a break from trying to get libraries to import for now and to try and learn Python on it's own. Thanks for your help and tutorials, though! Much appreciated.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)