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

jakendrick3

Members
  • Content Count

    3
  • Joined

  • Last visited

Posts posted by jakendrick3

  1. So, I've written my own menu API in CC, called 'Jenisis' named after what I called my software company on me and a few friends servers, (did quite well actually seeing as how I'm the only one who could code) and I ported it over to OpenComputers and then continued development on this, seeing as how IMO OC is better. Which brings me to my problem. I've been trying to add a feature where the API takes a table full of functions to run whenever an event is triggered, like for receiving modem messages whilst still in the menu's loop. I can't quite get it working and just need some new ideas on how.

     

    Here's the API:

    local term = require("term")
    local shell = require("shell")
    local internet = require("internet")
    local keyboard = require("keyboard")
    local event = require("event")
    local os = require("os")
    local component = require("component")
    local gpu = component.gpu
     
    jenisis = {}
     
    function jenisis.drawScreen(staticScreen, tableScreen, handlerTable)
      local running = true
      local rkeyp = true
      local cselected = 1
      local num = 1
      local static = true
      local isPrint = true
      local staticNum = 1
      local param = "f"
     
      while running == true do
        term.clear()
        term.setCursor(1, 1)
       
        rkeyp = true
        isPrint = true
        num = 1
        static = true
        staticNum = 1
        param = "nulll"
     
        while static == true do
          local line = staticScreen[staticNum]
          if line ~= nil then
            print(line)
            staticNum = staticNum + 1
          else
            static = false
          end
        end
     
        num = 1
        print(" ")
     
        while isPrint == true do
          local line = tableScreen[num]
          if line ~= nil and num ~= cselected then
            print(line)
            num = num + 1
          elseif line ~= nil and num == cselected then
            print("["..line.."]")
            num = num + 1
          else
            isPrint = false
          end
        end
       
        while rkeyp == true do
          local ev = {event.pull()}
          if ev[1] == "key_down" then
            local key = ev[4]
    
            if key == 200 then
              cselected = cselected - 1
              if cselected <= 0 then
                cselected = num - 1
              end
              rkeyp = false
            elseif key == 208 then
              cselected = cselected + 1
              if cselected >= num then
                cselected = 1
              end
              rkeyp = false
            elseif key == 28 then
              return cselected
            elseif key == 15 then
              return 999
            end
          else
            for k, v in ipairs(handlerTable) do
              if k == ev[1] then
                k(ev)
              end
            end
          end
        rkeyp = false
        end
      end
    end
     
    return jenisis 

     

    And here's the test program:

    local jenisis = require("jenisis")
    local component = require("component")
    local gpu = component.gpu
    local os = require("os")
    
    local jnhandletable = {
      touch = function(eventinfo) print("dont touch") end,
    }
    
    local jnmenu = {
      "This is some test stuff", 
      "Dont worry about it", 
      "Seriosuyl thooo"
    }
    local jnstatic = {
      "This is a test",
      "yeah"
    }
    
    --jenisis.drawScreen(jnstatic, jnmenu, jnhandletable)
    
    for k, v in ipairs(jnhandletable) do
      print(k, v)
    end 

     

    This isn't really my preferred way of doing it, I'd prefer something along the lines of:

    handleTable = {}
    
    function handleTouch(eventInfo) -- eventInfo is passed to the function by the API. It's the table returned from the actual event.
      -- things that happen when you touch it
    end
    
    handleTable["touch"] = handleTouch
    
    cselected = jenisis.drawScreen(static, menu, handleTable)
    

    Anyways, sorry for the wall of text, and thanks in advance for any help!

  2. Hey, sorry, I posted this a while back and it didn't get approved for a while, managed to figure out the problem. As a CC user, not used to declaring a table at the beginning of an API then having it return it. Sorry!

     

    EDIT - ran into a new problem. Whilst attempting to use term.read("*"), the pc that is running it crashes. Trying to make an autorun with a password.

  3. So, my problem occurs when trying to use this api, converted from CC:

     

    http://pastebin.com/qwt98zmj

     

    Original:

     

    http://pastebin.com/XZS4eF9Z

     

    Basically, all I am doing is:

    cselected = jenisis.drawScreen(static, menu)
    

    And I did this at the top (yes, before the function, and also the tables were declared as well):

    jenisis = require("jenisis")
    

    It's located inside the lib folder, and it's not about not finding/loading the API, because I already sorted that out. It's returning a rather unique error for an API:

    /jentest:17: attempt to index global 'jenisis' (a boolean value)
    stack traceback:
         /jentest:17: in main chunk
         (...tail calls...)
    

    Full 'test' program here: http://pastebin.com/ZfNvZ6Xk

×
×
  • Create New...

Important Information

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