Yiv 321 Posted April 16, 2014 Share Posted April 16, 2014 Dear community, I have done a small gui (for testing) and I have a function inside: def UpdateRK(self, val): self.rklable.SetText(val) I also added a packet which is sent from server and received by binary and I want to add inside the receive function a call of this python function with one argument (string). How can I mange it? Regards Link to comment Share on other sites More sharing options...
Premium Sanchez 2474 Posted April 16, 2014 Premium Share Posted April 16, 2014 You can easily call a function from binary: PyCallClassMemberFunc(m_apoPhaseWnd[PHASE_WINDOW_GAME], "UpdateRK", Py_BuildValue("(i)", 15)); UpdateRK - Name of your event(i) - The Py_BuildValue() Function15 - Value what you want to push (Sure you can use variables too) Example with a variable: int pushThis = 15; PyCallClassMemberFunc(m_apoPhaseWnd[PHASE_WINDOW_GAME], "UpdateRK", Py_BuildValue("(i)", pushThis)); 1 Link to comment Share on other sites More sharing options...
Yiv 321 Posted April 16, 2014 Author Share Posted April 16, 2014 But now the function has to be in game.py, doen't it? I have the function in an other file named uitestgui.py. What's now? Regards 1 Link to comment Share on other sites More sharing options...
Premium Sanchez 2474 Posted April 16, 2014 Premium Share Posted April 16, 2014 You can pass the value to that py or just use constInfo. Example: 1. Make a new variable in constInfo and name it to RKvalue 2. Paste this to your py: def OnUpdate(self): if not self.rklable.GetText() == str(constInfo.RKvalue): self.rklable.SetText(constInfo.RKvalue)Add this function to game.py: def UpdateRK(self, val): constInfo.RKvalue = val 1 Link to comment Share on other sites More sharing options...
Yiv 321 Posted April 16, 2014 Author Share Posted April 16, 2014 Hm.. Can I do a function with a return-value which I can call via python? Something like GetRKValue()? Regards Link to comment Share on other sites More sharing options...
Premium Sanchez 2474 Posted April 16, 2014 Premium Share Posted April 16, 2014 Sure: def GetRKValue(self): return constInfo.RKvalue Link to comment Share on other sites More sharing options...
Yiv 321 Posted April 16, 2014 Author Share Posted April 16, 2014 No, I mean that this function takes the value of a variable in Source. I saw something like "player.GetAlignmentData()" in uicharacter.py but I don't know how I should return the variable. Regards Link to comment Share on other sites More sharing options...
Premium Solution Sanchez 2474 Posted April 16, 2014 Premium Solution Share Posted April 16, 2014 1. Open PythonPlayerModule.cpp and add this to the static PyMethodDef s_methods[]: { "GetRK", playerGetRK, METH_VARARGS }, 2. Now still in PythonPlayerModule.cpp add this: PyObject * playerGetRK(PyObject* poSelf, PyObject* poArgs) { return Py_BuildValue("i", 15); } Add this to your py: def GetRKValue(self): return player.GetRK() 3 Link to comment Share on other sites More sharing options...
Yiv 321 Posted April 16, 2014 Author Share Posted April 16, 2014 Okay, thank you! Regards Link to comment Share on other sites More sharing options...
Premium Sanchez 2474 Posted April 16, 2014 Premium Share Posted April 16, 2014 One more important thing, do not forget to add this to the begin of your py: import player Link to comment Share on other sites More sharing options...
Yiv 321 Posted April 17, 2014 Author Share Posted April 17, 2014 Yes, I already did Regards Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now