Page 1 of 1
Cant hide move lines
Posted: 09 Apr 2014, 21:46
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?)
Re: Cant hide move lines
Posted: 09 Apr 2014, 21:53
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.
Re: Cant hide move lines
Posted: 09 Apr 2014, 23:02
by Floris
The addition of the \n fixed it for the move cmd, and also worked for the combination of the 2 writes
THANKS!
Re: Cant hide move lines
Posted: 10 Apr 2014, 05:27
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.
Re: Cant hide move lines
Posted: 10 Apr 2014, 05:54
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