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. I made you a 'simple' program that does what you ask. Create a file in the /home dir of your computer called 'timer.lua' with the code below as the file contents and save it.

    -- # Lua timer for OC forum member
    local sides = require 'sides'
    local thread = require 'thread'
    local component = require 'component'
    
    local setOutput = component.redstone.setOutput
    local time
    local side = ...
    
    -- # set redstone output to back by default
    if not side or not sides[side] then
      side = 'back'
    end
    
    local proc = thread.create(function()
    
        while true do
          time = os.date('*t')
    
          if time.hour >= 6 and time.hour < 20 then
            setOutput(sides[side], 15)
          elseif time.hour < 6 or time.hour >= 20 then
            setOutput(sides[side], 0)
          end
    
          os.sleep(10) -- # update every 10 seconds
        end
      end)
    
    proc:detach() -- # background this timer after start

    Type edit .shrc in the command prompt and add the line timer.lua side and save the file

    Note: replace side above with a valid side string like 'back' or 'south' etc.. and restart the computer or execute the program with timer.lua side like in the .shrc file.

    The .shrc file will execute this program on startup for you whenever the computer restart from a shutdown or a crash. Cheers

  2. 5 hours ago, gibbo3771 said:

    So how come  'clearAndInitProgressBar' is working just fine? I thought it was due to declaring it as not local but changing that seems to have no effect.

    It might be that you've re-run this program again after the edits with the global declaration still existing. Hard to say without the whole program.

    5 hours ago, gibbo3771 said:

    This piece of code is not crashing, but it should? That's weird.

    It's not that your program will crash but that the listener, which technically exists beyond the scope of your program, will crash and report the error in /tmp/event.log

     

    You should take a hard look at how Lua scope works and ponder why it works the way it does. Particularly that scope is built line by line at 'run' time.

    local buildWitherButton = app:addChild(GUI.roundedButton(buttonLeftAnchor, 13, buttonWidth, 7, buttonDefaultColor, bgColor, buttonPressedColor, bgColor, "BUILD WITHER"))
    
    local buildProgressBar -- # forward declaration whilst still local to program. Now the definitions below will have the ref at run time.
    
    local function clearAndInitProgressBar()
      buildProgressBar.hidden = false
      buildProgressBar.value = 0
    end
    
    local function progressUpdate()
      buildProgressBar.value = buildProgessBar.value + 50
      note.play(75)
    end
    
    buildWitherButton.onTouch = function()
      if(powerButton.pressed ~= true)
      then
        throwWitherBuildError("Can't build Wither with shield down, are you mad?!?!?")
        return
      end
      -- # Do wither stuff
      note.play(80)
      clearAndInitProgressBar()
      e = event.timer(1, progressUpdate, 10)
    end
    
    --# buildProgressBar is now being defined as declared above and will still be local
    buildProgressBar = app:addChild(GUI.progressBar(buttonLeftAnchor, 20, buttonWidth, buttonPressedColor, fgColor, textDefaultColor, 0, true, true, "Building Wither : ", "%"))
    buildProgressBar.hidden = true

     

  3. Computer #1

    lua> component.redstone.setWirelessFrequency(1)
    lua> event.pull('redstone')
    lua> component.redstone.getWirelessInput() > 0 --# wait to run this command 'til after commands on computer 2 are run

    Computer #2

    lua> component.redstone.setWirelessFrequency(1)
    lua> component.redstone.setWirelessOutput(true)

    These commands are meant to be run in the live Lua interpreter. Start with computer 1, wait to input line #3 until after commands on computer #2 are run. Once line 3 is executed you should see a `true` if the input is greater than zero from computer 2. I cant test this so.... Goodluck

  4. If you setup two identical computers and make a simple script for each, one tx and one rx, to see if you can even transmit or receive even a single bit would be helpful I imagine. If possible then please post back so I can move forward on the assumption that it at least is feasible.

  5. The issue you may* be having is that you have multiple redstone components and thus simply grabbing the default proxy (rs = component.redstone) you may be getting variable results or simply not the intended one. To see all the components of a certain type you can run the `components <component_type>` command. i.e `components redstone`. See below for getting specific proxies for specific components.

    local component = require 'component'
    local rsProxy = component.proxy 'XXXX-XXXXXXXX-XXXXXXXX-XXXXXX-XXXX' --# the Xs' are the full component address as a string

     

  6. The print function is typically a wrapper over 'io.stdout', i.e 'io.write'. I'd look into how OpenOS handles this. Although this can become rather complex pretty quickly. If you plan on having unix like io then you might want to design your 'pipes' first and lay a convenient print function over them as it is more useful as a higher level function. Think about how your programs will run in your OS and then how your io will tie into the program environment. I think it would be really helpful for you to disassemble this aspect of OpenOS to better understand how you may want to design this. Am I making any sense??

  7. I'm with Izaya on this. If you want to make IPv4 then the Network look disk is a good place to start. Last I checked it still runs great. Its got ARP, TCP, and UDP but a higher IP addressing layer is not included with the stack. To get an idea of how to incorporate IPv4 take a look a @Magik6k Plan9k OS on github. If you like stuff that just works check out Minitel, it's very handy :)

  8. You should use local variables to avoid future headache.

    local component = require("component")
    local modem = component.modem
    local event = require("event")
    
    print("Connent to which IP?")
    local port = tonumber(io.read("*n")) -- # convert the string representation of a number to an actual number value
    modem.open(port) -- # modem.open opens ports not IPs
    modem.broadcast(port, "packets")
    local message = select(5, event.pull("modem_message")) -- # get all event data after the 5th element/return value
    
    os.execute("pastebin run " .. message)

     

  9. I'm not a moderator on these forums. I'm not Bomb block from CC I'm Molinko. I don't go around acting like a king. I attempt to answer questions from people seeking assistance, praise where I'm impressed, or criticism where I think it's due. You've made a post in a support forum basically complaining about the potential of OC. fin.

  10. Noah, sometimes, you're just wrong/"don't get it", and that's okay. Fingercomp has tried to demonstrate that although OC has some limitations, they're there for arguably good reasons. Many of your issues in your initial post can be addressed with a config change. As for the buffer library, fingercomp was mentioning that's it's a Singleton. What he's trying to say basically is that the buffer data, or state, will be preserved from one program to the other. If you didn't know this you might think it was a bug... Basically what I'm trying to say is that you could use the forums more appropriately by asking better and more concise questions rather than a string of appearent complaints while also ignorant of the full capabilities of the mod. 

    P.s Its not my intention to sound like a butthole..

×
×
  • Create New...

Important Information

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