Jump to content

Call a python function with binary


Go to solution Solved by Sanchez,

Recommended Posts

  • Bronze

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

  • Premium

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() Function
15 - 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));
  • Love 1
Link to comment
Share on other sites

  • Premium

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
  • Love 1
Link to comment
Share on other sites

  • Premium
  • Solution

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()
  • Love 3
Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.