PDA

View Full Version : Debugging



Bidmaron
December 28th, 2010, 23:12
I am trying to debug some initialization code before you can enable the console in the chat window. Is there a way to activate the console programmatically? Or is there a better way to debug?

Bidmaron
December 29th, 2010, 00:26
Also, I have some cleanup code I need to perform when the system shutsdown. I have tried putting the code in the module's onClose function, but it appears that the Module code package is inaccesible then. My latest idea is to attach a handler to the onModuleUpdated event of the Module package and then see if we are deactivating with getModuleInfo. I keep getting a script error ("unexpected symbol near '=') on the handler declaration line. I am doing the declaration in the initialization code of the module lua file. I have tried all the following with the same result:

Module.onModuleUpdated("Monitor")=CheckUpdate;
onModuleUpdated("Monitor")=CheckUpdate;
Module.onModuleUpdated(Monitor)=CheckUpdate;
onModuleUpdated(Monitor)=CheckUpdate;

Anyone have any ideas what I'm doing wrong or have a better idea of how to do my module cleanup code?

EugeneZ
December 29th, 2010, 01:43
I haven't done much FG2 customization, but based on my experience with lua and other languages, it seems like what you're suggesting makes sense but you are attaching the handler in an odd way. You're "invoking" the handler and then trying to assign a value to the result of that invocation: onEvent(param) = CheckUpdate. This doesn't make sense to me, I suggest trying something like this:


Module.onModuleUpdated = CheckUpdate;

Then in CheckUpdate:


function CheckUpdate(name)
if name == 'Monitor' then
...
end
end

Bidmaron
December 29th, 2010, 03:55
Of course, you are right. Thanks. My question still remains about invoking the console programmatically, however.

Bidmaron
December 31st, 2010, 12:24
Bump.
For those of you who are FG2 coding demi-gods -- does anyone know the FG2 shutdown process well enough to know how I could tap my module termination code into that such that my code executes before the module is unloaded? As I said, the onClose event appears to occur after module data unload and any call to the Module code package at that point is failing. I think the cleanest way is to log an event handler on some main database node that gets updated as the program closes (of course, the problem with this is that the technique won't work when the module is running on a client). Since the code must also work on the client, I need something that works in either host or client mode (although if I needed to do two different things, I could easily do so with IsHost check).

Moon Wizard
January 5th, 2011, 20:31
You can use the print function to output messages to the console.log file, even when the console is not open.

There are 3 module events that you can register handlers for: onModuleAdded, onModuleUpdated and onModuleRemoved.

If the module is on the host or installed locally on a client, the onModuleUpdated event will be called when the module is unloaded; otherwise, the onModuleRemoved event is called.

The only code I've seen that tracks closing is the code for onWindowClosed which remembers last window position and zoom.

Regards,
JPG

Bidmaron
January 8th, 2011, 08:39
Well, I could swear that when I open the console using /console, anything I printed before I opened the console doesn't show up (i.e. it always opens empty unless there is a script error that forces the window open without using the /slash command.

drahkar
January 8th, 2011, 09:13
It doesn't show up in the console but I think it still gets stored to the log file.