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

Accessing functions from another file

Started by sirlawnsalot, 06 December 2016 - 05:24 AM
sirlawnsalot #1
Posted 06 December 2016 - 06:24 AM
Hi! I would like a little help in calling functions from a separate file. I have done a lot of reading on the subject but to be honest the documentation for lua I have found is a little confusing. Any help I can get in clearing this up would be great. Thank you for your time.


mineFuncts file:

function stairMaker()
print("Current Y Level?:: ")
local yLevel= io.read()
local digCounter = yLevel - 12
local loopCounter = 0
while loopCounter < digCounter do
  turtle.digDown()
  turtle.down()
  loopCounter = loopCounter + 1
  turtle.dig()
  while not turtle.forward() do
   turtle.dig()
   sleep(0.1)
  end

turtle.digUp()
end
end
function shaftMaker()
--future code
end


miner. (main file) – When ran I get attept to call nill line 1.
problem seems to be with the require statement as I get the same error whether or not the function call miner.stairMaker() is in the code.


miner = require("minerFuncts")

miner.stairMaker()

Bomb Bloke #2
Posted 06 December 2016 - 07:34 AM
"require" is not available within vanilla ComputerCraft - instead, os.loadAPI() is used.

http://www.computercraft.info/forums2/index.php?/topic/15052-api-basics/

Frankly, though, my advice is keep everything within the one file, unless you really think you'll be using the extra functions within multiple coding projects.
sirlawnsalot #3
Posted 06 December 2016 - 07:52 AM
Exactly what i was looking for Thanks! I usually write 1 big file but I thought it would be fun to do it a new way lol appreciate it bomb! (got name right this time lol)