Advertisement
flyingfisch

:42: Attempt to perform arithmetic on local 'y' (a nil value)

Jun 1st, 2012
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.27 KB | None | 0 0
  1. local rect = graydraw.rect
  2. local setColor = graydraw.setcolor
  3. local wait = misc.wait
  4. local line = graydraw.line
  5.  
  6. screenWidth = 128
  7. screenHeight = 64
  8.  
  9. key_left = 37
  10. key_right = 40
  11. key_exit = 36
  12. gDoorPosition = {0,0,0}
  13. gDoorActive = 1
  14.  
  15. function main()
  16.     setColor(1)
  17.     menu()
  18. end
  19.  
  20. function menu()
  21.     while not key(key_exit) do
  22.         if key(key_left) then gDoorActive = gDoorActive - 1 end
  23.         if key(key_right) then gDoorActive = gDoorActive + 1 end
  24.         if gDoorActive < 1 then gDoorActive = 1 end
  25.         if gDoorActive > 3 then gDoorActive = 3 end
  26.        
  27.         for i = 1, 3, 1 do
  28.             if i == gDoorActive and gDoorPosition[i] < 30 then gDoorPosition[i] = gDoorPosition[i] + 1
  29.             elseif gDoorPosition[i] > 0 then gDoorPosition[i] = gDoorPosition[i] - 1 end
  30.         end
  31.        
  32.         for ix = 1, 3, 1 do
  33.             garageDoor(ix * 20 + 5, y, 20, 30, gDoorPosition[ix], 5)
  34.         end
  35.        
  36.         refresh
  37.     end
  38. end
  39.  
  40. function  garageDoor(x, y, width, height, position, panelHeight)
  41.  
  42.     rect(x, y, x + width, y + height, 4, 4) --draw garage outine
  43.     rect(x, y, x + width, y + height - position, 4, 0) --draw door
  44.    
  45.     --draw panels
  46.     for iy = height - position, 0, -panelHeight do
  47.         line(x, y + iy, x + width, y + iy, 4)
  48.     end
  49. end
  50.  
  51. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement