Exabyte the Protogen Posted December 19, 2017 Posted December 19, 2017 im making a program, but commands that work in the lua interpreter dont inside a custom program. how do i fix this? Quote
0 Molinko Posted December 19, 2017 Posted December 19, 2017 Your description is a bit vague. Could you post your code with any current errors? Quote
0 Exabyte the Protogen Posted December 19, 2017 Author Posted December 19, 2017 the code that wont work: Component.computer.stop() the error: attempt to index global 'component' (a nil value) Quote
0 Exabyte the Protogen Posted December 19, 2017 Author Posted December 19, 2017 i also tried: stop() computer.stop() Quote
0 Molinko Posted December 19, 2017 Posted December 19, 2017 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 :/ Quote
0 Exabyte the Protogen Posted December 20, 2017 Author Posted December 20, 2017 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 Quote
0 Molinko Posted December 20, 2017 Posted December 20, 2017 All files in the lib folder are accessible by name globally in the lua interpreter. Quote
im making a program, but commands that work in the lua interpreter dont inside a custom program. how do i fix this?