Cant hide move lines

Cant hide move lines

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

Moderator: Moderators

Post Reply
User avatar
Floris
Posts: 611
Joined: 04 Jan 2011, 20:00

Cant hide move lines

Post by Floris »

Code: Select all

local function SetupCommandColors(state)
	local alpha = state and 1 or 0
	local f = io.open('cmdcolors.tmp', 'w+')
	if (f) then
	
		f:write('move  0.5 1.0 0.5 ' .. alpha)
		f:close()
		Spring.SendCommands({'cmdcolors cmdcolors.tmp'})
	end
	local f = io.open('cmdcolors.tmp', 'w+')
	if (f) then
	
		f:write('unitBox  0 1 0 ' .. alpha)
		f:close()
		Spring.SendCommands({'cmdcolors cmdcolors.tmp'})
	end
	os.remove('cmdcolors.tmp')
end

The code above: 'unitBox' gets properly hidden, 'move' wont.

(also: is it possible to just open 'cmdcolors.tmp' just once and write multiple times?)
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Re: Cant hide move lines

Post by zwzsg »

http://www.lua.org/manual/5.2/manual.html#pdf-io.open

Code: Select all

    "r": read mode (the default);
    "w": write mode;
    "a": append mode;
    "r+": update mode, all previous data is preserved;
    "w+": update mode, all previous data is erased;
    "a+": append update mode, previous data is preserved, writing is only allowed at the end of file.
So don't use "w+".

And yeah, would make more sense to have a single open with two writes.

I suppose you will need to write("\n") between the two lines though.
User avatar
Floris
Posts: 611
Joined: 04 Jan 2011, 20:00

Re: Cant hide move lines

Post by Floris »

The addition of the \n fixed it for the move cmd, and also worked for the combination of the 2 writes :-)


THANKS!
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Re: Cant hide move lines

Post by jK »

Don't create a file for that.
There is a UnsyncedCtrl callout that takes the files content as input instead of a filename.
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Re: Cant hide move lines

Post by zwzsg »

jK means you should do something like:

Code: Select all

local function SetupCommandColors(state)
   local alpha = state and 1 or 0
   Spring.LoadCmdColorsConfig('move  0.5 1.0 0.5 ' .. alpha)
   Spring.LoadCmdColorsConfig('unitBox  0 1 0 ' .. alpha)
end
Post Reply

Return to “Lua Scripts”