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

Molinko

Members
  • Content Count

    451
  • Joined

  • Last visited

  • Days Won

    35

Posts posted by Molinko

  1. Your error is indeed pretty simple. The method component.get returns the full address of a component, which is a string, not an object(table) with methods. In OC it's called a component proxy. Try this out and feel free to ask more questions either in this thread or via PM.

    local component = require("component")
    local term = require("term")
    local gpu_address = component.get("3085") -- # this returns the components full address from an abbreviated one
    local screen_address = component.get("40c6")
    
    local gpu = component.proxy( gpu_address ) -- # get a 'proxy' to the gpu component
    gpu.bind( screen_address ) -- # call .bind from the proxy

     

  2. Im sorry but this one has me stumped. The error is basically saying that 'br.setActive' is a boolean and not a function. From the wiki we know its  a method that takes a boolean so I dunno WTF is going on here. Maybe a version bug between BR and OC or .... I really don't know, sorry :/ 

  3. To start, components dont really have 'names'. Names aren't unique and we end up with the issue you've mentioned. Components have 'types' and 'addresses'. When using the component library fields like component.flux_gate what is actually happening is the component library is looking up the 'primary' component, really this is just the first component of that type to be found.

    print( component.flux_gate == component.getPrimary('flux_gate') ) -- # this should print 'true'

    To find individual components of a certain type you can call component.list

    local flux_gates = {}
    
    for address in component.list('flux_gate') do
      local gate = component.proxy(address)
      table.insert(flux_gates, gate)
    end
    
    -- or
    
    local gate_iter = component.list('flux_gate')
    local fg1, fg2 = component.proxy(gate_iter()), component.proxy(gate_iter())

     

  4. The documentation for the term library is incorrect with respect to the latest version of OpenOS. Basically the term library will use whichever screen is bound to the tty output. Its a bit confusing personally. I would recommend reading through the term and tty library to see how they are related. But, to answer your question you can use this..

    local component = require "component"
    local term = require 'term'
    local thread = require 'thread'
    local fs = require 'filesystem'
    
    local function getSecondary(ctype)
        local path = '/dev/components/by-type/' .. ctype .. '/1'
        if fs.exists(path) then
            local file = assert(fs.open(path .. '/address', 'r'), 'failed to open ' .. path .. '/address.')
            local address = file:read()
            file:close()
            return address
        end
        return nil, 'no secondary ' .. ctype .. ' component.'
    end
    
    local gpu2 = component.proxy(getSecondary('gpu'))
    gpu2.bind(getSecondary('screen'))
    
    local function Window(dx, dy, w, h, gpu)
        gpu = gpu or term.gpu()
        local window = term.internal.open(dx, dy, w, h)
        term.bind(gpu, window)
        window.as_window = term.internal.run_in_window
        return window
    end
    
    local window = Window(0, 0, 160, 50, gpu2) -- # give window offset & dimensions and gpu proxy.
    local function log(...)
        return window:as_window(print, ...) -- # run print with the tty window as our our window
    end
    
    print "This is on the main screen"
    log "This is on the second screen"

    hope this is helpful..

    Some thing else fun to try and use as well..

    -- # considering the above code..
    -- # take term char input on two screens at once
    
    thread.create(function()
        	window:as_window( term.read ) -- # read input on term 2. blink and all :)
        end)
    
    -- # the windowed term.read will exit either when it returns or if this call returns first closing the above thread.
    term.read() -- # read from main term input.

     

  5. Okay, good thinking. I know it's possible, I just can't remember really how to do it

     

    Drone

    Drones are built using a Drone Case in the Assembler. They are entity-based “robots”, a little cheaper but with more limited functionality. They can not interact with external components!

    They have no secondary storage and so are programmed entirely by using an eeprom. Once assembled, a drone can be reprogrammed by crafting it with a new eeprom (its old eeprom is returned).

  6. It seems like something the file format or encoding is incorrect. This seems like it may be related to the server you're on. First just try a clean install of openOS on a new drive and see if the issue persists. If it does persist, you should bring it up with your server admin.

  7. local file_path = "/home/myFile.txt" -- # path to your file here
    local pattern = "match this" -- # your pattern to find
    local matches = {}
    
    local function contains(str, pattern)
      return string.match(str, pattern) and true or false
    end
    
    for line in io.lines(file_path) do
      if contains(line, pattern) then
        table.insert(matches, line)
      end
    end

    That should get you started. Feel free to ask more questions if you like :) 

  8. That sounds like the OC config. If you're developing outside the game in an editor while the game is open then [by default] the in-game files will not sync with the real filesystem until MC is closed. If you want to save files live outside the game and not have to restart the game you can change the config in .../instances/your_pack_here/config/opencomputers/settings.conf. Set the option to "bufferChanges=false". Be sure to read the disclaimer above the option too.

  9. Ive loaded your script and api and they seem to be working as expected..

    I see the test button and when i click the 'Working.' message is printed.

    I'm not getting your error at all. Perhaps reboot, its possible an older dev version of your 'gButtonAPI3' is or was still loaded when you ran your test.

    if you don't already know, this trick can be helpful while developing apis and testing them as you tweak them.

    package.loaded.myAPInameHere = nil -- # require is idempotent. purge it!
    local api = require 'myAPInameHere'
    
    api.stuff()

     

  10. Okay. I cracked it. I think you're going to have to do some more testing.

    How: Hold ctrl+c. This tells the os to terminate the running program(yours)...

    Here are some small tips.

    local computer = require("computer")
    
    print("Whats The Password?")
    local Password = io.read() -- # this is where ctrl+c can be a problem for you.
    if Password == "password" then
    	print("Passowrd Accepted")
    	os.sleep(1)
    else
    	print("Password Denied")
    	computer.stop() -- # This doesn't even work. 'stop' is a device method. You've loaded the 'computer' library. use 'computer.shutdown(true)' instead.
    end

    Here is a version of your program that will fix users like me being able to bypass it.

    local computer = require("computer")
    local term = require("term")
    
    print("Whats The Password?")
    -- # term.read or io.read will throw an error from within your program when ctrl+c is pressed.
    -- # supress this with luas' pcall function. It calls term.read for us.
    local ok, Password = pcall(term.read, { dobreak = false, pwchar = "*" })
    
    if ok then -- # not sure why but term.read add a space to the end of the returned string. Trim that shit.
      Password = string.sub(Password, 1, #Password - 1)
    end
    
    if Password == "password" then
    	print("Password Accepted") -- # fixed a typo in "Password Accepted"
    --	os.sleep(1) # not needed here. the user shouldn't wait to use his/her pc.
    else
    	print("Password Denied")
      	os.sleep(1.5) -- # sleep here instead to give time to inform the user they input an incorrect password.
    	computer.shutdown(true) -- #reboot. Note im using 'shutdown' the lib method not the device method 'stop'.
    end

    I hope this helps.

  11. I would look into the 'install.lua' program in OpenOS. The path to the program is /bin/install.lua but if you wanna read up on it check out the man file for it \@ /man/install or run the man program from the shell with 'man install'.

  12. local computer = require ("computer")
    print("What's The Password?")
    local password = io.read()
    -- # HERE is the missing end. Also, use the '==' for equality and single '=' for assignment
    -- # Also to note, io.read returns a string. password == 123 will error comparing a string to a number.
    -- # Use password = tonumber(password) or convert the right side of the comparison to a string with tostring(123)
    -- # if password == "123" then ... or password == tostring(123) ... or tonumber(password) == 123 ...
    if password == "123" then -- # I just put the pass in quotes to keep it simple.
    	print("Password Accepted")
    -- end # bad end here too
    else
    	print("Password Denied")
    	os.sleep(2)
    	computer.stop()
    end -- # end goes here

     

  13. 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 :/

  14. I don't know of any programs that do this yet but I have been working on one that will be able to do what you want. Can't say when it will be ready though.. maybe a day.. Maybe a week..

×
×
  • Create New...

Important Information

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