This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
ReBraLaCC's profile picture

[SOLVED] Weird Bug

Started by ReBraLaCC, 30 June 2016 - 02:57 PM
ReBraLaCC #1
Posted 30 June 2016 - 04:57 PM
So I am trying to make a Rubik's Cube in CC and done some tests with the rendering of the pieces, something weird i found out was that if a launch the code first time it works great

And the second time I do it, it renders the cubes in black color (if i reboot the computer it works again)

Maybe there is something wrong with the code so that's why i've posted it here


w,h = term.getSize()
colors = {colors.white,colors.green,colors.yellow,colors.red,colors.blue,colors.orange}

local function renderCube(side)
for k,v in pairs(cube[side]) do
   drawPiece(cube[side][k],k)
end
end

function drawPiece(var,nPiece)
if nPiece == 1 then
   paintutils.drawFilledBox(w/2-2-5,h/2-2-2,w/2-2-2,h/2-2,var)
elseif nPiece == 2 then
   paintutils.drawFilledBox(w/2-2,h/2-2-2,w/2-2+3,h/2-2,var)
elseif nPiece == 3 then
   paintutils.drawFilledBox(w/2-2+5,h/2-2-2,w/2-2+8,h/2-2,var)
elseif nPiece == 4 then
   paintutils.drawFilledBox(w/2-2-5,h/2-2+2,w/2-2-2,h/2-2+4,var)
end
end

for a = 1,100 do
drawPiece(colors[math.random(1,6)],1)
drawPiece(colors[math.random(1,6)],2)
drawPiece(colors[math.random(1,6)],3)
drawPiece(colors[math.random(1,6)],4)
sleep(0.04)
end
Edited on 30 June 2016 - 03:21 PM
Dog #2
Posted 30 June 2016 - 05:19 PM
You're overwriting the colors api on line 2 and your variable isn't localized. That's why it might work once, then not again until a reboot. Rename your colors table to something other than colors…and it would probably be good to go ahead and localize w, h, and whatever name you settle on for your colors table.
Edited on 30 June 2016 - 03:20 PM
ReBraLaCC #3
Posted 30 June 2016 - 05:21 PM
You're overwriting the colors api on line 2. Rename your colors table to something other than colors…and it would probably be good to go ahead and localize w, h, and whatever name you settle on for your colors table.

Works! Thanks!