Main Menu

API Problem

Started by Fallout, Oct 11, 2023, 03:48 AM

Previous topic - Next topic

Fallout

Despite having programming experience I am having some very painful problems with CC

I am using an Advanced Mining Turtle with an Ender Modem. I have setup the GPS constellation with standard computers and Ender Modems and edited the startup.lua as appropriate for each device. My mining bot can get it's gps location using gps locate. So I think I am all set in that department.

Where I am striking problems.
I have my program and an API saved on disk which I have copied to the root level of the turtle using copy /disk/locale.lua / and I can see locale.lua on the turtle but when I try and get another program to reference it using os.loadAPI("locale") and then call it from my test.lua I get bios.lua:567: Failed to load API locale due to File not found.

What am I doing wrong?

Fallout

#1
I am writing my first lua scripts but I am striking a problem..

I have the line os.loadAPI("locale") in my test.lua main file and when it is run it results in

"bios.lua:567: Failed to load API locale due to File not found."

test.lua and locale.lua are both in the root directory of the turtle.

I have also tried:
local myModule = require("locale")
myModule.subroutinename()

that didn't work either.

Lupus590

Are you sure that it copied to the turtle correctly?

Have you ran ls on the turtle to verify that the file copied with the name that you expect without having the disk connected?

Are you running any OS programs other than the one built into the mod?

QuickMuffin8782

If it says "API not found", then you have a issue loading it from the file directly.

If it is in the root folder, make sure you directly link the file like the example code below.

local function ensureAPILoad(pathToFile)
  if fs.exists(pathToFile) then
    os.loadAPI(pathToFile)
  elseif fs.exists("/"..pathToFile) then
    os.loadAPI("/"..pathToFile)
  else
    error("Couldn't find file, as it doesn't exist. Check your filesystem for more info.", 2)
  end
end

ensureAPILoad("<path>")
"The Blue Blur" - Working on Net Star OS, a new frontier for Red Star OS 3.0
linktr.ee/quickmuffin8782