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

    • Lizzy Trickster

      Latest Stable OpenComputers Version   11/26/16

      The latest released version of OpenComputers is version 1.7.2 for MC 1.7.10, 1.10.2, 1.11.2 & 1.12.2. See more information here! Beta/Dev builds can be found at the Jenkins Build Server (ci.cil.li)

The Simon

  • Content count

  • Joined

  • Last visited

About The Simon

  • Rank
    Junior Member
  • Birthday 05/03/1998

Contact Methods

  • Minecraft

Profile Information

  • Gender
  1. Trouble with Geolyzer and OpenGlasses addon

    Here is a gif of it in action:
  2. 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
  3. Trouble with Library

    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)?
  4. Trouble with Library

    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).
  5. Trouble with Lua

    Thanks! I knew I was close to the solution, but I knew I couldn't solve it myself.
  6. Trouble with Lua

    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.
  7. 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.
  8. Computer controlled Elevator

    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.
  9. Computer controlled Elevator

    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?
  10. Computer controlled Elevator

    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:
  11. Dude, the reason it won't connect is because you don't have Project Red - Compat installed. There is unfortunately no version for Minecraft 1.10.2 yet. You could make a analog redstone converter for the different colors, so if there is a redstone signal strength of "1" it should toggle the white cable. Redstone strength of "2" could be orange, etc.