Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
  • 0
Heavy Cat

component help

Question

6 answers to this question

Recommended Posts

  • 0

Okay. I think I understand whats going on. You're used to ComputerCrafts' global api system. In CraftOS(Computercrafts default OS), if you want to load a library you call os.loadAPI "myLibrary" and any program executed after that call can access 'myLibrary.myfunction'. OpenOS, and most Lua environments, use the 'require' function to access and load a library within a program. Here's and example.

You must use require in each individual file loading a library respectively.

This means that if file 'A' used require to load the library 'myLib', file 'B' will also have to require 'myLib' itself to access it.

-- # Load the 'component' library. Libraries are usually stored in /lib
local component = require("component")
-- # Get the computer 'component'. Like a CC peripheral handle. This is the device api and not the library.
local computer_device = component.getPrimary("computer") -- # this device api has the 'stop' method.
-- # Shorthand for getting the primary component.
local computer_device = component.computer

-- # I'd recommend using the computer library. 
-- # This api wraps the primary computer 'component' with some handy methods that are nicer to use.
local computer = require("computer")

-- # With device api
-- # Stop the primary 'computer' component. This is most likely 'this' computer.
computer_device.stop()

-- # With the computer library. Comment out the above call to computer_device.stop to test this method.
computer.shutdown(false) -- pass boolean true to reboot.

I hope this is helpful. Look HERE for documentation. Beware some of this doc is out of date :/

Share this post


Link to post
Share on other sites
  • 0

Well, i have never laid a big finger on CC (not at all for a few years), i just assumed if it worked in the lua interpreter it would in the custom programs too.

but thanks anyway, i think this will help

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.