Advertisement
Guest User

Help me fix what did I do wrong ?

a guest
Oct 6th, 2015
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.25 KB | None | 0 0
  1. -- grid-demo
  2. -- Grid testing.
  3.  
  4. term.clear
  5.  
  6. -- Variables
  7. button_lc = 1
  8. button_rc = 2
  9. exit_  = "q"
  10.  
  11. w,h = term.getSize()
  12.  
  13. -- 3x3 grid
  14. grid = {
  15.     0,0,0,0,0,0;
  16.     0,0,0,0,0,0;
  17.     0,0,0,0,0,0;
  18. }
  19. gridColumnWidth = 6
  20.  
  21. -- Draw the grid
  22. function drawGrid()
  23.     for i=1, #grid do
  24.         term.setCursorPos(1,i)
  25.         term.write( string.rep("*",gridColumnWidth) )
  26.     end
  27. end
  28. drawGrid()
  29. function SetTile(n) grid[ n+#grid ] = 1 end
  30. function DetTile(n) grid[ n+#grid ] = 0
  31.  
  32. term.setCursorPos( (w-string.len("Hold CTRL+T to exit.")) + 1, h )
  33. term.write("Hold CTRL+T to exit.")
  34.  
  35. -- Main program
  36. while true do
  37.     local event, button, x, y = os.pullEvent()
  38.     if(event == "mouse_click") then
  39.         if(button == button_lc) then
  40.              if(x >= 1 and x <= gridColumnWidth and y >= 1 and y <= #grid) then
  41.                 SetTile(x)
  42.              
  43.              --drawGrid()
  44.              term.setCursorPos(x,y)
  45.              term.setTextColour(colours.white)
  46.              term.setBackgroundColour(colours.white)
  47.              term.write("D")
  48.     end
  49.         elseif(button == button_rc) then
  50.             if(x >= 1 and x <= gridColumnWidth and y >= 1 and y <= #grid) then
  51.                 DetTile(x)
  52.            
  53.             --drawGrid()
  54.             term.setCursorPos(x,y)
  55.             term.setBackgroundColour(colours.black)
  56.             term.setTextColour(colours.white)
  57.             term.write("*")
  58.    end
  59.         end
  60.     end
  61. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement