Python Plugin for C-Script

Posted By: Cellulaer

Python Plugin for C-Script - 12/30/03 07:49

First Beta version of GSPython.dll is now available. You can write Python code inside your c-script files.

At the moment the only thing you can pass back and forth between Python and Acknex are strings.

Any feedback would be appreciated.

Download Now

Example:

Code:
 
include <gspython.wdl>;

// Define a string for you to use. I default it to 1000 characters here.
string MyPythonString[1000];

text python_txt
{

layer = 1;
pos_x = 50;
pos_y = 50;
strings = 1;
font = standard_font;
string = MyPythonString;
alpha = 100;
flags = narrow, transparent, visible;

}

function EvaluatePython() {

dll_handle = dll_open("GSPython.dll");

// Fill our test string with something
str_cpy(MyPythonString,"123");

// Create and Initialize the Python Engine
Python_Init();

// Link MyPythonString to a string variable defined in Python named AckNexStr.
// Changes to one effect changes to the other.
Python_LinkStr("AckNexStr",MyPythonString);

// Evaluate code.
Python("

# Print goes nowhere right now
print 2+2

# Test the Acknex<->Python string interface
AckNexStr.Value = AckNexStr.Value + '456' + AckNexStr.Value

");

// Free the Python Engine
Python_Free();

dll_close(dll_handle);

}



Posted By: Orange Brat

Re: Python Plugin for C-Script - 12/30/03 08:01

Why exactly would someone use Python? Just curious, I don't really know much of anything about it. I know Gamespace uses it, so I should probably learn about it. This will be yet another reason.
Posted By: Cellulaer

Re: Python Plugin for C-Script - 12/30/03 08:21

I don't know the Python language either. However, from what I've seen it does give you a lot of options for accessing databases, the file system, data processing, data manipulation, OS information, etc. If you already knew Python it would probably be useful verses having to learn c-script (if/when I get the other Acknex objects accessable via the plugin in Python). Bottom line is that it gives you a lot of the power of C++ or Object Pascal in a scripting language embedded in c-script.

Another example would be that I also have an Object Pascal plugin which functions similarly to the Python plugin (has an Object Pascal interpreter). Personally since I program in Object Pascal all the time it is most benificially to be able to write Object Pascal script right inside my c-script files. I ran read/write INI files, the registry, and whatever else I can think of without having to re-compile a DLL every time. Plus there is support for types, classes, and objects.

Lastly with both languages in the above examples it would allow the user to easily MOD source code for whatever game you distributed (if you allowed them to) via a standardized language. You could have a group of effects files written in Python and the user could add their own effects files (I don't know if c-script can be used in this fashion at design time).

Implimenting Python was requested by a couple users so it wasn't more than the work of a few hours to do.
Posted By: HeelX

Re: Python Plugin for C-Script - 12/30/03 09:17

Someone asked today how to write a filemanager / explorer in 3D with A6 and the answer referred to the SDK. Within Python and your plugin you get the access to all needed functions and features you need to write something like this.
Posted By: clone45

Re: Python Plugin for C-Script - 12/30/03 11:18


Holly poop! That's SO cool! Might I ask how you did it? I had considered doing a similar thing for Perl, but it didn't seem like the 3dGameStudio SDK was going to "talk" with my Perl created .dll correctly. It kept saying "Not a GameStudio DLL" (or something similar).

Gracias.
- Bret
Posted By: Cellulaer

Re: Python Plugin for C-Script - 12/30/03 11:47


Delphi has a Python interface available for it here. I haven't as of yet seen a Perl interface for Delphi.

I'm currently working on implimenting Python access to Entities.
Posted By: Templar

Re: Python Plugin for C-Script - 12/31/03 03:15

now that's coooool!
Posted By: tesanders

Re: Python Plugin for C-Script - 01/01/04 10:22

Having used Python on a number of projects, (one of the ACM's electronic journals, two modest game titles, and countless CGI scripts), I'm thrilled to hear that someone's working on this. I always thought Python would make for an excellent scripting language for 3DGS.
Posted By: Cellulaer

Re: Python Plugin for C-Script - 01/14/04 08:27


Released GSPython v0.91 *BETA*

Added the ability to link Acknex Entities and Particle as Python objects. You can also call custom WDL functions from inside Python.

dllfunction Python_LinkEnt(VarName, VarEntity);
// VarName is the name of the Python variable you are creating.
// VarEntity is the Acknex entity you are linking it to.
// Everything is support except .link.
// Access .min[0..2] with .min0, .min1, .min2
// Access .max[0..2] with .max0, .max1, .max2
// Access .skill[1..48] with .skill1, .skill2, etc.

dllfunction Python_LinkPar(VarName, VarParticle);
// VarName is the name of the Python variable you are creating.
// VarParticle is the Acknex particle you are linking it to.
// Everything is support except .link. and .bmap
// Access .skill[1..4] with .skill1, .skill2, etc.

Posted By: Cellulaer

Re: Python Plugin for C-Script - 01/17/04 07:52


Released GSPython 0.92 *BETA*. Also added the source code for download.

Now supports (in Python):
*Entities
*Strings
*Textures
*Bmaps
*Fonts
*Texts
*Panels
*Views
Posted By: JetpackMonkey

Re: Python Plugin for C-Script - 02/15/06 23:33

I need to do a lot of string operations with the Python plugin, but when I run it,
I get an error, like "Module import error: Datetime not found."

Any ideas?

I get it with both 6.314 and 6.22, but the demo program which came with the python plugin works as a standalone app.

I've also got python 2.4.2 installed on my machine separately-- I don't know whether or not that would make a difference.

It's excellent that you have made this available, cellulear!!! I'm surprised more people aren't using it/talking about it, because string processing would be much more difficult without it.

Best wishes
Posted By: poke_smot

Re: Python Plugin for C-Script - 02/16/06 22:54

Hi,
its been awhile(early A6) but i experimented alot with this plugin.
Quote:

I get an error, like "Module import error: Datetime not found."



In dev mode all imported modules had to be in the bin folder.
Not sure how this would work in the current version of A6 since there is no longer a bin folder, perhaps the acknex_plugins.
For a published file the modules had to be in the app folder.
By plain default with gsPython.dll you need datetime.pyd
It took me a long time to figure this all out( when i was messing with it datetime.pyd was not included with the demo, that only happened after i told him what i found)

It was/is? a cool plugin because you can do alot of stuff.
I managed to make pop3 connections to check email with 3dgs.
There were some problems that the plugin didn't support everything python actually does.
Posted By: Anonymous

Re: Python Plugin for C-Script - 02/17/06 00:18

Wow, you are fantastic Cellulaer! Python is used for making primitive games in Blender, and in causal relationships in Blender too!

You're the most underrated person I've seen on here, all these dlls you make would give me scripting nightmares!
Posted By: Ambassador

Re: Python Plugin for C-Script - 02/17/06 06:44

Quote:

Python is used for making primitive games in Blender, and in causal relationships in Blender too!




Primitive? I would say that blender logic brick system is used for making so called 'primitive' games. With python you can make almost any kind of game in blender.
© 2024 lite-C Forums