My draw function is not working correctly.
A example of my file formate
Spoiler
My load function
Spoiler
My draw function
Spoiler
And then at the very top I have
Spoiler
Posted 06 August 2015 - 03:57 PM
Posted 06 August 2015 - 04:37 PM
Posted 06 August 2015 - 08:15 PM
Posted 06 August 2015 - 08:22 PM
function readFile(path)
local handle = fs.open(path, "r")
local data = textutils.unserialize("{" .. handle.readAll() .. "}")
handle.close
return l.layers
end
for a,b in pairs(layers) do -- layers[a] == b. So you don't need to do layers[a] end
sX = sX + x - 1 -- Replace this with local offsetX = sX + x - 1Otherwise you are just overwriting sX every time. If that isn't breaking your code then the fact that lua tables start at 1, whilst your numbers start at 0 will - so color lookup ends wrong.
colors[x] -- can be replaced with 2^x -- (Or 2 ^ (x-1) if you start at 1).
Edited by SquidDev, 06 August 2015 - 08:24 PM.
Posted 06 August 2015 - 08:46 PM
Posted 06 August 2015 - 09:58 PM
function draw(layers, sX, sY)
for a, b in pairs(layers) do
for y=1, #layers[a].bgColors do
for x=1, #layers[a].bgColors[1] do
term.setCursorPos(sX + x, sY + y)
if not layers[a].bgColors[y][x] == -1 then
term.setBackgroundColor(2 ^ layers[a].bgColors[y][x])
end
term.setTextColor(2 ^ layers[a].textColors[y][x])
if tonumber(layers[a].text[y][x]) == nil or layers[a].text[y] == nil or layers[a].text == nil then
term.write(layers[a].text[y][x])
else
term.write(" ")
end
end
end
end
end
Posted 06 August 2015 - 10:37 PM
Posted 07 August 2015 - 12:32 AM
Posted 07 August 2015 - 06:49 AM
je06, on 07 August 2015 - 12:32 AM, said:
--if not layers[a].bgColors[y][x] == -1 then if layers[a].bgColors[y][x] ~= -1 then
if layers[a].bgColors[y][x] ~= -1 then term.setBackgroundColor(2 ^ layers[a].bgColors[y][x]) else term.setBackgroundColor(2 ^ 15) -- the black color end
--if layers[a].bgColors[y][x] ~= -1 then -- term.setBackgroundColor(2 ^ layers[a].bgColors[y][x]) --else -- term.setBackgroundColor(2 ^ 15) -- the black color --end term.setBackgroundColor(2 ^ (b.bgColors[y][x] == -1 and 15 or b.bgColors[y][x]))
Posted 07 August 2015 - 09:29 AM
Posted 07 August 2015 - 04:53 PM
Edited by je06, 07 August 2015 - 07:54 PM.
0 members, 1 guests, 0 anonymous users