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

Molinko

Members
  • Content Count

    446
  • Joined

  • Last visited

  • Days Won

    34

Posts posted by Molinko


  1. Bummer.. I guess because user input is not strictly a file it's not behaving the way I expected.. perhaps you'll have to roll your own user input with event.pull..


  2. Io.read should yield the thread until enter is hit or the arg to it is satisfied ie after 2 characters. setCursorBlink will only set the blink mode of the cursor


  3. To limit the number of characters read you can pass a number to io.read. i.e `io.read(2)`

    As for the cursor blinking and overwriting your input box you can either make your input box larger or turn the cursor blinking off with `term.setCursorBlink(false)`


  4. The lib you're looking for are cursor.lua & full_cursor.lua but I'm not sure these will do what you're seeking to accomplish I just remember hearing about them...

    Also my example was done in a way that it could be modified to control the windows(and thus the cursors) of other processes. If you just want to access the current processes window it  may be simpler with the tty lib.

    local tty = require "tty"
    local event = require "event"
    local kb = require "keyboard"
    
    local window = tty.window
    local handle = event.listen("touch", function(_, _, x, y)
        	window.x = x
        	window.y = y
        	print "HI"
        end)
    
    while true do
      local ev = { event.pull("key", nil, nil, kb.keys.q) }
      event.cancel(handle)
      break
    end

     


  5. Was this any help? I forgot, but there is actually a cursor library in the later versions of openos that you might want to check out.. I haven't used it and I'm not familiar with it at all but that might be a better solution.


  6. okay so its a bit tricky cause i dont know what exactly you're trying to pull but ill give it a shot...

    local term = require "term"
    local kb = require "keyboard"
    local event = require "event"
    local process = require "process"
    local component = require "component"
    
    local window = term.internal.open() -- # creates a full screen window. optionally provide (dx, dy, width, height)
    term.bind(component.gpu, window) -- # bind the primary gpu to the window we made
    
    local proc = process.info() -- # get an instance of this process' details
    local handle = event.listen("touch", function(_, _, x, y) -- # this is basically your 'cursor' function
        	proc.data.window.x = x
        	proc.data.window.y = y
        	print "HI" -- # click around to see the effect
        end)
    
    while true do
      local ev = {event.pull("key")}
      if ev[4] == kb.keys.q then break end -- # quit the loop and basically the program
    end
    
    event.cancel(handle) -- # clear the event listener

    This example can be modified to control the window of another process as well. I hope this can get you started. Ask away if this isn't very clear....


  7. Each process in openos has its own instance of a cursor. It's stored in the window property of a process I believe.. try assigning to the processes window cursor as term.setCursor will only set the cursor of the process calling it... I can't test any code ATM so you may have some exploring to do


  8. If event.listen is after a continuous loop then it wont be called until that block is finished. To use event.listen it should be called before the loop starts. Note: the loop will have to yield somehow via either event.pull or os.sleep or computer.pullSignal.

    while (some_condition) do
      doSomething(data)
      os.sleep(5)
      doSomethingElse(more, data)
    end
    
    event.listen('some_event', listener) -- # this will not run until `some_condition` above returns false or there is an error
    event.listen('some_event', listener)
    
    while (some_condition) do
      doSomething(data)
      os.sleep(5)
      -- # if an event named `some_event` happens during this sleep call above then the listener will execute
      doSomethingElse(more, data)
    end

    background stuff..

    local thread = require 'thread'
    local event = require 'event'
    
    local bg_proc = thread.create(function()
        print 'starting background thread..'
        while true do
          local ev = event.pull 'key'
          print 'somebody pressed something!'
        end
      end)
    
    print 'starting main loop'
    local i = 0
    while true do
      i = i + 1
      print('count is ' .. tostring(i))
      os.sleep(1)
    end

     


  9. Possible. Maybe. But definitely not practical. You would use the network card along with client and host programs on each machine. Computers dont have access to each others components so any communication can be done over a network. You can write a program on one machine to request access and write data over a network connection and another program on another machine to answer requests and read/write data from that connection. Im not really sure of another way to perform this. Perhaps others can chime in.


  10. So there are two ways to do this. The first is a little more complex. You can simply have two screens and one gpu and switch which screen the gpu is bound to and draw. The second and probably better way is to have two gpus, one for each screen.

    -- # 2 screens 1 gpu
    local component = require "component"
    local prim_screen = component.gpu.getScreen()
    local sec_screen
    
    -- # get the second(non primary or unbound) screen address from the dev fs
    local f = assert(io.open "/dev/components/by-type/screen/1/address")
    sec_screen = f:read "*a" -- # read the file which has the component address
    f:close() -- # clean your room
    
    -- # the goods
    print "this is one screen 1"
    compnent.gpu.bind(sec_screen)
    print "gpu is bound to screen 2 now"
    component.gpu.bind(prim_screen)
    print "back to screen 1"
    -- # 2 gpus
    local component = require "component"
    local gpu1 = component.gpu
    local gpu2_address, scr2_address
    
    for address, ctype in component.list() do
      if ctype == 'gpu' and address ~= gpu1.address then
        gpu2_address = address
      elseif ctype == 'screen' and address ~= gpu1.getScreen() then
        scr2_address = address
      end
      if gpu2_address and scr2_address then break end -- # quit early if we have the second gpu & screen pair
    end
    
    local gpu2 = component.proxy(gpu2_address)
    gpu2.bind(scr2_address) -- # bind the second screen to the second gpu
    
    gpu1.set(3, 3, "this is on screen 1")
    gpu2.set(3, 3, "this is on screen 2")

    Hope this gets you started. Feel free to ask more if you like :)


  11. local GUI = require("GUI")
    local component = require 'component'
    local thread = require 'thread'
    local event = require 'event'
    
    local reactor = component.reactor_chamber
    local currentTemps = reactor.getHeat()
    --------------------------------------------------------------------------------
    
    -- Create new application
    local application = GUI.application()
    
    -- Add panel that fits application
    application:addChild(GUI.panel(1, 1, application.width, application.height, 0x262626))
    -- Add smaller panels
    application:addChild(GUI.panel(4, 2, 23, 4, 0x880000))
    application:addChild(GUI.text(5, 3, 0xFFFFFF, "Current Reactor Temps"))
    
    -- Grab a reference to the text object you need to update
    local gui_temp = GUI.text(5, 5, 0xFFFFFF, currentTemps)
    application:addChild(gui_temp)
    application:draw(true) -- initial paint
    thread.create(application.start, application) -- Start the app event handler as a subprocess of this one
    
    while true do
      os.sleep(3) -- Update the element every 3 seconds
      gui_temp.text = tostring(reactor.getHeat())
      gui_temp:update() -- Signal the app that this element should be refreshed
    end

    This is just another attempt in case I missed something... If this doesn't work yet again, then could you run `cat /tmp/event.log` after running this (if it fails), and reply with its output if it's available. Threads and event timers don't throw errors in the main process.

     


  12. 1) yes. The quotes.

    2) autorun isn't depricated ( I don't think..) but you might like the .shrc format better.

    Run 'edit .shrc' in the home dir and add the path to the file you want to run on the first available line. It's super simple and can have multiple programs to run on startup. Also programs can take shell args just like typing it in yourself.


  13. I'm not super familiar with this library so you may have to adjust the code as it is untested.

    local GUI = require("GUI")
    local component = require 'component'
    local thread = require 'thread'
    local event = require 'event'
    
    local reactor = component.reactor_chamber
    local currentTemps = reactor.getHeat()
    --------------------------------------------------------------------------------
    
    -- Create new application
    local application = GUI.application()
    
    -- Add panel that fits application
    application:addChild(GUI.panel(1, 1, application.width, application.height, 0x262626))
    -- Add smaller panels
    application:addChild(GUI.panel(4, 2, 23, 4, 0x880000))
    application:addChild(GUI.text(5, 3, 0xFFFFFF, "Current Reactor Temps"))
    
    -- Grab a reference to the text object you need to update
    local gui_temp = GUI.text(5, 5, 0xFFFFFF, currentTemps)
    application:addChild(gui_temp)
    
    -- Create a timer that will run every 3 seconds, forever.
    local tid = event.timer(3, function()
        gui_temp.text = tostring(reactor.getHeat()) -- overwrite the text data
        gui_temp:update() -- notify the app that the state of gui_temp has changed
      end, math.huge)
    
    --------------------------------------------------------------------------------
    
    application:draw(true)
    application:start()
    event.cancel(tid) -- cleanup the timer after application:start returns

     


  14. The issue you see here is because `component` is removed from the global scope in OpenOS and must be required using the `require` function. If this file is intended to be run from an eeprom at boot instead of the standard Lua bios then `component` will still be global and this issue shouldn't remain. Running this program from the shell (as you're doing in the picture).. it will be provided an environment that doesn't contain the `component` namespace. This program seems to be intended to only run from a computer with seemingly multiple screens and gpus, cpu, redstone block(or card?), ram, and of course an eeprom. No hdd and no OS(no OpenOS floppy either). 


  15. On line 349 and others you use an undeclared variable named 'turbineNum' to index the turbine table like so "some_value = turbine[turbineNum].someMethod()".

    You use this in a few places in the script yet I can't find a placed where it is defined.

×
×
  • Create New...

Important Information

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