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. The code looks great.. One problem stands out and that is that your keyChecker coroutine isn't being run. Also, Your main function and the keyCheck function both have a loop that will block one another if keyChecker is run within main. Try this solution out. I believe its what you're going for....

    function main()
      local running = true
      local e = nil
    
      repeat
        -- Get the tank information, results are in table format
        local tInfo = batbox
        local cap = tonumber(batbox.getCapacity())
        local fill = tonumber(batbox.getStored())
    
        -- Output as you want... a very simple way:
        print("CESU Power Levels and Controls")
        print("Energy Stored : "..fill)
        print("CESU Capacity : "..cap)
        print("\n Press Enter to toggle reactor.")
        print("Press Back to return to OpenOS.")
        term.setCursor(1,1)
    
        e = event.pull(1, "key_up")
        if e == "key_up" then
          toggleBox()
        elseif e == "back" then
          running = false
        end
    
      until not running or e == "terminated"
    end

     

  2. You are correct. I thought for some reason that was an example you inserted to say ...this model...

    The 'answer' var is a string returned from either term.read() or io.read() (excuse my first advice. term.read is probably better...). The line you're looking for is this..

    os.execute("print3d /usr/share/models/" .. answer .. ".3dm") -- # string concatenation
    -- # OR
    os.execute(table.concat({"print3d ", "/usr/share/models/", answer, ".3dm"})) -- # Using table.concat({...})

     

  3. 2 hours ago, XenizedKitsune said:

    (Plus running between two different trees means putting in 'robot.forward()' half a dozen times and that feels so crude...)

    What you're looking for is a function. Specifically a 'for' or while loop in a function. Here is a crude one of the former that 'could' be made way better (features n stuff)...

    local robot = require 'robot'
    
    local function forward( times )
    	times = times or 1
    	
    	local success, reason, moves = false, nil, 0
    	for move = 1, times do
    		success, reason = robot.forward()
    		if not success then break end 
    		moves = moves + 1
    	end
    
    	return success, moves, reason
    end
    
    -- # USAGE
    -- # Let's say we're moving 3 forward, on a clear path.
    forward( 3 ) -- # // true, 3, nil (success, moves, reasonForFailure)
    
    -- # Now we try another 3 with and obstruction 2 blocks ahead of the robot.
    forward( 3 ) -- # // false, 1, "path obstructed... or something like this that component.robot.move(side) returns when it fails"

     

  4. Yes, functions are real... I'm not really sure what you meant by that.. But here's an example anyways..

    -- # A named function
    local function sum( a, b )
    	return a + b
    end
    
    -- # An 'anonymous' function stored in the named variable 'mul'
    local mul = function( a, b )
    	return a * b
    end
    
    local pow -- # forward declaration allows us to reference the caller 'pow' inside of itself.
    pow = function( a, p )
    	if not p then -- # return a partial application
    		return function( p2 )
    			-- # remember the initial number 'a' and take a power of p2 to apply
    			return pow( a, p2 )
    		end
    	end
    
    	return a^p
    end
    --[[ #
    	local val = pow( 3, 2 ) --> // 9
    	local f = pow( 3 ) --> // function( p2 ) return 3^p2 end
    	local val2 = f( 2 ) --> // 9
    ]]

     

  5. Interesting OS. Small, simple, and to the point. I like it. BTW, what exactly is the point? It seems heavily network oriented as the title suggests... Base Control.. Sounds neat. I'm looking forward to a breakdown of what you intend this to be :).... 

  6. I believe I see the problem.. You are sleeping past the responses from the server.. Try this out. It has some comments to try and explain...

    -- # Setting libraries
    local component = require("component")
    local term = require("term")
    local event = require("event")
    local modem = component.modem
    
    -- # Program code
    
    modem.open(111)
    
    term.clear()
    print(">")
    term.setCursor(2,1)
    input = io.read()
    
    if input == "server.status" then
      modem.send("address of the server", 123, input)
      -- # os.sleep(2) // HERE. We sleep beyond the response of the server, thus waiting forever.
      -- # event.pull is essentially coroutine.yield, which will wait for a loose match of an event id. i.e "modem" will match "modem_message"
      local _,_,_,_,_,status = event.pull("modem") -- # halt until any modem* event. This, ideally, should be "modem_massege"
      print("Server status: " .. status) -- we must have seen an event that at least started with the string "modem".
    else
      print("Illegal command")
    end

     

  7. You could think about loading libraries remotely into memory from a network... As TYKUHN2 said..

    On 3/26/2017 at 9:30 AM, TYKUHN2 said:

    Also "require" is not much more than loading and executing a file.

    With an extra step of requesting a file... require could be switched with a call to load or loadfile.

    -- # pseudo code.. this might work but isn't tested or even run...
    function require(module)
      -- # do some checks n shit..
      local file, chunk = nil, ""
      modem.send(address, port, "get[file] " .. module)
      
      while true do
        local e, la, ra, p, d, ch, status = computer.pullSignal(2)
        
        if e == "modem_message" then
          if status:match("error") then -- # request failed somehow
            return nil, status
          elseif st == "chunk" or st == "start" then -- # first and subsequent chunks
            chunk = chunk .. ch
          elseif st == "done" then -- # we haz all the chunkz. time to load ze chunkz.
            file = chunk .. (#ch > 0 and ch or "")
            break
          end
        end
      end
      
      if file then
        local ret = {pcall(load, file, "=" .. module)}
        if not ret[1] then return nil, ret[2] end -- # ret[2] here is an error msg
        ret = {pcall(f)}
        return ret[1] and ret[2] or nil, ret[2]
      end
      
      return nil, "failed because reasons..."
    end

     

  8. From what I understand file:seek is only a method available when reading files with io.open. The char you need it backslash n or '\n'.

    You can use the concatenation operator to join 2 strings into one. Looks like this '..' .

    I.e. 

    s = 'line 1\n' .. 'line 2\n' .. 'More lines...'

    file:write(s)

  9. 3 hours ago, Ketzak said:

    Did you ever get this working? I'm trying to write a similar program. Rather, I'm trying to rewrite a program I wrote in Computer Craft that used coroutines to monitor redstone inputs and send them to a server, while updating outputs based on data from a server. Every way I try to implement it results in the computer eventually failing out for not yielding.

    Tis a really old post.. If you're seeking help on a particular piece of code try making a new topic in Programming/Support :)

     

×
×
  • Create New...

Important Information

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