Problems with onModNetMessage?

mikeejimbo

Chieftain
Joined
Jan 16, 2010
Messages
65
OK, I can't seem to get this message passing to work at all. In my CvEventManager I have the following defined:

Code:
def onBeginGameTurn(self, argsList):
       'Called at the beginning of the end of each turn'
       iGameTurn = argsList[0]
       CvTopCivs.CvTopCivs().turnChecker(iGameTurn)
		
       CyMessageControl().sendModNetMessage();

and this

Code:
	def onModNetMessage(self, argsList):
		'Called whenever CyMessageControl().sendModNetMessage() is called - this is all for you modders!'
		iData1, iData2, iData3, iData4, iData5 = argsList
		
		CyInterface().addImmediateMessage('Message Received',None)

		print("Modder's net message!")
		
		CvUtil.pyPrint( 'onModNetMessage' )

So I expected to see "Message Received" every turn, but I do not. I imagine I just don't know how to use this function.
 
Did you use addEventHandler to register your onModNetMessage() function for the event? I don't recall if CvEventManager already has a handler registered.
 
You don't provide any argslist, so I am relatively certain that it is throwing you a python exception each turn telling you that your function call doesn't match up, and you have python exceptions turned off.

Use this instead:

CyMessageControl().sendModNetMessage(1, 1, 1, 1, 1)


Also, C++ uses the ; to end a line. Python does not, it uses the carriage return. So I am REALLY certain that you don't have python exceptions enabled.
 
You don't provide any argslist, so I am relatively certain that it is throwing you a python exception each turn telling you that your function call doesn't match up, and you have python exceptions turned off.

Use this instead:

CyMessageControl().sendModNetMessage(1, 1, 1, 1, 1)

Oh yeah! Good point, that's probably it.

Also, C++ uses the ; to end a line. Python does not, it uses the carriage return. So I am REALLY certain that you don't have python exceptions enabled.

Whoops. I thought that in Python, ending a line with a semicolon meant "suppress the output"

Wait, no, I'm thinking of another language. Never mind. The weird thing is that I have other lines that ended in semicolons that worked just fine, though. I think I copied it from some other section of code and just left them in.
 
I think you can use a semicolon to put two statements on the same line, but don't quote me on that.
 
Semicolons are optional. The right number of arguments is required. *Please* turn on python exceptions and check for errors before asking for help. Also, you may find it helpful to look at working examples; there is a parallel thread with some suggestions.
 
The right number of arguments is required.

This does make sense, however, I have seen working examples that don't supply arguments at all. Specifically I'm thinking of the official GodsOfOld mod, which uses sendModNetMessage( ).

I will turn on Python exceptions, then. That sounds helpful.
 
I actually leave Python exception popups off because they make debugging more difficult. Each line of the stack trace appears in a separate alert window, and if you get a lot in a loop, you're stuck force-quitting the game.

Instead, turn on the Logging system so that all exceptions are written out to Logs/PythonErr.log. This is more useful because a) you don't need to remember what he popup said, b) you can easily copy-n-paste it into a forum post, and c) the game doesn't freak out trying to display alerts. The downside is that you must create a habit of checking that file or you'll miss them.
 
Each person may have their own preference. With popups disabled, you don't know you have a problem. I use both popups and logging, so that the popup tells me I have a problem, and the logfile lists all the text.
 
I skimmed the thread again, but I didn't see any update after adding those arguments. Does it still do nothing? Add some logging messages with pyPrint() so you know your code is being reached or not.
 
I skimmed the thread again, but I didn't see any update after adding those arguments. Does it still do nothing? Add some logging messages with pyPrint() so you know your code is being reached or not.

Yeah, I turned on logging and turned off hide exceptions. Supplying all five arguments has worked thus far. I am, somehow, having problems with my tech chooser screen, but the exceptions are in files that I haven't even supplied for this mod, so it seems like it might be unrelated. And if I continue to have problems with it, it'd be best to open a new thread.

My sincere thanks for all your help, everyone.
 
Still, that does mean my question is answered.

Oops, I misread that as "isn't answered" and was asking what question that was. Glad it's working! :goodjob:
 
I am, somehow, having problems with my tech chooser screen, but the exceptions are in files that I haven't even supplied for this mod.

I have had this specific problem many times. I do not have the exact message text handy. If it is going to happen, it happens as soon as you "reload python modules" in game. Thereafter, whenever you bring up the tech chooser, a cascade of these alerts appear, making the game unplayable. I have spent a little time to try to track it down, but never succeeded. It has something to do with the fact that "reloading python modules" re-initializes these objects. Apparently the tech chooser object does not like being re-initialized and stops working.
 
I have had this specific problem many times. I do not have the exact message text handy. If it is going to happen, it happens as soon as you "reload python modules" in game. Thereafter, whenever you bring up the tech chooser, a cascade of these alerts appear, making the game unplayable. I have spent a little time to try to track it down, but never succeeded. It has something to do with the fact that "reloading python modules" re-initializes these objects. Apparently the tech chooser object does not like being re-initialized and stops working.

It did happen immediately after re-loading modules, which explains why it worked again when I closed the game and reopened it.
 
Back
Top Bottom