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

The Simon

Members
  • Content Count

    23
  • Joined

  • Last visited

Posts posted by The Simon

  1. Hi

    I ran into the problem showing up here:

    2019-04-19_16_44.09_1.png.26d9c7131585647a273fcbbded634b10.png

    I made a issue suggestion report here explaining the problem. But due to the mod being focused more to later versions of Minecraft it might be better to make an addon instead.

    I haven't modded Minecraft that much and simply only made a few mods to create items and items in use with Baubles API. But I kind of got stuck right away when adding a new module:

    help1.png.93988f8774eb46111e70f3a11c41b36b.png

    ModuleFacade.java

    package net.simon.tiscovers.items;
    
    import li.cil.tis3d.api.machine.Casing;
    import li.cil.tis3d.api.machine.Face;
    import li.cil.tis3d.api.machine.Port;
    import li.cil.tis3d.api.util.RenderUtil;
    import li.cil.tis3d.client.renderer.TextureLoader;
    import li.cil.tis3d.common.module.ModuleDisplay;
    import net.minecraft.client.renderer.GlStateManager;
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.item.ItemStack;
    import net.minecraft.util.EnumHand;
    import net.minecraftforge.fml.relauncher.Side;
    import net.minecraftforge.fml.relauncher.SideOnly;
    
    public class ModuleCover extends ModuleDisplay {
    
        private Casing casing;
        private Face face;
    
    
        public ModuleCover(Casing casing, Face face) {
            super(casing, face);
        }
    
        @Override
        public Casing getCasing() {
            return this.casing;
        }
    
        @Override
        public Face getFace() {
            return this.face;
        }
    
        @Override
        public void onInstalled(ItemStack itemStack) {
    
        }
    
        @Override
        public void onUninstalled(ItemStack itemStack) {
    
        }
        @Override
        public void onEnabled() {
    
        }
        @Override
        public void onDisabled() {
    
        }
        @Override
        public void onDisposed() {
    
        }
    
        @Override
        public boolean onActivate(EntityPlayer player, EnumHand hand, float x,float y,float z) {
            if (player.isSneaking()) {
                return false;
            }
    
            // Reasoning: don't remove module from casing while activating the
            // module while the casing is disabled. Could be frustrating.
            if (!getCasing().isEnabled()) {
                return true;
            }
    
            return true;
        }
    
        @Override
        public void step() {
    
        }
    
        @Override
        public void onBeforeWriteComplete(final Port port) {
            // No need to clear other writing pipes because we're outputting random
            // values anyway, so yey.
    
            // Start writing again right away to write as fast as possible.
        }
    
        @Override
        public void onWriteComplete(final Port port) {
            // No need to clear other writing pipes because we're outputting random
            // values anyway, so yey.
    
            // Start writing again right away to write as fast as possible.
        }
    
        @SideOnly(Side.CLIENT)
        @Override
        public void render(final boolean enabled, final float partialTicks) {
            if (!enabled) {
                return;
            }
    
            RenderUtil.ignoreLighting();
            GlStateManager.enableBlend();
    
            RenderUtil.drawQuad(RenderUtil.getSprite(TextureLoader.LOCATION_OVERLAY_MODULE_RANDOM));
    
            GlStateManager.disableBlend();
        }
    }

     

    Some help is greatly appreciated. For the time being, I simply want the mod to compile and adding the new module.

  2. Hi!

    I have two screens and two graphics cards on my server, I want it to use one of them every time I boot the computer. As it is right now it chooses one of the two graphics cards randomly whenever I boot and binding them or changing the primary component with rc doesn't seem to fix the issue. Right now I simply spam click the power button until it selects the right monitor.

  3. I had an idea to use 3D models to make a nice transition between my wall and the floor, but as all 3D models all have in common is that they usually become a bit darker than their original counterpart. I have tried a bunch of solutions to fix this; giving it a light level, placing a light source behind it, changing the tint. You guys got any tips I could try to possibly fix this issue? Otherwise, I will have to do another solution other than 3D prints.

     

    2018-08-31_16.22.18.png

  4. Hi!

    Been working on a Control Station for my Robot. It has most of the essential features done; movements, scanning, interactions, etc. But I have reached a stage when it's mostly optimizations which are left to do, one of them is power usage. The Robot has a battery tier 3 upgrade installed, but as it is now it can still only run for about 20 minutes before it runs out of power and shuts down. This is not ideal due to not be able to remotely turning on a computer directly and needs either a Player or other Robot interaction to turn it back on again.

    Components are a good culprit in this, and can easily be turned off until needed. Signals can be compressed, interactions can be guessed. But as far as software and such I am at a loss. Any suggestion I could use to extend the battery life of my Robot would be great.

     

    Things I have learned about power usage is that os.sleep() reduce power usage during the specified time. Each new character on a screen increases power usage, so it should be turned off when not in use. Signals to the Robot doesn't seem to use power (Linking Card), but signals from the Robot does use power as expected. Coroutines also increase power as expected but reduce the number of available resources inside the computer until the function has finished.

  5. A component that either can be installed inside of a Robot/Drone (possibly in its own slot) or be right-clicked on a computer case will execute the code that was put on the EEPROM during the crafting when pressing the power button. The crafting recipe should contain a Capacitor as an extra power cell for the component to function even if the local machine runs out of power. This could be useful when using a headless Robot/Drone if you want to save its state or want to send a signal it has been forced shutdown, can be a lifesaver in some regards.

    It would also be neat if it had a boolean statement whenever it should fire when the power in the local machine reaches zero, but the computer API can read the machine's energy level so I wouldn't say that should be a necessity.

  6. 9 hours ago, Molinko said:

    So I did some testing and I think what your approach is misunderstood. Once a Tunnel is placed into a Relay it cannot be addressed (as a component). It effectively becomes a part of the "physical" network layer. A better approach would be to place a Tunnel into a Relay on the "master" computer network (via some cable. the master has a modem inside). Your robot should have a wireless modem. And the third piece is a "Network extender".

    A "Network extender" consists of a Power Distributor component connected via cable to two Relay components (these must not touch each other nor can both directly touch the Power Distributor. Creates 'cycles'. Cycles are bad). A Relay is denoted with either a "R^"(Tunnel) or  "R*" for (Modem).

    Crap network diagram

    
    C : Computer                ^   : [Tunnel]          network interface
    R : Relay                   *   : [Wireless Modem]  network interface
    P : Power distributor       -|+ : Wired cable connection
    
                             P
                             |
        C1---R1^        R2^--+--R3*  ("Network extender")
    
                            C2*
    
    C1 is computer #1
    C2 is computer #2 (your robot)
    R[1-3] are Relay components

     

    Ok, I got it setup after your diagram. Here is a picture of it from above:

    154432956_NetworkExtendersetup.png.7a573947a54b369490fae3a8684d4ec5.png

    Edit* I saw now the Extender needs the Relays to be connected, removed the two cables on the sides of the Power Distributor and placed one cable in the middle of the Relays.

  7. Hi!

    I'm working on a "Main control station" to control my various Robots around the world without having to go there myself. I have been using a Linking Card to send signals to my Robot, but the plan is to use multiple and switch to the one you want to control. Right now I have it installed on my Server but want it in a Relay so I can expand the amount of Linking Cards, but I'm having a hard time getting it to work. I have no idea how to send stuff from it to the Robot. When I send from the Robot to the Server it just flashes indicating it has received a signal, but no signals are fired inside of the Server.

    So some feedback would be greatly appreciated in order for this to work.

  8. On 6/23/2018 at 9:32 PM, Molinko said:

    Im not sure really what you're going for.. But I think the update function needs a little work. Also the event listeners you create in the update function might be acting funny because they're in threads, which are like little processes, and I think processes dump they're event registrations when they're complete(this may be nonsense...). One other note, you may want to stick to the term library instead of tty. tty is a core lib an subject to change. I think with your current setup update could look like this(below) and still hypothetically work.

    
    local function update()
      local ev = {event.pull(1, "modem_message")}
      
      if ev[1] == "modem_message" and ev[6] == "scanData" then
        recieveScanData(table.unpack(ev))
        gButtons.update()
      end
    end

     

    You were right with doing it inside a threat would mess stuff up. After I registered it inside of the main loop it worked as I wanted. And I'll keep in mind to use the Term Libray from now on.

  9. Hi!

    I am working on a long distance robot control program. I have a Geolyzer and Linked Card installed inside of it for getting an image of the robot's surroundings and then sends the data to my control station where the mod OpenGlasses draws blocks for an illustration. I got it working when I simply registered a event.listen() at the start of the program, but it is kind of an inconvenience if I want other kinds of signals from the robot. So my idea was to only have one registered when it's waiting for the scan data and when it's done it should unregister it. But this new approach doesn't seem to work for some reason. I made it print out its return value when I registered/unregistered it, and it returned 1 and false.

    I have no idea how to proceed to the next step. Help is appreciated!

    station.lua

    local c = require("component")
    local lights = require("lights")
    local gButtons = require("gButtonAPI4")
    local gKeyboard = require("gKeyboard")
    local event = require("event")
    local ser = require("serialization")
    local thread = require("thread")
    local d = require("computer")
    
    local GPU = c.proxy("332a93bc-f0a6-4c71-9460-d7a7d6ee0d2c")
    local APU = c.proxy("4ba6d276-efab-474c-ba48-bcbd7fd62353")
    --local glasses = c.glasses
    
    local terrain = {}
    local localPos = {0,0,0}
    local facing = "W" -- S W N E (+Z -X -Z +X)
    
    
    
    local digitDisplays = {
      {
        "a87d9238-f46e-4b17-b605-6d8771fba4c4",
        "28dfb050-4f70-4bf8-b221-cc84ab43c660",
        "fef15435-a434-4e33-a3ca-3f725e02dd7f",
        "c0941fad-d5fb-4dce-b356-724431e6b66c"
      },
      {
        "d5a80dc6-963c-4fb5-98ea-711ebb2ff1eb",
        "c868c412-22f5-4605-8e4a-b4bce3e1320c",
        "19b54b1e-8970-4305-9294-d3582d85d06d",
        "c06effa6-bada-4ddc-8578-c46d155b4250"
      },
      {
        "6191d4e0-715f-4c8c-a98e-8960c79c26ab",
        "54ab4452-b63f-4b43-a1e1-13208eac1628",
        "84948db9-81dd-4646-932f-a047ecdef4d7",
        "f226bacf-7af6-47ad-be01-6bb31fcfda9b"
      }
    }
    
    local function compress(tab)
      tab = ser.serialize(tab)
      tab = c.data.deflate(tab)
      return tab
    end
    
    local function decompress(val)
      val = c.data.inflate(val)
      val = ser.unserialize(val)
      return val
    end
    
    local function addBlock(pos,color)
      local x = c.glasses.addCube3D()
      x.set3DPos(table.unpack(pos))
      x.setColor(table.unpack(color))
      x.setAlpha(0.7)
      x.setScale(0.8)
      return x
    end
    
    local function HSL(hue, saturation, lightness, alpha)
        if hue < 0 or hue > 360 then
            return 0, 0, 0, alpha
        end
        if saturation < 0 or saturation > 1 then
            return 0, 0, 0, alpha
        end
        if lightness < 0 or lightness > 1 then
            return 0, 0, 0, alpha
        end
        local chroma = (1 - math.abs(2 * lightness - 1)) * saturation
        local h = hue/60
        local x =(1 - math.abs(h % 2 - 1)) * chroma
        local r, g, b = 0, 0, 0
        if h < 1 then
            r,g,b=chroma,x,0
        elseif h < 2 then
            r,b,g=x,chroma,0
        elseif h < 3 then
            r,g,b=0,chroma,x
        elseif h < 4 then
            r,g,b=0,x,chroma
        elseif h < 5 then
            r,g,b=x,0,chroma
        else
            r,g,b=chroma,0,x
        end
        local m = lightness - chroma/2
        return (r+m)*255,(g+m)*255,(b+m)*255
    end
    
    lights.digit(3,digitDisplays[1],0xff033d)
    lights.digit(5,digitDisplays[2],0xff033d)
    lights.digit(9,digitDisplays[3],0xff033d)
    
    GPU.set(25,5,"Le GPU")
    APU.set(25,5,"La APU")
    
    for i=1,5 do d.beep() end
    
    local function receiveScanData(_,_,_,_,_,msg1,msg2,msg3,msg4)
      print(msg1)
      if msg1 == "scanData" then
    
      else
        --[[addBlock(table.unpack(decompress(msg1)),{0,255,0})
        addBlock(table.unpack(decompress(msg2)),{0,255,0})
        addBlock(table.unpack(decompress(msg3)),{0,255,0})
        addBlock(table.unpack(decompress(msg4)),{0,255,0})--]]
        local coord = {decompress(msg1),decompress(msg2),decompress(msg3),decompress(msg4)}
        for i in pairs(coord) do
          thisHue = 360 - ((coord[i][1]+5))/9*360
          addBlock({coord[i][1],coord[i][2],coord[i][3]},{HSL(thisHue, 1, 0.5, 1)})
          if coord[i][2] then print(coord[i][1],coord[i][2],coord[i][3],thisHue) end
        end
      end
    end
    --event,_,linkingCard,_,_,msg1,msg2,msg3,msg4
    --event.listen("modem_message",receiveScanData)
    
    gButtons.initialize()
    --name,group,label,x,y,w,h,color,alpha,callback
    gButtons.createNewButton("scan",nil,"Scan",5,5,35,14,{255,0,0},0.4,function(x)
      gButtons.Color(x,{0,255,0})
      --c.glasses.removeAll()
      c.tunnel.send("scan")
      os.sleep(0.4)
      gButtons.Color(x)
    end)
    
    
    local function update()
      --print(event.pull(1/20,"modem_message"))
      os.sleep(1/20)
      thread.create(function()
        gButtons.update()
      end)
      thread.create(function()
        local _,_,_,_,_,o = event.pull(1/20,"modem_message")
        --print(o)
        if o == "scanData" then
          print(event.listen("modem_message",receiveScanData))
          print("Enabled")
        end
        if o == "scanDataComplete" then
          print(event.ignore("modem_message",receiveScanData))
          print("Disabled")
        end
      end)
    
    end
    
    while true do update() end

    remote.lua (Robot)

    local computer = require("computer")
    local c = require("component")
    local event = require("event")
    local ser = require("serialization")
    local tty = require("tty")
    local thread = require("thread")
    
    local hardValues = {}
    local terrain = {}
    
    
    --c.tunnel.send()
    local function compress(val)
      val = ser.serialize(val)
      val = c.data.deflate(val)
      return val
    end
    
    local function decompress(val)
      val = c.data.inflate(val)
      val = ser.unserialize(val)
      return val
    end
    
    local function scan()
      local x = {}
      print("Analyzing ..")
      for i=-4,4 do
        for d=-4,4 do
          table.insert(x,c.geolyzer.scan(i,d))
        end
      end
      print("Done Analyzing.")
      return x
    end
    
    thread.create(function()
      os.sleep(5)
      tty.clear()
      print("Initilizing ..")
      --os.execute("/bin/components.lua")
      --c.gpu.bind("125bb046-a2c9-4182-8459-785265229229")
    end):detach()
    
    
    
    local function receive(_,_,_,_,_,msg1,msg2,msg3,msg4)
      computer.beep()
      terrain = {}
      if msg1 == "scan" then
        print("Starting Sequence ..")
        --[[for x in pairs(hardValues) do
          for z in pairs(hardValues[x]) do
            for y in pairs(hardValues[x][z]) do
              c.gpu.set(1,6,x .. " " .. y .. " " .. z)
              if hardValues[x][z][y] > 0 then
                table.insert(terrain,{x,y,z})
                --print(x .. " " .. y .. " " .. z)
                break
              end
            end
          end
        end--]]
        --local x,z = -4,-4
        for x=-4,4 do
          --x = x + 1
          for z=-4,4 do
            local tile = c.geolyzer.scan(x,z)
            --z = z + 1
            --os.sleep(2)
            --print(tile)
            for y=#tile,1,-1 do
              --print(y)
              if tile[y] ~= 0 then
                table.insert(terrain,{x,y-33,z})
                --print("Found: ",x,y,z)
                --break
              end
              if y < 31 then
                break
              end
            end
          end
        end
        print("Calculation Complete.")
        print(#terrain .. " entries.")
        print("Sending Data ..")
        c.tunnel.send("scanData")
        os.sleep(1)
        for i=1,#terrain,4 do
          c.tunnel.send(
            compress(terrain[i]),
            compress(terrain[i+1]),
            compress(terrain[i+2]),
            compress(terrain[i+3])
          )
        end
        print("Data Sent.")
        os.sleep(1)
        c.tunnel.send("scanDataComplete")
      end
    end
    
    event.listen("modem_message",receive)
    
    local function update()
      os.sleep(0)
    end
    
    while true do update() end

     

  10. Hi!

    I have some questions about how to get OpenComputers' items with NBT through commands. I would like to give players the OpenOS Floppy Disk when they run a command block, but when I'm trying to give the floppy any of the OC attributes I'm getting an error:

    Data tag parsing failed: Expected '}' but got ':' at: {oc:data:<--[HERE]

    This is the command I'm currently using:

    /give @p opencomputers:storage 1 1 {oc:data:{oc:fs.label:"openos"}, display:{Name:"OpenOS (Operating System)"}}
  11. Hello everyone! Direwo... eh, not quite right.

    Well, OpenGlasses for 1.12 is out! And I noticed there were no public button API for it, so I made one myself!

    I have a few functions built-in to make it easier to change stuff, but it was created with simplicity in mind. So if you simply just initialize a button and bind a function to it, it won't do any fancy stuff except for activating the function when you press it, so you have to add your own functionality to it:

    3d8e7c6ea70368e7380a6e0884f47e72.gif

     

    But with a little bit of extra code:

    04c14e1852118c5b37749b6571376011.gif

     

    Ok, not that big a difference, you guys are probably more creative than me!

     

    I also have a concept called "groups". When creating a button, you can specify what group it should be in. So if you want to change the color of all the buttons to the left side to pink, you can do that.

    Functions (in no particular order):

    --Needs to be called before creating any buttons, works as a reset also:
    gButtonAPI4.initialize()
    
    --Creating a new button element:
    gButtonAPI4.createNewButton(name,group,display,x,y,w,h,color: table,transparently,callback: function)
    
    --Has to be inside of your main loop:
    gButtonAPI4.update()
    
    --Prints all registered groups:
    gButtonAPI4.printGroups()
    
    --Change the visibility of the button/group:
    gButtonAPI4.visibility(button/group,boolean)
    
    --Change the color of the button/group:
    gButtonAPI4.Color(button/group[,color: table])--None for default color.
    
    --Same as color, but changes the label:
    gButtonAPI4.Label(button/group[,text])--None for default label.
    
    --Add a button to a group:
    gButtons.addToGroup(button,group)

     

     

     

    If you don't want to make a new function for each new button, you can then bind them all to the same function. And add a parameter to your function, the name of the button that was clicked will be returned:

    local function btniF(buttonx)
      gButtons.Color(buttonx,{0,255,0})
      print("I am " .. buttonx .. "!")
      os.sleep(0.5)
      gButtons.Color(buttonx)
    end

     

    I added a Demo program that shows most of the library's functions. Oh, btw, I like the number 4. It's not like this is my fourth attempt creating this or anything!

    Write a reply if you have any questions, this was my first attempt to create a usable library.

    gButtonAPI4.lua

    gButtonsDemo.lua

  12.  

    Hi!

     

    I have been working on a program for a few days on and off. But I kind of hit a wall on what I should do to make it work.

    It's supposed to be a program that scans the environment through a geolyzer installed inside a tablet, and thereafter sends the scan data through a linking card to a stationary computer with a OpenGlasses' terminal. It will then go through each entry and check its value to determine whenever or not it's an ore, a liquid or if it's indestructible.The tablet program will ask for the player's location and how a large area it should scan, then asks if the player wants to send this data to be processed.

    The tablet program will ask for the player's location and how a large area it should scan, then asks if the player wants to send this data to be processed. The stationary computer should just receive and process the data, then create 3D graphics at the player's location. I've got the collection and transmission part done, but I have problems with how I would go about to draw this on the glasses.

     

    Tablet program:

    local c = require("component")
    local geo = c.geolyzer
    local tunnel = c.tunnel
    local event = require("event")
    local ser = require("serialization")
    
    local coords = {}
    local rows = {}
    local radius
    
    
    local function isInt(n)
    	n = pcall(function() return n==math.floor(n) end)
    	return not n
    end
    
    local function readCoordinates(cor)
      local w = {}
      for word in string.gmatch(cor,"%S+") do
    	table.insert(w,word)
      end
      coords = {
    	  x = w[1],
    	  y = w[2],
    	  z = w[3]
      }
    end
    
    
    
    
    io.write("Your coordinates: ")
    readCoordinates(io.read())
    if coords.x == nil or coords.y == nil or coords.z == nil then
      print("You didn't type them in correctly.")
      coords = {
        x = -3042,
        y = 56,
        z = 3031,
      }
    end
    
    io.write("Radius: ")
    radius = io.read()
    if radius == "" or isInt(radius) then
    	print("You didn't type it in correctly.")
    	radius = 5
    end
    
    tunnel.send("UserData",ser.serialize(coords),radius)
    os.sleep(1)
    
    for x=-radius,radius-1 do
      for z=-radius,radius-1 do
        print("Scanning: " .. x .. " " .. z)
        table.insert(rows,ser.serialize(geo.scan(x,z,false)))
      end
    end
    io.write("Scan Complete. Send data?[Y/n] ")
    if string.lower(io.read()) == "y" then
    	tunnel.send("maxPack",#rows)
    	os.sleep(0.2)
      for i=1,#rows,4 do
    		tunnel.send("Data",rows[i],rows[i+1],rows[i+2],rows[i+3])
    		print("Sending package " .. i .. "/" .. #rows .. ".")
    	  os.sleep(0.2)
    	end
    	print("Sending package " .. #rows .. "/" .. #rows .. ".")
    	print("Data sent.")
    end

    Stationary computer with Glasses terminal:

    local c = require("component")
    local event = require("event")
    local ser = require("serialization")
    local holo = c.hologram
    local glasses = c.glasses
    
    
    local radius
    local coords
    local localCoords = {
      x = -3051,
      y = 51,
      z = 3027
    }
    local rows = {}
    local maxPack = 0
    
    local isDone = false
    
    local function receive(evt,_,_,_,_,msg1,msg2,msg3,msg4,msg5)
      print("Received Message:")
    
      if msg1 == "maxPack" then
        maxPack = tonumber(msg2)
        print(msg2 .. " total packages.")
      end
    
      if msg1 == "UserData" then
        io.write("Coordinates are: ")
        coords = ser.unserialize(msg2)
        radius = msg3
        io.write("X:" .. coords.x .. " Y:" .. coords.y .. " Z:" .. coords.z .. " Radius: " .. msg3 .. "\n")
      end
    
      if msg1 == "Data" then
        table.insert(rows,ser.unserialize(msg2))
        table.insert(rows,ser.unserialize(msg3))
        table.insert(rows,ser.unserialize(msg4))
        table.insert(rows,ser.unserialize(msg5))
      end
        print("Size: " .. #rows .. "/" .. maxPack)
    end
    
    local function cleanUp()
      print("Interrupted. Press [ctrl+alt+c] to exit.")
      event.ignore("modem_message",receive)
      event.ignore("interrupted",cleanUp)
    end
    
    local function toGlasses()
      local times = 1
      while times < #rows do
        for i=-radius,radius do
          for d=-radius,radius do
    
          end
        end
        times=times+1
      end
    end
    
    
    local function createDot(x,y,z,color)
      local dot = glasses.addDot3D()
      dot.set3DPos(x+0.5,y+0.5,z+0.5)
      dot.setColor(table.unpack(color))
    end
    
    
    local function update()
      if #rows > 0 then
        toGlasses()
      end
    
    end
    event.listen("modem_message",receive)
    event.listen("interrupted",cleanUp)
    
    
    --createDot(0,5,0,{255,0,0})
    
    while true do
       update()
       os.sleep(1/5)
    end

     

  13. On 2017-12-23 at 8:51 PM, Molinko said:

    Ive loaded your script and api and they seem to be working as expected..

    I see the test button and when i click the 'Working.' message is printed.

    I'm not getting your error at all. Perhaps reboot, its possible an older dev version of your 'gButtonAPI3' is or was still loaded when you ran your test.

    if you don't already know, this trick can be helpful while developing apis and testing them as you tweak them.

    
    package.loaded.myAPInameHere = nil -- # require is idempotent. purge it!
    local api = require 'myAPInameHere'
    
    api.stuff()

     

    Yeah, I had already rebooted the computer with the program on it. I eventually gave up for the day, next day I began working on it again. And hold and behold, it works!

    Maybe it solved itself when I restarted the game (restarted my computer). I hadn't restarted the game at all that day, so that could have been the problem. I highly doubt it was because of my computer and simply the game. I have to keep that in mind in the future to restart my game once in a while so I don't go nuts over stuff like this.

     

    I made this library because I couldn't find any myself. I thought of sharing it. You know where I can post my library so it doesn't disapear into the depth of the internet and falls into oblivion (and has to be re-invented again)?

  14. Hi!

    I have some problems with getting this library to work that should add buttons to the hud of the mod OpenGlasses:

    I made it first as a program and then converted it to a library for better organization of the code (and for later use). It worked fine when it was a program that called it's own functions, but now it throws errors when it calls them from another program. It says it can't insert the value to the empty table "API.buttonsName". When it was a standalone table it worked fine to insert the value into it, but it keeps saying the that spot is "bad" (that it doesn't exist?). I did try as you guys can see another method to insert it, to no success.

    Here is the program that calls the library:

    --buttonTest1.lua
    local gButtons = require("gButtonAPI3")
    
    local function test1()
      print("Working.")
      
    end
      
    gButtons.createNewButton("box1","Box 1",2,8,45,15,255,0,0,test1)
    
    while true do
      gButtons.update()
    end

    And here is the whole library (better write too much than too little):

    --gButtonsAPI3.lua
    local component = require("component")
    local event = require("event")
    
    local API = {}
    
    local glasses = component.glasses
    
    API.buttons = {}
    API.buttonsNames = {}
    
    local xV, yV = -1,-1
    
    
    function API.createNewButton(name,label,x,y,w,h,cR,cG,cB,callback)
      
      --API.buttonsNames[#buttonsNames+1] = name
      table.insert(API.buttonsNames, name)
      API.buttons[name] = {
        rect = glasses.addRect(),
    	lbl = glasses.addTextLabel(),
        posRect = {x,y},
        sizeRect = {w,h},
        colo = {cR,cB,cG},
    	state = false,
    	callbk = callback,
    	
    	posTxt = {x + (w / 2) - ((string.len(label) / 2) + (w / 4.5)),y + (h / 3)}
      }
      
      
      API.buttons[name]["rect"].setPosition(x,y)
      API.buttons[name]["rect"].setSize(w,h)
      API.buttons[name]["rect"].setColor(cR,cG,cB)
      API.buttons[name]["rect"].setAlpha(0.4)
      
      API.buttons[name]["lbl"].setPosition(API.buttons[name]["posTxt"][1],API.buttons[name]["posTxt"][2])
      API.buttons[name]["lbl"].setText(label)
      API.buttons[name]["lbl"].setScale(1)
      API.buttons[name]["lbl"].setColor(255,255,255)
      
    end
    
    function clickEvent(id, device, user, x, y, button, maxX, maxY)
      fX = x * (512 / maxX)
      fY = y * (288 / maxY)
      xV = fX
      yV = fY
      
    end
    
    
    
    local function initialize()
      
      event.ignore("interact_overlay", clickEvent)
      event.listen("interact_overlay", clickEvent)
      
      
    end
    
    
    initialize()
    
    
    function API.update()
      os.sleep(1/20)
      
      for i in pairs(API.buttonsNames) do
    	if 
          xV >= API.buttons[API.buttonsNames[i]].posRect[1] and xV <= API.buttons[API.buttonsNames[i]].posRect[1]+API.buttons[API.buttonsNames[i]].sizeRect[1] and
          yV >= API.buttons[API.buttonsNames[i]].posRect[2] and yV <= API.buttons[API.buttonsNames[i]].posRect[2]+API.buttons[API.buttonsNames[i]].sizeRect[2] then
    	  
          API.buttons[API.buttonsNames[i]].callbk()
    	  xV = -1
    	  yV = -1
    	  
    	end
      end
    end
    
    return API

    And the error log is attached to this post as a picture:

    If anyone got any idea what could be the error, I gladly accept any answer! If anyone has questions about the code just ask me and I'll try explaining what it does (or rather "should" do).

    ErrorLua2.png

  15. Hi!

    I'm trying to do buttons in a OpenComputers addon OpenGlasses. But it seem to have problems with calling the element from the table. I am not very used to Lua and this is my first big project I'm working on in Lua.

    local component = require("component")
    local glasses = component.glasses
    local buttons = {}
    
    local function newButton(name,x,y,w,h,cR,cG,cB)
      buttons[name] = {
        rect = glasses.addRect(),
        pos = {x,y},
        size = {w,h},
        colo = {cR,cB,cG}
      }
      buttons[name][rect].setPosition(buttons[name][pos][1],buttons[name][pos][2]) --Here it says the value is null.
      buttons[name][rect].setSize(buttons[name][size][1],buttons[name][size][2])
      buttons[name][rect].setColor(buttons[name][colo][1],buttons[name][colo][2],buttons[name][colo][3]) --And probably here too...
    end
    
    newButton("box1",2,2,10,10,255,0,0)

     

    It says the variable it's trying to reach is null for some reason. Any help would be appreciated.

    ErrorLua1.png

  16. Hi!

    I have a elevator program that controls a elevator though buttons on a screen. I have a new screen on each new floor that gets re-bound to the gpu every time to save computer resources. These other screens are never turned off, they only sit there until the elevator is on the same floor as it.

    So my question is: Does it drain less power (rf/t) to turn off the screens when they are not in use? Or does it not matter whenever they are on or off. In real life if you turn off a computer screen you will save more power, but I'm not sure how it is in OpenComputers.

  17. Ok, I solved it.

    if tostring(gpu.getScreen()) ~= tostring(screens[i]) then
    	gpu.bind(tostring(screens[tonumber(i)]))
    	gpu.setResolution(29,15)
    	tty.clear()
    	doButtons()
    end

    It seems like Lua doesn't convert the variables sometimes. So it searched for example "1" instead of 1.

  18. Alright, thanks.

    I did try to add this part to the click function:

    if gpu.getScreen() ~= screens[i] then
        gpu.bind(tostring(screens[i]))
        doButtons()
    end

    But for some reason it won't switch to that screen. When I do it manually in the Lua interpreter it works fine. You know what the problem is?

  19. Ah, yes. I am a noob when it comes to Lua, so if there is a very simple and obvious solution to this problem let me apologize in advance.

    Alright, here is the problem: I have this mod Thut's Elevators installed so you can make realistically working elevators in Minecraft. I have this program to control the elevator through buttons on a tier 2 screen. But due to how the mod is made you can't have a screen on board in the elevator, so I need to have a screen on each new elevator destination. The buttons are working and can send the elevator from one screen, but I can't switch it to another screen and re-draw the buttons when arriving.

    Here is the code:

    local component = require("component")
    local tty = require("tty")
    local event = require("event")
    local gpu = component.gpu
    local lift = component.lift
    local screen = component.screen
    
    local bkgrdColor = gpu.getBackground()
    
    local buttons = {}
    
    
    local screens = {
    "a4bd2de3-cbaf-4a4b-ac3b-acf2dbd62bc1",
    "f48c1033-81ea-432d-ae91-73bfaca47334",
    "2bb63258-c785-42be-8598-573e457a38d7",
    "c07ce065-ac3a-4877-9802-ee381036d1a1",
    "cc5570bc-cbb1-4966-9586-171938103bcd",
    "ef89a0c1-615a-4998-a6e2-d701a22260cf",
    "acce1910-793e-4668-81a0-8ddac3f26bab",
    }
    
    local floors = { --The Y-coordinates the elevator stops by 1-7.
    "67",
    "72",
    "78",
    "83",
    "88",
    "93",
    "98",
    }
    
    local currentScreen = screens[1]
    
    local function newButton(x,y,number)
      gpu.setBackground(0x990000)
      gpu.fill(x,y,3,3," ")
      gpu.set(x+1,y+1,number)
      gpu.setBackground(bkgrdColor)
      buttons[number] = {x,y}
    end
    
    local function doButtons()
      newButton(2,2,"1")
      newButton(6,2,"2")
      newButton(10,2,"3")
      newButton(14,2,"4")
      newButton(18,2,"5")
      newButton(22,2,"6")
      newButton(26,2,"7")
    end
    
    gpu.setResolution(29,15)
    tty.clear()
    
    
    doButtons()
    
    
    while true do
      local _,_,x,y = event.pull("touch")
      
      
      
      for i in pairs(buttons) do
        
    	
    	
    	
        if x >= buttons[i][1] and x <= buttons[i][1]+3 and y >= buttons[i][2] and y <= buttons[i][2]+3 then
    	  
    	  currentScreen = screens[i]
    	  
          gpu.setBackground(0x008153)
    	  gpu.fill(buttons[i][1],buttons[i][2],3,3," ")
    	  os.sleep(0.05)
    	  lift.callFloor(tonumber(i))
    	  gpu.setBackground(0x990000)
    	  gpu.fill(buttons[i][1],buttons[i][2],3,3," ")
    	  gpu.set(buttons[i][1]+1,buttons[i][2]+1,i)
    	  gpu.setBackground(bkgrdColor)
        end
      end
    end

    The elevators API:

     

    2017-10-19_20.03.58.png

×
×
  • Create New...

Important Information

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