Page 1 of 1

lua script outside a game

Posted: 05 Jun 2015, 22:41
by prandipadaro
i have write a little script

Code: Select all

function gadget:GetInfo()
  return {
    name      = "AIinfo",
    desc      = "get the performance of the ai's",
    author    = "prandipadaro",
    date      = "6/6/2015",
    license   = "GPLv2",
    layer     = -1, 
    enabled   = true -- loaded by default?
  }
end
function gadget:GameOver()
	print(tostring('AIFEEDBACKSTART-AIFEEDBACKSTART-AIFEEDBACKSTART-AIFEEDBACKSTART-AIFEEDBACKSTART-AIFEEDBACKSTART'))
	
	local allTeams=Spring.GetTeamList()
	for i,v in ipairs(allTeams) do
		print(tostring(i),tostring(v))
		local q,w,e,r,t,y=Spring.GetAIInfo(v)
		print(tostring(q),tostring(w),tostring(e),tostring(r),tostring(t),tostring(y))
		if q then
			local max=Spring.GetTeamStatsHistory(v)
			a={}
			local a= Spring.GetTeamStatsHistory(v,max,max)
			print (tostring(a[1].frame))
			print(type(a))
			for k,n in pairs(a[1]) do
				print(tostring(k),tostring(n))
			end
			

		end
		
			
	end
	print(tostring('AIFEEDBACKSTOP-AIFEEDBACKSTOP-AIFEEDBACKSTOP-AIFEEDBACKSTOP-AIFEEDBACKSTOP-AIFEEDBACKSTOP-AIFEEDBACKSTOP'))
end
it works if i put it insida a game BA or ZK
but i need to have it outside a game, avaible for each games
I tried to put it in /spring/luaui/widgets but does not work
any help?

Re: lua script outside a game

Posted: 05 Jun 2015, 23:09
by Floris
because its not a widget, your lua code shows it is a gadget


use widget: instead of gadget:

Re: lua script outside a game

Posted: 05 Jun 2015, 23:15
by zwzsg
Make it a widget.

In addition to placing it in /spring/luaui/widgets/ you also have to replace;
gadget:GetInfo() and gadget:GameOver()
by:
widget:GetInfo() and widget:GameOver()

There's some more differences between gadget and widget, such as what info is available, or that gadget have both synced and unsynced parts while widget only have unsynced.

Some games, and IIRC in particular ZK, disable external widgets. There may be some option well hidden inside nested game menu to allow them.

Re: lua script outside a game

Posted: 07 Jun 2015, 21:59
by prandipadaro
so a new little question
i have write a script in /.spring/LuaUI/widgets
i need to create read and write some file in different paths
so if i use simple:

Code: Select all

local f = io.open("example", 'w+')
f:write('hello')
f:close()
all work fine and spring automatic create file in /.config/spring

but if i try to create a file in a different path:

Code: Select all

local f = io.open('/home/p/.spring/AI/Skirmish/Shard2/dev/ai/soma.lua', 'w+')
f:write('hello')
f:close()
spring give me this error:

Code: Select all

Error in Initialize(): [string "LuaUI/Widgets/aifeedback.lua"]:78: attempt to index local 'f' (a nil value)
anyone can explane me this behavior?

Re: lua script outside a game

Posted: 07 Jun 2015, 22:07
by Silentwings
Iirc you only have access to the filesystem within your spring datadir, using relative paths.

Re: lua script outside a game

Posted: 07 Jun 2015, 22:12
by prandipadaro
Silentwings wrote:Iirc you only have access to the filesystem within your spring datadir, using relative paths.
ok but the path is in the spring datadir
there are a guide that explain how to move between the folders?

Re: lua script outside a game

Posted: 07 Jun 2015, 22:29
by prandipadaro
now I understand
maybe

Re: lua script outside a game

Posted: 08 Jun 2015, 11:08
by Forboding Angel
Use relative paths :-)

Re: lua script outside a game

Posted: 08 Jun 2015, 13:31
by prandipadaro
Forboding Angel wrote:Use relative paths :-)
what do you mean?

Re: lua script outside a game

Posted: 08 Jun 2015, 16:00
by Silentwings

Re: lua script outside a game

Posted: 19 Jun 2015, 17:19
by abma
relative paths = paths not starting with /

i.e. /bla/bla/path is an absoulte path, when bla/bla/path is a relative path.

so for this example
/home/p/.spring/AI/Skirmish/Shard2/dev/ai/soma.lua
this is a relative path which should work:
AI/Skirmish/Shard2/dev/ai/soma.lua