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

Importing a module

Started by Firnagzen, 05 August 2013 - 07:25 AM
Firnagzen #1
Posted 05 August 2013 - 09:25 AM
Um… How do I go about doing this? I'm a native Python coder, so I'm quite unfamiliar with Lua, but I'm trying to use the flow API.

I have flow saved as 'flow' in the root directory of the turtle.

My test program is as such:

local flow = require "flow"
flow.setPos(0,0,0)
flow.setWaypoint("home")
flow.setWaypoint("there", 10, 1, 0)
flow.goto("there")

However, it throws me a test:1 attempt to call nil.
Cranium #2
Posted 05 August 2013 - 10:52 AM
Split into new topic.

ComputerCraft does not implement require in its code, and instead uses os.loadAPI(pathToAPI).
So If you are wanting to use that API, try this:

os.loadAPI("flow") --#"flow" is the absolute path to this API, so if you placed the API inside a folder, be sure to include that.
flow.setPos(0,0,0)
flow.setWaypoint("home")
flow.setWaypoint("there", 10, 1, 0)
flow.goto("there")
Firnagzen #3
Posted 05 August 2013 - 08:23 PM
Ah, I see. So the ComputerCraft OS isn't exactly Lua.
Lyqyd #4
Posted 05 August 2013 - 08:29 PM
No, there are a few minor differences and gotchas, like the os.loadAPI instead of require. Another thing to note is that your program must yield occasionally, which is not a problem for most programs (nearly all if not all turtle calls yield, as do read, sleep, os.pullEvent, etc.).