Page 1 of 1

Getting Started with a Logging Gadget/Widget

Posted: 23 Aug 2010, 09:56
by GamerSg
Im trying to build a logging gadget/widget which can log all events in the game. I believe a widget is not suited for this purpose since it cannot be notified of the events of the opposing player.

My approach atm is to use the relevant call ins like gadget:UnitCreated to write to a log file. However i keep getting errors that io is a nil value. I suppose Spring disallows access to the Lua API for gadgets?

Code: Select all

function gadget:Initialize()
	Spring.Echo("UAI Logger Inited")
	Spring.Echo(gadget)
	file = assert( io.open("UAILog.txt", "w") )  --Error:io is nil
end
Can someone guide me on how i can get started for logging?

Re: Getting Started with a Logging Gadget/Widget

Posted: 23 Aug 2010, 10:28
by knorke
Hi
I believe a widget is not suited for this purpose since it cannot be notified of the events of the opposing player.
yes, otherwise cheating would be very easy ;)
As spec or in replays widgets can see everything though.
Can someone guide me on how i can get started for logging?
http://springrts.com/phpbb/viewtopic.ph ... 1&start=42
See the attachment in this post.

I have not tried gagdets yet but as far as I understand you can not just put them in your spring\luaui\widgets folder, they must be bundled into the .sdz of the mod.

Re: Getting Started with a Logging Gadget/Widget

Posted: 23 Aug 2010, 11:17
by GamerSg
Hi knorke

Thanks for your reply. The gadget part is a non-issue as the game is intended to be played internally(locally), so all players will have the gadget installed. I have no problems atm to retrieve information about what the enemy/myself have built. The problem seems to be simply that i do not have access to the io libraries. I get the following error
LuaRules::RunCallIn: error = 2, GameOver, [string "LuaRules/Gadgets/uailogger.lua"]:40: attempt to index global 'io' (a nil value)
stack traceback:
[string "LuaRules/Gadgets/uailogger.lua"]:40: in function 'writeLog'
[string "LuaRules/Gadgets/uailogger.lua"]:50: in function 'GameOver'
[string "LuaRules/gadgets.lua"]:1029: in function <[string "LuaRules/gadgets.lua"]:1027>
(tail call): ?
Just to clarify, im using the Spring:1944 mod. Could it be that io access in Gadgets is prevented by Spring or the 1944 team? Here are the relevant 2 functions

Code: Select all

function writeLog()
	local replayInfo = Game.mapName .. "_" .. Game.modShortName .. "_" .. tostring(game_id) .. "_"
	local file = assert( io.open("Logs\\UAILog " .. replayInfo .. ".txt", "w") )
	for k,v in pairs(log) do
		file:write(v)
		print(v)
	end
	file:close()
end

function gadget:GameOver()
	Spring.Echo("Shutting Down UAILogger\n")
	writeLog()

end

The error occurs at io.open.

Re: Getting Started with a Logging Gadget/Widget

Posted: 23 Aug 2010, 12:59
by BrainDamage
basically, while synced part of gadgets can access the info for the whole map, they cannot do operations that differ from pc to a pc ( direct file access is one, the file could be different between machines ) by design, therefore you cannot access files using the synced part

to do what you want, you need to make the synced part send the data to unsynced, then the unsynced part will write it in a file

Re: Getting Started with a Logging Gadget/Widget

Posted: 23 Aug 2010, 16:09
by AF
an alternative is to replay the game afterwards as a demo and run the widget then with all players in view.

Re: Getting Started with a Logging Gadget/Widget

Posted: 24 Aug 2010, 07:07
by GamerSg
Thanks for the replies. I guess i will go with the widget route then and log it during the replay.

Re: Getting Started with a Logging Gadget/Widget

Posted: 24 Aug 2010, 12:17
by knorke
as the maker of the only partly awesome demonaut* i hope you too want to create awesome game statistics and not make a boring debug tool or something! :)

* http://knorke.net23.net/demonaut.html , http://knorke.net23.net/battlereports