[Python] Direct access to objects?

For questions about using Classic.

Post » Wed Sep 08, 2010 1:03 pm

[quote="Keeper":25apxpgq]Glad to be of help :P
But remember to organize your code and try to understand/use classes: they can make your life a lot easier![/quote:25apxpgq]
I'm pretty familiar with Python and the concepts of modules, classes, methods, functions and oop. The background for my question was, that I'm coding a system that might be of help for many Constructors, and I want to establish it with the least effort for them as possible. The complete system shall run with no more than two (visible) scripts:

Start of layout:
[code:25apxpgq]
from fancypkgname import attractivemodulename

myclass = attractivemodulename.coolclass(globals())
[/code:25apxpgq]

Always:
[code:25apxpgq]myclass.update()[/code:25apxpgq]

They should not have to alter the code everytime they use it in another project. That was the intention ;)
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Wed Sep 08, 2010 1:26 pm

Nice idea!
You still have to change object names inside your update() if you change them in Construct.
I guess it's only a matter of taste where to reference the global objects.

Following your idea I think Construct should append the project path to sys.path automatically so one can write his own modules in the same directory (or directory structure following python standard __init__.py).

To test the (little) module we discussed in this page I was using this code:
[code:383wvjwf]
import sys
sys.path.append("D:/test")
[/code:383wvjwf]

Also, a bit OT, is there a way to write Construct plugin using python?
B
1
G
2
Posts: 9
Reputation: 643

Post » Thu Sep 09, 2010 7:10 pm

Automatically appending to sys.path would be a convenience. You could also generalize it with

[code:1xjyesjw]
import os
import sys
sys.path.append(os.getcwd())
[/code:1xjyesjw]
On the other hand, when thinking of later uses by other constructors, it might be better to let them just copy the package to Constructpath\Data\Python. This way, everything one might want to use can be found at a central, general place... I made no decision yet.

Writing plugins with Python? I don't think it's possible. The sdk is for use with Microsoft Visual C++/Studio, and embedding Python through C++ (although possible, [url:1xjyesjw]http://docs.python.org/c-api/[/url:1xjyesjw]) would just make it more complicated. But maybe some day one talented programmer creates a python-plugin, a precompiled plugin whose functionality is completely controlled by simple python scripts. I would walk over broken glass if that would help to motivate someone developing it :)
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Previous

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 2 guests