[SDK] How to access python script data from SDK?

Cybah

Emperor
Joined
Jun 22, 2007
Messages
1,481
I need to know how I can access script data from sdk, a get function would be enough. I need it for an interface modification.

For python I'm using SdToolKitCustom.
 
If I get it right, you have somewhere in python where you wrote self.iData = 4 (or whatever) and then in the DLL you want to have a get function for iData.

The usual way is to expose a DLL function to python, which python then calls with the number as an argument. They are often called set functions. However if you really need to make the DLL request data from python, then you will likely need one of the following:
PHP:
bool callFunction(const char* moduleName, const char* fxnName, void* fxnArg=NULL)
bool callFunction(const char* moduleName, const char* fxnName, void* fxnArg, long* result)
bool callFunction(const char* moduleName, const char* fxnName, void* fxnArg, CvString* result)
bool callFunction(const char* moduleName, const char* fxnName, void* fxnArg, CvWString* result)
bool callFunction(const char* moduleName, const char* fxnName, void* fxnArg, std::vector<byte>* pList)
bool callFunction(const char* moduleName, const char* fxnName, void* fxnArg, std::vector<int> *pIntList)
bool callFunction(const char* moduleName, const char* fxnName, void* fxnArg, int* pIntList, int* iListSize) 
bool callFunction(const char* moduleName, const char* fxnName, void* fxnArg, std::vector<float> *pFloatList)

This means you will then have to call using something like this:
PHP:
CyArgsList argsList;
argsList.add(gDLL->getPythonIFace()->makePythonObject(pyUnit));   // pass in unit class
argsList.add(iAction);
long lResult=0;
gDLL->getPythonIFace()->callFunction(PYGameModule, "isActionRecommended", argsList.makeFunctionArgs(), &lResult);
The last argument is a pointer rather than a value. This means the call will write the return value to lResult, which has to have one of the types from the first list of functions.

If you need more help, then you need to be more specific.
 
Hi,

1. the ScriptData fields (strings) are already available as m_szScriptData / getScriptData()
in the SDK.

2. The SdToolKitCustom seems to encode its stuff with Pickle. To decode the script data string I would suggest to use a C library instead of calling the Python backend, see i.e. https://stackoverflow.com/questions/1296162/how-can-i-read-a-python-pickle-database-file-from-c

Edit: In PAE we will the scriptData fields with json strings instead of encoded stuff. This made it easier to debug/manipulate the content of the script data fields.
 
Last edited:
Top Bottom