lua, lua, lua

  • Please make sure you are posting in the correct place. Server ads go here and modpack bugs go here
  • The FTB Forum is now read-only, and is here as an archive. To participate in our community discussions, please join our Discord! https://ftb.team/discord

BlackFire

New Member
Jul 29, 2019
344
0
0
Hey guys,

I've been trying to create a monitor in my base to have complete access to all of my spawners as well as keep track of my power and liquid levels. However, I can't figure out how to combine the os.pullEvent("monitor_touch") with the constant update of my power/liquid levels. Since the pullEvent is ran, the computer will wait until the screen touch to do anything, the power levels and liquid levels aren't updated until I click on a button, In this case turning on a spawner, then the current power/liquid levels are updated.

Does anyone have a way around this?

here is by sloppy script if needed:

Code:
mon = peripheral.wrap("right")
mon.setTextScale(1)
mon.setTextColor(colors.white)
local button={}
local energyTable={}
mon.setBackgroundColor(colors.black)
wireless = peripheral.wrap("left")
energyReader = peripheral.wrap("bottom")
         
for i = 1, 8 do
  energyTable[i] = {}
  for j = 1, 2 do
    energyTable[i][j] = {}
    for k = 1, 2 do
      energyTable[i][j][k] = nil
    end
  end
end         
         
         
function getEnergyStats()
  for i = 1, 8 do
    junk, junk2, junk3, stats = energyReader.get(i)
    if stats ~= nil then
      local j = 1
      while j < 3 do
        for label, value in pairs(stats) do
          energyTable[i][j][1] = label
          energyTable[i][j][2] = value
          j = j + 1
        end
      end
    end
  end 
end
                   
function setTable(name, func, xmin, xmax, ymin, ymax)
  button[name] = {}
  button[name]["func"] = func
  button[name]["active"] = false
  button[name]["xmin"] = xmin
  button[name]["ymin"] = ymin
  button[name]["xmax"] = xmax
  button[name]["ymax"] = ymax
end
 
function funcName()
  print("You clicked buttonText")
end
 
function testRedstone()
  if redstone.testBundledInput("back", colors.white) then
    redstone.setBundledOutput("back", 0)
    print("marker")
  else
    redstone.setBundledOutput("back", colors.white)
    print("marker1")
  end
end
               
                       
function fillTable()
  setTable("Spawner1", testRedstone, 5, 15, 3, 5)
  setTable("Spawner2", funcName, 5, 15, 7, 9)
  setTable("Spawner3", funcName, 5, 15, 11, 13)
  setTable("Spawner4", funcName, 5, 15, 15, 17)
  setTable("Spawner5", funcName, 5, 15, 19, 21)
  setTable("Spawner6", funcName, 5, 15, 23, 25)
end   
 
function fill(text, color, bData)
  mon.setBackgroundColor(color)
  local yspot = math.floor((bData["ymin"] + bData["ymax"]) /2)
  local xspot = math.floor((bData["xmax"] - bData["xmin"] - string.len(text)) /2) +1
  for j = bData["ymin"], bData["ymax"] do
      mon.setCursorPos(bData["xmin"], j)
      if j == yspot then
        for k = 0, bData["xmax"] - bData["xmin"] - string.len(text) +1 do
            if k == xspot then
              mon.write(text)
            else
              mon.write(" ")
            end
        end
      else
        for i = bData["xmin"], bData["xmax"] do
            mon.write(" ")
        end
      end
  end
  mon.setBackgroundColor(colors.black)
end
   
function screen()
  local currColor
  for name,data in pairs(button) do
      local on = data["active"]
      if on == true then currColor = colors.lime else currColor = colors.red end
      fill(name, currColor, data)
  end
end
 
function toggleButton(name)
  button[name]["active"] = not button[name]["active"]
  screen()
end   
 
function flash(name)
  toggleButton(name)
  screen()
  sleep(0.15)
  toggleButton(name)
  screen()
end
                                           
function checkxy(x, y)
  for name, data in pairs(button) do
      if y>=data["ymin"] and  y <= data["ymax"] then
        if x>=data["xmin"] and x<= data["xmax"] then
            data["func"]()
            --return true
            data["active"] = not data["active"]
            print(name)
        end
      end
  end
  return false
end
   
function heading(text)
  w, h = mon.getSize()
  mon.setCursorPos((w-string.len(text))/2+1, 1)
  mon.write(text)
end
   
function label(w, h, text)
  mon.setCursorPos(w, h)
  mon.write(text)
end
 
function subTitle(w, h, text)
  mon.setCursorPos(w, h)
  mon.setTextColor(colors.red)
  mon.write(text)
  mon.setTextColor(colors.white)
end
 
function printingStatisticEU(table)
  local line = 5
  for i = 1, 8 do
  -- for j = 1, 2 do
    -- for k=1, 2 do
     
        if table[i][1][2] ~= nil then
         
          local total = 0
          total = tonumber(table[i][2][2])
          print(total)
          local current = 0
          current = tonumber(table[i][1][2])
          local percent = current / total * 100
          label(21, line, "EU Storage #"..i)
          label(23, line + 2, "Percent Full: "..percent)
          label(23, line + 3, "Total EU Stored: "..current)
          line = line + 7
        else
        -- print("death")
        end
    -- end
--  end
  end     
end
 
function wirelessAura()
  e, senderID, message, distance = os.pullEvent("rednet_message")
  auraLevel = textutils.unserialize(message)
 
end
 
fillTable()
while true do
  mon.clear()
  heading("Heading, you got this")
  subTitle(18, 3, "EU STORAGE:")
  getEnergyStats()
  printingStatisticEU(energyTable)
  screen()
  local e, side, x, y = os.pullEvent("monitor_touch")
  print(x..":"..y)
  checkxy(x,y)
  sleep(.1)
end
 

BlackFire

New Member
Jul 29, 2019
344
0
0
I think this might be what you need.
that does sound about right. Have one constantly refreshing the screen and displaying the energy/liquid while the other function will listen for an event monitor_touch. I'll give it a try.

Set a timer event. Listen for any event, not just monitor.
that might work, if the parallel doesn't ill give this a try.

Thank you guys! good to see the community working together!