Jump to content




[SOLVED] Weird Bug


  • You cannot reply to this topic
2 replies to this topic

#1 ReBraLaCC

  • Members
  • 100 posts
  • LocationSublime Text 2

Posted 30 June 2016 - 03: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 by ReBraLaCC, 30 June 2016 - 04:21 PM.


#2 Dog

  • Members
  • 1,179 posts
  • LocationEarth orbit

Posted 30 June 2016 - 04: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 by Dog, 30 June 2016 - 04:20 PM.


#3 ReBraLaCC

  • Members
  • 100 posts
  • LocationSublime Text 2

Posted 30 June 2016 - 04:21 PM

View PostDog, on 30 June 2016 - 04:19 PM, said:

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!





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users