• Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
Welcome to OpenComputers

Register now to gain access to all of our features. Once registered and logged in, you will be able to contribute to this site by submitting your own content or replying to existing content. You'll be able to customize your profile, receive reputation points as a reward for submitting content, while also communicating with other members via your own private inbox, plus much more!

This message will be removed once you have signed in.

  • Announcements

    • Lizzy Trickster

      Latest Stable OpenComputers Version   11/26/16

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

Molinko

Members
  • Content count

    184
  • Joined

  • Last visited

  • Days Won

    20

1 Follower

About Molinko

  • Rank
    Leading Member

Profile Information

  • Gender
    Not Telling

Recent Profile Visitors

428 profile views
  1. The or keyword is binary and can only work on two variables. Each function you have is returning multiple values and only the first of each are being used and assigned.
  2. There seems to be a bug in the term lib loading a tty window. I think perhaps tty isnt fully loaded yet..? Try using term.read instead of io.. Maybe that'll help... If you get a new error that'd be helpful.
  3. Thanks, you're nice . It was my first language. ^^^ THIS. So much yes. I had a hard time grasping the concept of OOP at first because Lua doesn't have many of the features an OO language like Java and so on.. Personally an OOP-like library is the only real practical way in my opinion to even use OO in Lua. Writing actual program logic doesn't work so well this way.. Gets bloated quick. BUT, an OO library is easy to extend for a use case should you need it. Oh boy I've been trying forever to get this right. When I do I'll let you know . @Dustpuppy I agree. I just wanted to show you how big the world is... lol. If you really want to twist your brain for the better check out Functional programming. Also, a useful mind-fuck. As for the intended style Lua was built for... I believe its intended to be Procedural with a dash of meta-programming. As I said earlier, Lua was my first and still my favorite. This has been a nice discussion .
  4. yeah.. I was worried it might just look like spaghetti... Yes and No. Yes. The user of the library doesn't need or want to know how the library works to be able to use it and shouldn't have to either. No, because anyone like @Fingercomp who might like to use your library, even if it lacks a specific element, might like to be able to integrate a custom element and not have to write an entire library to do it. A good example would be to think of how similar a 'Label' and a 'Button' object are to each other. They can share ~90% of their code, so why rewrite the other 90% of a button if its just like a label with a touch event listener. -- # ... more gui shit above.. local Label = {} Label.__index = Label function Label:draw(fg, bg) local ofg, obg = gpu.setForground(fg), gpu.setBackground(bg) -- # self here refers to the label instance. The specific label calling draw. Label:draw is really a shorcut for Label.draw(labelInstance, fg, bg) gpu.fill(self.x, self.y, self.width, self.height, " ") -- # draw the box gpu.set( math.floor((self.x + self.width - 1) / 2 + #self.text / 2 + .5), math.floor(self.height / 2 + .5), self.text ) -- # center the label text. ugly gpu.setForground(ofg) -- # reset the fg and bg colors gpu.setBackground(obg) end local function newLabel(x, y, text, w, h) return setmetatable({ x = x, y = y, text = text, width = w, height = h }, Label) end local Button = setmetatable({}, {__index = Label}) -- # look to Label for :draw method Button.__index = Button local function newButton(x, y, text, w, h, action) local button = newLabel(x, y, text, w, h) button.action = action local listener = function(...) local _, x, y = ... if x >= self.x and x <= self.x + self.width - 1 then if y >= self.y and y <= self.y + self.height - 1 then action() end end end event.listen('touch', listener) -- # this is easy for the demo here but can be a memory leak if left after the program ends... return setmetatable(button, Button) end -- # End I hope this example, although not much less complicated, will help convey the point.
  5. @Fingercomp makes a great point. Without trying to use too much jargon.. OOP or Object Oriented Programming is a style of program or library organization that pairs 'Classes' with 'Instances'. This is hard to explain so I'll use an example that hopefully will demonstrate why OOP can be a powerful paradigm and useful to learn. -- # Person. Our 'Base' class for a set of more complex classes. local Person = {} -- # Use Person(name, age, sex) to use as an instance constructor. Person.__index = Person setmetatable(Person, { __call = function(_, name, age, sex) local person = { name = name, age = age, sex = sex } return setmetatable(person, Person) end }) function Person:introduce() return ("Hello, my name is %s."):format(self.name) end function Person:greet(otherPerson) return self:introduce() .. (" Nice to meet you %s."):format(otherPerson.name) end -- # Now we can create 'Persons' or 'instances' of Persons as we call them in OOP. local bob = Person('Bob', 49, 'male') local jane = Person('Jane', 33, 'female') print( bob:greet(jane) ) -- # > "Hello, my name is Bob. Nice to meet you Jane." -- # This is where OOP really shines and why it would be recommeneded. 'Inheritance'. local Wizard = {} Wizard.__index = Wizard setmetatable(Wizard, { __call = function(_, name, age, sex, spells) local wizard = Person(name, age, sex) -- # create a wizard from the Person class. Wizards are people too. Not all People are Wizards. wizard.spells = spells -- # Wizard specific return setmetatable(wizard, Wizard) -- # bestow Wizard methods upon wizard instance. end, -- # inheritance __index = Person -- # If a method or field isn't within a 'Wizard' then fallback to the 'Base' which is 'Person'. i.e wizardInstance:greet(bob) }) -- # Sub-class method override. function Wizard:introduce() -- # Wizard introductions should state the prestige that they are Wizards! return ("Hello, my name is %s the wizard."):format(self.name) end -- # Wizard:greet is inherited from Person. function Wizard:cast(spell, target) assert(self.spells[spell], "Invalid spell. Your Wizard is weak.") return ("%s the wizard casts '%s' upon %s for %d damage."):format(self.name, spell, target.name, self.spells.damage) end local merlin = Wizard("Merlin", 61, "male", { ["Abbra"] = { name = "Abbra", damage = 12 } }) -- # Notice :greet() is inherited from Person class but uses the merlin instances version of :introduce() print( merlin:greet(bob) ) -- # > "Hello, my name is Merlin the wizard. Nice to meet you Bob." print( merlin:cast('Abbra', bob) ) -- # > "Merlin the wizard casts 'Abbra' upon Bob for 12 damage." -- # End I hope this example can illustrate to you the advantages of OOP design. Any questions? ask away
  6. This looks great. Taking @Nexarius ' advice is a good idea. No term.clear(). bad, badbadbad. This makes the flicker. This angers the gods. Also, I would suggest using a gui library. Maybe @Gophers' GML or Zer0Galaxys' libforms. One more suggestion would definitely be, again @Nexarius suggestion, to use a lookup table rather than the long if-else chains you have set up. This would help with functions like 'reactorDataTable()' or 'captureKeys()'.
  7. I think Gorzoid means a 'debug' card
  8. You should check out what openOS does for require. Here. Specifically the package library Check out What's available. <-here Above its what's in the bare lua environment without a loaded os
  9. edit geo2holo.lua use arrow keys to navigate to line 29 type the magic words component.hologram.setScale(3) ctrl+s to save and ctrl+w to close the edit program. ...profit???
  10. You put component.hologram.setScale(3) online 29.... Then you run it... Then...??? Profit...???
  11. Craft a lua bios by using an eeprom and an OCmanual. Put lua bios and tablet in crafting bench. I THINK this might be possible... It works with drones.. If not use a disassembler :/
  12. projector.setScale(value:number) Set the render scale. A larger scale consumes more energy. The minimum scale is 0.33, where the hologram will fit in a single block space, the maximum scale is 3, where the hologram will take up a 9x6x9 block space.
  13. To answer you first question We have to understand that messages in OpenComputers are only the basic types: strings, numbers, booleans, and NOT tables and/or functions. This means that in order to have a robot take "commands" from another computer it has to have a special program that waits for special, known commands (a protocol) and executes either a simple command or maybe a more complex command like running another program from the filesystem and awaiting another command after it has finished the program. Here we'll make 2 very basic programs to do simple control of a robot. One for the client and one for the robot. -- # Client.lua local term = require "term" local component = require "component" local modem = component.modem assert(modem, "You need a modem dummy.") local port, robot_address = 15, "34eb7b28-14d3-4767-b326-dd1609ba92e" modem.open(port) while true do print "Enter robot command." local command = term.read() modem.send(robot_address, port, command) end -- # END Client.lua -- # Robo.lua local component = require "component" local event = require "event" local robot = require "robot" local modem = component.modem modem.open(15) -- # listen on port 15 like the client local commands = { ["printFuel"] = function() print("fuel lvl:", component.computer.energy(), "/", component.computer.maxEnergy()) end } setmetatable(commands, {__index = robot}) while true do print "Awaiting next command.." local msg = table.pack(event.pull("modem_message")) local command = msg[6] if commands[command] then print("Executing command [" .. command .. "]..") local ok, err = pcall(commands[command]) if not ok then print("ERROR: ", err) end end end -- # END Robo.lua DISCLAIMER: This is a proof of concept program and hasn't been tested but, with tweaking for any errors, should work as intended. To answer your second question, robot.forward and other movement methods are relatively slow without an experienced experience upgrade component. If you want to move multiple times without typing robot.forward X amount of times then you need to look into functions and how to use and write them. -- # This is a naive approach but works as intended. Simply. local function forward(times) times = times or 1 for i = 1, times do robot.forward() end end As for your third question... Theres quite a bit pack into it. Firstly you need an inventory_controller upgrade to manipulate and get info about inventories. The information returned about item stacks in slots is a table. Look into 'tables' in lua. They're fundamental, you'll need em sooner or later. Lemme know if you need some more information or clarification.
  14. Check out THIS post I answered before. A drone is exactly the same as a micro controller, with regards to the Lua environment, but with exposure to the drone 'component'.
  15. I'm at work so I cant give details right now but I would highly suggest you look at the "types" of values you can use to program, such as booleans or strings. These are paramount to the basics of programming and understanding documentation so you can help yourself better.