Advertisement
HarvDad

fetch

May 20th, 2014
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. -- Sample program to demonstrate some possible programming techniques
  2.  
  3. usage = "usage: fetch <itemName>"
  4.  
  5. -- Array of items/blocks: name, x, z
  6. -- Pretend this array has hundreds of entries
  7.  
  8. items = {
  9. {"cobblestone", 4, 6},
  10. {"dirt", 4, 7},
  11. {"sand", 4, 8},
  12. {"gravel", 4, 9},
  13.  
  14. {"gold_ore", 5, 6},
  15. {"iron_ore", 5, 7},
  16. {"coal_ore", 5, 8},
  17. {"oak_wood", 5, 9},
  18.  
  19. {"lapis_ore", 6, 6},
  20. {"sandstone", 6, 7},
  21. {"diamond_ore", 6, 8},
  22. {"redstone_ore", 6, 9},
  23.  
  24. {"cactus", 7, 6},
  25. {"clay_block", 7, 7},
  26. {"sugar_cane", 7, 8},
  27. {"pumpkin", 7, 9},
  28. }
  29.  
  30. -- getIndex: Return the array index of the entry containing <name>
  31.  
  32. function getIndex(name)
  33. rv = 0 -- return value
  34. nItems = #items
  35. print("nItems = ", nItems)
  36.  
  37. for i= 1,nItems do
  38. if name == items[i][1] then
  39. rv = i
  40. break
  41. end
  42. end
  43.  
  44. return(rv)
  45. end
  46.  
  47.  
  48. -- Main Program
  49.  
  50. args = {...}
  51. nArgs = #args
  52.  
  53. if nArgs ~= 1 then
  54. print(usage)
  55. return
  56. end
  57.  
  58. itemName = args[1]
  59. index = getIndex(itemName)
  60. if index == 0 then
  61. print("Can't find \"", itemName, "\"")
  62. else
  63. item = items[index]
  64. x = item[2]
  65. z = item[3]
  66.  
  67. print("The ", itemName, " chest is at ", x, ", ", z)
  68. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement