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

Search the Community

Showing results for tags 'lua'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • OpenComputers
    • Announcements
    • Feedback
    • IRC
  • Code Central
    • Support
    • Showcase
    • Tutorials
  • Addons & More
    • Addons Mods
    • Architectures
    • OpenEngineering Task Force
  • General
    • Lounge
    • Forum Games
    • Showcase
    • Servers
  • Archives
    • Public Archives

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Minecraft


GitHub


IRC


Fediverse ID


Location


Interests

Found 40 results

  1. Getting the followong error message: Until expected (to close "repeat" at line 15) near "elseif": https://pastebin.com/tRz7VnRE Not sure what the problem is, can anyone explain what i could do? thx! start.lua
  2. Hello. I’m entirely new to Opencomputers and Lua scripts. I’m not familiar with the language nor can I code. I would like ask how to create a automatic door to open with a passcode. I have all the components just don’t know how to make it all work! Thanks in advance ;)
  3. SavageNoob

    OpenSecurity

    Hello, I was wondering if anyone could point me in the direction of a sample code to interact with these machines, the card writer most importantly. I attempted and failed miserably, do not know how to copy and paste code from within the minecraft opencomputer system. I am a complete noob so bear with me. I tried to use and edit this (I know its the wrong mod, i need a reference point as there is none for this mod besides the wiki) and get an attempt to call nil. I would also like to know how to program the other machines such as the keypad, i see the example code but how and where do i put it? Do i have to connect it to a computer first? So confused. Thank you in advance,
  4. Yarkın

    AE2 API help

    Hello everyone! I want to use AE2 api. But i don't know the formats of the tables that functions take or return. Where can i learn these easily?
  5. So I made myself a little lua script to read the inventory of my me storage system and also list the amount of bytes they require. Its my first script so I'm sure there are better ways to do all of this. The Me Network is connected to the Computer via an adapter on the me controller of the network. Pastebin here Now what it does is it uses the getItemsInNetwork function to list all items in a loop and display the name and amount of Bytes of each item in one line. A line counter goes up for each of the items added which is needed later. After all Items are listed it displays the total amount of Bytes available as well as the amount of bytes used and then the percentage of used storage. And finally at the very end a timer is displayed that counts down from 60. Once this timer is over the script refreshes and goes through the list of items again so that the item counts are updated. here is where I used the line counter so that the very last line could get cleared and replaced with the new timer that displays one second less on every loop until it hits zero and the script refreshes. This script has worked for me for quite a while and on a second me system that only holds 3 different types of items it still does. On my main me storage however this script is starting to break at the very end with the timer line no longer being overwritten and instead adding multiple lines alongside the new timer line like so: And here is how it looks on the other me system: Here the line "Time until refresh: n" is replaced the way its supposed to. The only difference between the two scripts is that the one that works uses the getFluidsInNetwork function instead. Is there a way for me to fix this or is it a problem of having too many items in storage ? Additionally tips on how to improve this script in general are welcome as its my first and could probably be improved a lot.
  6. Hello guys i am Symbo i know this is a simple tutorial but the fact that idk programming well let's talk about it! Now the programming language as named LUA is a programming language that is very easy to learn! Let's get start with an explication of what you sould start with. Now whos like me that dosen't know programming well your here to learn some. You sould go ahead and get ComputerCraft and learn CC's lua because it's the same but some apis are modified because OC uses direct lua. This is the most inpersive concept of learning lua without learning the apis. First of all i am not a programmer i will not teach you lua, it's your opinion if you want to learn lua or not. Now the fact that lua is easy to learn you sould first learn ComputerCraft... well heres some apis that will actualy help you programming some programs term.clear() term.setCursorPos(X, Y) print("STRING") Now those are some basic stuff. CC has basic lua so you will learn much much basics from CC, If you do that then you can learn OC because if you know CC already then it wil lbe 5x more easier to learn because only some apis are changed from the basic lua. The stuff you don't need at CC is components, components are the basic stuff you start with and they are optional for OC (Open Computers) Now you sould learn CC first and then OC because it will be very very easy to learn DIRECT LUA I recommend lua 5.3 because lua 5.2 is not even doing good anymore. Now if you wanna change the cpu to lua 5.3 then just brick right click in air and you will see in chat what type of lua you changed. Now replay if you want i will try replaying to the replay you did so if this makes no sense then i will call your replays comments. Now let's start with some basic stuff that people are very lazy to do Well the first stuff is learning, people whos lazy dosen't even have time to learn but they have to make thier programs. But what if programming languages was about explaining what the program does Like While the program is open then Open the other program. end Well this is not how it works. People stop being lazy reading and start learning! - Post end -
  7. Description: I need a controling system for distance control of my bunker. Mods: OpenComputer for 1.12.2 Opensecurity for 1.12.2 OpenGlasses for 1.12.2 Functions: Door state control Lock/Unlock doors Key card locks for piston doors All of it must controled from glasses from openglasses If you don't understood somethink, please write and i will answer you as soon as posible. And sorry for mistakes, i'm from Russia ans not master of english.
  8. I have tried for a long time to figure out a way to read a NBT Tag from Lua but all it says when I hit enter is 'nil "0"'. For example: In reactorcraft, you can make toroid magnets, and for some reason unlike other blocks in reactorcraft, you cannot read the tank levels. So, you must get the NBT data. I looked in the mod files and found the tags, but when I put the string into the function to get the NBT Tag, it says 'nil "unknown error"', meaning it knows that it is a recognized tag, becuase otherwise with a random string nothing happens. Please help me get this data from LUA!! Thanks, DMANisAWESOME
  9. It seems completely funny but I am actually trying to get through this for the last 2 days: I try to access weather data through the OpenWeatherMap.org API wich seems to work fine with internet.request(url). The problem is just that it returns me the JSON as a table instead of a String. I tried to access fields of that table but everything seems to return nil. I just can't get to access anything from that table. There are tons of JSON serialization librarys out there but they all need the JSON as a String. I am completely lost rn. This is the API response that gets stored as a table for some reason: {"coord":{"lon":7.68,"lat":52.85},"weather":[{"id":500,"main":"Rain","description":"light rain","icon":"10n"}],"base":"stations","main":{"temp":10.51,"pressure":999,"humidity":66,"temp_min":10,"temp_max":11.11},"visibility":10000,"wind":{"speed":5.1,"deg":230},"rain":{"3h":0.11},"clouds":{"all":92},"dt":1552771115,"sys":{"type":1,"id":1871,"message":0.0045,"country":"DE","sunrise":1552714945,"sunset":1552757625},"id":2810860,"name":"Werlte","cod":200} My Lua code couldn't be simpler: local web = require("internet") local data = web.request(<API_LINK>) -- data is of type table and I don't know how to get any values. Tried so many combinations on indices. -- For each loop works to loop through everything though
  10. hi i am okay to computercraft but a complete newb to openccomputers but here is my question I have made a program in cc and then ported it over to oc it works but for some unknown reason will it not read the data from my table or maybe from ae2 itself here is the code so what's wrong local component = require "component" local gpu = component.gpu local colors = require("colors") local term = require "term" local me = component.me_interface local monX,monY = gpu.getResolution() local low = 64 local meItems = { [1] = {"Iron Ingot","minecraft:iron_ingot","0"}, [2] = {"Sand", "minecraft:sand","0"}, [3] = {"Acasia Wood","minecraft:log2","0"}, [4] = {"Acasia Planks","minecraft:planks","4"}, [5] = {"SawDust","Mekanism:Sawdust","0"}, [6] = {"Paper","minecraft:paper","0"}, [7] = {"Cactus","minecraft:cactus","0"}, [8] = {"Cactus Green","minecraft:dye","2"}, [9] = {"Ink","minecraft:dye","0"}, [10] = {"Red Dye","minecraft:dye","1"}, [11] = {"Purple Dye","minecraft:dye","5"}, [12] = {"Gray Dye","minecraft:dye","8"}, [13] = {"Light Gray Dye","minecraft:dye","7"}, [14] = {"Light Blue Dye","minecraft:dye","12"}, [15] = {"Dandyline Yellow","minecraft:dye","11"}, [16] = {"Aluminium Ingots","TConstruct:materials","11"}, [17] = {"Stone","minecraft:stone","0"}, [18] = {"CobbleStone","minecraft:cobblestone","0"}, [19] = {"Gold Ingots","minecraft:gold_ingot","0"}, [20] = {"Copper Ingots","Mekanism:Ingot","5"}, [21] = {"GlowStone Dust","minecraft;glowstone_dust","0"}, [22] = {"Glass","minecraft:glass","0"} } function checkMe(checkName, name) melist = me.getAvailableItems() for a = 1, #melist do itemName = melist[a].fingerprint.id .. melist[a].fingerprint.dmg value = tostring(melist[a].size) if itemName == checkName then centerT(name, row+2, 0x000000, 0x0024BF, "lefty") if tonumber(value) <= low then centerT(value, row+2,0x000000, 0xBF0000, "righty") else centerT(value, row+2,0x000000, 0x0FBF00, "righty") end row=row+1 end end end function checkTable() row = 1 clearScreen() for i = 1, #meItems do checkName = meItems[2] .. meItems[3] name = meItems[1] checkMe(checkName, name) end end function clearScreen() gpu.setBackground(0x000000) term.clear() term.setCursor(1,1) centerT(" ME Inventory ",1 ,0x0F00BF , 0xFFFFFF,"head") end function centerT(text,line,txtback,txtcolor,pos) gpu.setBackground(txtback) gpu.setForeground(txtcolor) length = string.len(text) dif = math.floor(monX-length) x = math.floor(dif/2) if pos == "head" then term.setCursor(x+1, line) term.write(text) elseif pos == "lefty" then term.setCursor(2,line) term.write(text) elseif pos == "righty" then term.setCursor(monX-length, line) term.write(text) end end while true do checkTable() -- sleep(10) end
  11. I'm writing a kernel that has cooperative multi-tasking. It works great, but one job of it is to track a process' memory usage. It can track more memory being used but If the coroutine sets a bunch of stuff to nil, it should be able to subtract the difference as well. However sometimes the garbage collector might not get around to freeing it by the time the test is performed leading to an inaccurate result. Is there some way of forcing a garbage collector cycle?
  12. I am attempting to write an OS from scratch and I have come up with a couple questions that somebody can hopefully clarify for me as I cannot continue without the following knowledge. 1).Since a critical function like require is unavailable, can someone point me to general steps needed to write a custom require function. 2).What would be needed to implement a custom filesystem without any libraries from openos. Any help is greatly appreciated
  13. I did a program to manage my batteries and reactors, and i got a problem in reactor.setActive(true/false) for address, name in pairs(reactorsID) do local reactor = component.proxy(address) countR = countR + 1 local tR = (countR + count) * 3 progressBar( name, tR, reactor.getEnergyStored(), reactor.getEnergyCapacity(), 0x00bb00, true, "RF") progressBar( "Reactor(Energy Last Tick)", tR + 3, math.ceil(reactor.getEnergyProducedLastTick()), 6200, 0x00bb00, true, "RF") if brPower + totalPower < brMaxPower + totalMaxPower then reactor.setActive(True) else reactor.setActive(False) end end The reactor doesn't turn on or off, and the program doesn't return any error . Here is the full code : https://pastebin.com/gkmtstis
  14. Got this error, but i have no idea how to fix it, need some help!. Here is the code. local component = require("component") local term = require("term") local gpu = component.gpu local cube = component.basic_energy_cube local event = require("event") local colors = { black = 0x000000, red = 0xC14141} gpu.setBackground(colors.black) term.clear() local infos = {} cube["stats"] = {} function setInfos() infos["stored"] = { x = 3, y = 2, weight = 73, height = 1, title = "STORED ENERGY : ", unit = " RF"} infos["capacity"] = { x = 3, y = 4, weight = 73, height = 1, title = "BATTERY CAPACITY : ", unit = " RF"} end function printInfos(infoName) local maxLenght = 15 local i = infos[infoName] gpu.set(i.x, i.y, i.title .. cube.stats[infoName] .. i.unit) end function updateCubeStats() cube.stats["stored"] = cube.getEnergyStored end function startup() updateCubeStats() setInfos() printInfos() end startup() repeat updateCubeStats() until event.pull(0.1) == "interrupted"
  15. I did this program, it's very simple, but i want to terminate it and i don't know how to do it... I tried Ctrl + C, Ctrl + Alt + C. I need some help. local component = require("component") local term = require("term") local event = require("event") local keyboard = require("keyboard") local cube = component.basic_energy_cube local computer = component.computer local gpu = component.gpu local w, h =gpu.getResolution() local colors = {} colors.gray = 0x555555 colors.red = 0xFF0000 colors.lime = 0x00FF00 function label(x, y, message, color, ...) local color = color or gpu.getForeground() local oldColor = gpu.getForeground() gpu.setForeground(color) term.setCursor(x, y) print(string.format(message, ...)) gpu.setForeground(oldColor) end function toMRf(val) return val / 1000000 end function toJ(val) return val / 4 / 100000 end os.sleep(2) term.clear() computer.beep(1000,1.5) while true do energy = toMRf(cube.getEnergyStored()) energyMax = toMRf(cube.getMaxEnergyStored()) energyJ = toJ(cube.getEnergyStored()) energyMaxJ = toJ(cube.getMaxEnergyStored()) label(1, 1, "%.2f MRf / %.2f MJ (Energia Acumulada)", colors.red, energy, energyJ ) label(1, 3, "%.2f MRf / %.2f MJ (Capacidade da bateria)", colors.lime, energyMax, energyMaxJ) end
  16. So I am coming from ComputerCraft and the term API there is pretty straight forward and allows us to create windows to write / redirect to. Anyway, in the term API wikipage of OpenComputers there is for example the method term.bind with an optional parameter "window", the problem is I can't find any information about this parameter and I assumed that this would be the same kind of "window" as in CC and I won't have to write my own API for it. Do you guys know something about it?
  17. Gladox114

    Testing nummber

    I know that "not nil" is wrong but how to test if the input is a nummber and do something when input is a nummber. read = io.read() if string.match(read, "(%d+)") == not nil then -- do something end
  18. Gladox114

    Testing nummber

    I know that "not nil" is wrong but how to test if the input is a nummber and do something when input is a nummber. read = io.read() if string.match(read, "(%d+)") == not nil then -- do something end
  19. Michael

    Energy Stored

    Hello everyone, I'm trying to set up a Opencomputers energy monitoring system that will control the energy level of an Industrialcraft2 mfsu by turning on 1 to 6 reactors but I'm having problems at the energy reading part. Here is my code so far: https://pastebin.com/654kRYaf (ignore that getEnergyStored is commented out, I was testing something and uploaded to pastebin wrong version), but here is an abbreviated version with comments: -------------start of script---------- local fill = 0 --predefine variable fill local cap = 0 --predefine variable capacity require 'normal' things (event, component, term, colors, sides) local rs = component.redstone --Redstone I/O block local mfsu = component.ic2_te_mfsu ---as shown when components is run ----------create writing------------------ ---create writing and boxes ----------reset redstone (just in case) ---- set colors used to 0 ------------------------------------------- ------------------------------------------------------------------------ while true do local _,_,x,y = event.pull("touch") -----works up to this point fill = mfsu.getEnergyStored() --find amount of energy in mfsu cap = mfsu.getMaxEnergyStored() --find capacity of mfsu print(fill, cap) ---print it (temp) --------check user clicks squares and set redstone outputs-------- --//insert computer turn on reactors here (to do later)\\-- end ---end of script--- I plan to implement code that will turn off and on the reactors depending on the amount of energy in the mfsu but I havent been able to read the amount of energy in the mfsu to be able to make the calculations. (the big empty space on the left of the screen is for a progress bar that is currently hidden, which depends on the amount of energy in the capacitor) As you can see (bellow) the code works fine until the user clicks the screen, at which point it errors, the Max energy or current energy "returns a nil" and the code discontinues running. to my understanding this means that this doesn't exist therefore what is the current terminology? I could find one that works but I wanted to make one myself. Minecraft v. 1.10.2 Age Of Engineering v. 1.1.2 (Twitch modpack) OpenComputers v. 1.7.1.150
  20. I sent the command '=component.printer3d.addShape(6,6,0,9,7,0,"hardened_clay_stained_lime")', and ended up with this error 'empty block' That's it. What am I doing wrong?
  21. Good morning. I have a problem with an operation to do in the LUA language: I have a file in which I have stored data, separated by line. I would need to read this file and store every line of this in an array, ignoring the first one. For example: array = {line2, line3, etc} Next, I would also need to compare each of these lines with a string, to check if it is contained, and I would need to know how to do both. Thanks in advance for the help.
  22. 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).
  23. 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.
  24. Hello, for a few last days now, I've been having hard times with lua. I'm using OpenSecurity addon, but this problem I'm having more with lua. When I use Entity Detector it returns me table with info about entities around it. I can print those with function for k, v in pairs(output[1]) do print(k, v) end but I don't know how to make from this table unique variable strings, so I could have checked if the entity is me or not. I know that it will probably be some easy function, but I can't find it anywhere on the internet. I'm almost beginner in Lua, so please don't kill me Thanks
  25. 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:
×
×
  • Create New...

Important Information

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