lua script outside a game

lua script outside a game

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

Post Reply
User avatar
prandipadaro
Posts: 98
Joined: 19 Oct 2011, 22:38

lua script outside a game

Post 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?
User avatar
Floris
Posts: 611
Joined: 04 Jan 2011, 20:00

Re: lua script outside a game

Post by Floris »

because its not a widget, your lua code shows it is a gadget


use widget: instead of gadget:
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7049
Joined: 16 Nov 2004, 13:08

Re: lua script outside a game

Post 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.
User avatar
prandipadaro
Posts: 98
Joined: 19 Oct 2011, 22:38

Re: lua script outside a game

Post 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?
User avatar
Silentwings
Posts: 3720
Joined: 25 Oct 2008, 00:23

Re: lua script outside a game

Post by Silentwings »

Iirc you only have access to the filesystem within your spring datadir, using relative paths.
User avatar
prandipadaro
Posts: 98
Joined: 19 Oct 2011, 22:38

Re: lua script outside a game

Post 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?
User avatar
prandipadaro
Posts: 98
Joined: 19 Oct 2011, 22:38

Re: lua script outside a game

Post by prandipadaro »

now I understand
maybe
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Re: lua script outside a game

Post by Forboding Angel »

Use relative paths :-)
User avatar
prandipadaro
Posts: 98
Joined: 19 Oct 2011, 22:38

Re: lua script outside a game

Post by prandipadaro »

Forboding Angel wrote:Use relative paths :-)
what do you mean?
abma
Spring Developer
Posts: 3798
Joined: 01 Jun 2009, 00:08

Re: lua script outside a game

Post 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
Post Reply

Return to “Lua Scripts”