Jump to content

hacking script/net/*.lua in DCSWorld, how to debug script error?


Recommended Posts

Posted

hi guys

In DCS A-10C I know I can monitor the lua script output or script error in %userprofile%\savedgames\dcs warthog\log\dcs.log

 

but I'm unable to get any lua output or msgs of lua syntax error in dcs.log under DCSW.

 

How can I get such log message in DCSW?

 

Many thanks

overpro = I'm not good at Nintendo Mario and always get "Game over" pretty fast, so over~~pro

Posted

I tried to "hook" the OutputDebugString message but the messages are totally identical with the contents in dcs.log

overpro = I'm not good at Nintendo Mario and always get "Game over" pretty fast, so over~~pro

Posted
hi guys

In DCS A-10C I know I can monitor the lua script output or script error in %userprofile%\savedgames\dcs warthog\log\dcs.log

 

but I'm unable to get any lua output or msgs of lua syntax error in dcs.log under DCSW.

 

How can I get such log message in DCSW?

 

Many thanks

 

Ok, I just got back from a long vacation, so I am a little behind.

 

Could you be a little more specific as to what the problem is?

Is it only Lua syntax errors that are unreported? Is it only Scripts/net mods that are effected?

 

Anyway, I do think I remember an error reporting problem with dofile I noticed back in May. IIRC, you can solve it by changing the way dofile works:

 

-- insert this script before you use dofile
function dofile(fname) -- replaces the old dofile
local f = io.open(fname, 'r')
if f then
	local fs = f:read('*all')
	if fs then
		local func, err = loadstring(fs)
		if func then
			func() -- maybe could use pcall for any runtime errors, if that is an issue too?
		else
			print('dofile syntax error in file "' .. fname .. '", error: ' .. err) -- if the loadstring failed, err is the error message.
		end
	else
		print('dofile error: unable to read file "' .. fname .. '"!') -- I donno if this would ever happen...
	end
else
	print('dofile error: unable to open file "' .. fname .. '" for reading!')
end
end

 

Anyway, I hope to get back to Lua and testing this weekend, and I will probably notice whatever problem you are having pretty quickly as I adapt Slmod to DCS: World. I'll keep you updated.

Intelligent discourse can only begin with the honest admission of your own fallibility.

Member of the Virtual Tactical Air Group: http://vtacticalairgroup.com/

Lua scripts and mods:

MIssion Scripting Tools (Mist): http://forums.eagle.ru/showthread.php?t=98616

Slmod version 7.0 for DCS: World: http://forums.eagle.ru/showthread.php?t=80979

Now includes remote server administration tools for kicking, banning, loading missions, etc.

Posted

Thanks speed,

The problem is lua runtime error or syntax error in Scripts/net mods are unreported in dcs.log.

To be precise: if I tried to import a module like this in server.lua:

 

local socketHttp =  require("socket.http")
socketHttp.TIMEOUT = 5

if lua can't find socket.http then the value change of .TIMEOUT would fail because socketHttp is nil. this runtime error can be logged in dcs.log in dcs a10c, but in dcsw there is nothing ( I checked dcs.log and net-server.log ).

 

So I created my own log file in main.lua and inserted quite a lot of debug log output in server.lua to see which piece of code introduced the error, like this:

in server.lua:

#some code
#some code
#some code
myDebugLog( "section 1 executed")
#some code
myDebugLog( "section 2 executed")#some code
#some code
myDebugLog( "section 3 executed")

by using this stupid method I finally found the erroneous code.

 

The scripts/net mods are loaded during dcs.exe multiplayer start up, if there are any issues in there then the "network speed" drop down list in "options" windows will be empty.

 

Once the scripts are loaded then the scripts functions runtime error( errors in server.on_connect() or events.on_kill() ) can be seen in dcs.log.

Anyway, I feel a little bit pain to debug script error with dcsw.

overpro = I'm not good at Nintendo Mario and always get "Game over" pretty fast, so over~~pro

Posted (edited)

I have not had a problem getting Lua runtime errors to report, at least after the script has been initially loaded. Runtime errors in the initial loading of the script do not report though.

 

However, the way that the server module is being loaded has changed somehow. ED has been upgrading the net gui, and somehow in the process, things have gotten a little borked with error reporting. So yea, if you have a compilation error, it won't be reported.

 

It is easy to debug though... just make yourself a test function, or use this one I made:

-- insert this script at the beginning of Scripts/net/main.lua
function testfile(fileloc)
local f = io.open(fileloc, 'r')
if f then
	local fs = f:read('*all')
	if fs then
		local func, err = loadstring(fs)
		if func then
			local success, err = pcall(func)
			if not success then
				print('LUA RUNTIME ERROR!!! File "' .. fileloc .. '" contains a runtime error: ' .. err)
			else
				print('SUCCESS! File "' .. fileloc .. '" contains no syntax or runtime errors')
			end
		else
			print('LUA SYNTAX ERROR!!! Syntax error in file "' .. fileloc .. '", error: ' .. err) -- if the loadstring failed, err is the error message.
		end
	else
		print('WTF ERROR!!! Unable to read file "' .. fileloc .. '"!') -- I donno if this would ever happen...
	end
else
	print('ERROR! INVALID FILE! Unable to open file "' .. fileloc .. '" for reading!')
end
end

 

So, for example, I created a Lua error in Scripts/net/server.lua. Then I pasted the above function into the top of Scripts/net/main.lua, and below that, I put:

 

testfile('./Scripts/net/server.lua')

 

I put a "print('testing 123')" statement into server.lua, and also created a Lua runtime error by trying to index a nil value. This is what I see in dcs.lua now:

00000.174 UNKNOWN ?: testing 123
00000.174 UNKNOWN ?: LUA RUNTIME ERROR!!! File "./Scripts/net/server.lua" contains a runtime error: [string "-- Server hooks..."]:181: attempt to index global 'a' (a nil value)

 

It is important that you run this code at the beginning of Scripts/net/main.lua, BEFORE require('server') is requested.

 

Kind of annoying to work around, but not world-shattering.

Edited by Speed

Intelligent discourse can only begin with the honest admission of your own fallibility.

Member of the Virtual Tactical Air Group: http://vtacticalairgroup.com/

Lua scripts and mods:

MIssion Scripting Tools (Mist): http://forums.eagle.ru/showthread.php?t=98616

Slmod version 7.0 for DCS: World: http://forums.eagle.ru/showthread.php?t=80979

Now includes remote server administration tools for kicking, banning, loading missions, etc.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...