Python or other scripting language for simple AI?

Hey folks,

Was wondering if there is a way to invoke python scripts from java for simple AI scripting? I’m not planning on doing any sophisticated AI, just simple stuff.I would like to do it in python to cut down on code.

I want to do something along these lines:



//java code ...
entity.tick(){

     //invoke python script...
     //python script updates entity variables...
}

for (Entity e : entities){
     
     e.tick();
}


I something like this possible, where I can update java class variables from a python script? Or maybe there is another scripting alternative that can accomplish this? Any tips or links to tutorial resources appreciated!

Check out Jython. There are many scripting alternatives for the JVM, or JavaScript is built in. You can even live-compile Java. This is great if you want to let users edit stuff. However, IMO this will not cut down on code, because you’ll be adding loads of boilerplate and a great deal of complexity. If it’s just for you, I’d stick with Java - it isn’t that much more verbose. :wink:

I checked out Jython and the setup is not worth the time/complexity. Oh well, I’ll stick to java. Thanks for the reply. :slight_smile:

If you’re looking for a plugin framework, PF4J is basic and expandable, and most of the other ones (like JPF) are either old, or bloated.

Using python for this could work, but you should check out Lua. It’s great.

I use Luaj 5.2 build. You can inject code into the environment, run entry functions, and call scripts whenever you want. These scripts run on the calling thread, not a new one. It perfectly fits your scenario.

Thanks, guys/gals, for the advice. I’ll look into those options and see if they’re a good fit for me!