1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

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

Discussion in 'Civ4 - SDK/Python' started by Cybah, Jun 5, 2017.

  1. Cybah

    Cybah Emperor

    Joined:
    Jun 22, 2007
    Messages:
    1,480
    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.
     
  2. Nightinggale

    Nightinggale Deity Supporter

    Joined:
    Feb 2, 2009
    Messages:
    4,129
    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 charmoduleName, const charfxnNamevoidfxnArg=NULL)
    bool callFunction(const charmoduleName, const charfxnNamevoidfxnArglongresult)
    bool callFunction(const charmoduleName, const charfxnNamevoidfxnArgCvStringresult)
    bool callFunction(const charmoduleName, const charfxnNamevoidfxnArgCvWStringresult)
    bool callFunction(const charmoduleName, const charfxnNamevoidfxnArgstd::vector<byte>* pList)
    bool callFunction(const charmoduleName, const charfxnNamevoidfxnArgstd::vector<int> *pIntList)
    bool callFunction(const charmoduleName, const charfxnNamevoidfxnArgintpIntListintiListSize
    bool callFunction(const charmoduleName, const charfxnNamevoidfxnArgstd::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.
     
  3. Ramkhamhaeng

    Ramkhamhaeng Warlord

    Joined:
    Feb 24, 2014
    Messages:
    146
    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: Jun 19, 2017

Share This Page