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

Molinko

Members
  • Content Count

    451
  • Joined

  • Last visited

  • Days Won

    35

Posts posted by Molinko

  1. Thanks, I doubt I am using this correctly, but the event.listen() working as a "background" process if you will, works for what I need.

    Wobbo makes a point. Lua has no real parallelism. But, post some code. I like seeing what others are making :)

  2. Pedrosgali is right! That is the best part about coding. No one way to achieve functionality! In that regard the above post of mine was a half assed quick and dirty approach. I should've posted something more in depth for support.

  3. I dont know all the function names for the mffs miner but this pseudo code should be close enough for you to get the gist of  it.

    local m = component["mffs_miner??"] -- mffs miner thingy here..
    
    local keys = {
      -- w is the key you want bound to this function
      w = function( ... )
        return m.forward() -- miner relevant direction per key press here
      end,
      s = function( ... )
        return m.backwards() -- same as above but for key 's'
      end,
      -- etc...
    }
    
    while true do
      local event = {event.pull()}
        if event[1] == "key_down" and keys[event[2]] then
           -- if key press and key is a registered key bind then
           keys[event[2]]()
        end
    end
    
  4. There is no code for this, I am simply trying to use the Adapater Block to get the amount of power stored in a Capacitor Bank (Ender IO) using the "getEnergyStored" method.

     

    It always returns 0 even though that value is not correct.

    Try iterating over all of the sides. Maybe its a bug or brain fart.

    -- ## where 'c' is the component
    for k,v in pairs( sides ) do
      print( "side:", k, "energy:", c.getEnergyStored( v ) )
    end
    
  5. The piping is a feature of besh (which can be found on a loot disk). I think currently it's not even horribly broken. To make stuff compatible for piping, basically make sure to use the `io.read` and `io.write` methods instead of operating on the term or gpu directly, besh automatically wraps those.

     

    Thanks for the reply. I was messing around in creative and found the besh disk. What  I was way more curious about t how is something like that used and what is a decent example use case? Could one use it for say logging errors to a file or what?

  6. I am trying to get the Adpater Block to read the RF from an Ender IO capacitor bank.  I've been able to read the "max power" (in MJ) but I cannot get the energy stored to work.  Has anyone had luck with this?  The block had 250,000RF (250 MJ stored).

     

    wIlEDqS.png

     

    If you can post your current, if any, code and any / all error msgs you have received id be happy to help.

  7. https://www.youtube.com/watch?v=alEiZFmPNP0

     

    I saw, in the video above, that the openOS shell supported pipes, streams, and io redirection. Now Im not sure what the heck all that is but it sounds and looked so useful. Could somebody maybe point me to a good reference on how to use these capabilities or maybe explain like im five, but have been using lua for a year.. I've dabbled in most of the data type of lua and know em alright but I'm a total linux/unix noob and could use a hand understanding how and why someone would use this stuff(pipes n such). Thanks for any help in advance.

        - Fast Eddie

  8. Heh, yeah, they're still experimental, so no big fanfare just yet ;) There are quite a few things that still need doing, such as making them use energy, and probably make them insertable into disk drives to allow charging them and editing their file systems.

    Yes, that's one of the few cards/upgrades that actually work :P

     

    Hmm, MC1.6 or 1.7? I did some fixing for 1.7 in 1.3.4, and it worked fine when I tested it.

     

    I haven't added WAILA back in since i updated to 1.3.4 but i was struggling to find out what was crashing me while making a 1.7 pack until i realized that whenever I placed a screen I crashed. Then I realized after dumping mod after mod to compare compatibility with OC, it was WAILA  popping up as soon as I placed a screen and failing to look up the block correctly, or some such error.

  9. Aha. I see you're hard at work on your very own solution! Allow me to give a tip or 5 :)

     

    Today we'll talk a little about OOP or Object Oriented Programming. Now, in lua, OOP is a little different than in other more popular OOP languages such as JAVA.

    So for you guys out there who would say lua doesnt have oop... You probably know better than me. With that said lets learn some stuff about simulating OOP in lua.

     

    First off there are tables. myTable = {}. In lua tables are used as objects because every table created is unique. Not table references though. i.e. myTableA = myTable, this is referencing myTable.

     

    With this in mind we can create objects with behavior relevant to that object. Still following? Example:

    local Bob = {}
      Bob.name = "Bob"
      Bob.age = "32"
    -- ## Bob works 40/60 hrs per week so he cant play enough MC with OC  . Must support them lousy kids. >
      Bob.familyMan = true
    
    function Bob.introduce()
      return "Hi, my name is " .. Bob.name .. ". I'm " .. Bob.age .. " years old."
    end
    
    print(Bob.introduce()) --> output: "Hi, my name is Bob. I'm 32 years old."
    

     

    If you notice the Bob object has specific fields, name and age, that identify him. The fields arent so unique but the Bob object is.

    Bob isnt very flexible as an object though. This brings me to Classes. Classes are Objects. But, they are not the same as lets say Bob.

    Bob is an instance of a Class. We usually wont interact with a class like we would an instance of a class. For example:

    -- ## This is a class
    local Person = {}
    
    function Person.create( name, age )
      -- ## This is our instance of this class
      -- ## It will be unique and relevant to the 'Person' class and act like a 'Person'
      local newPerson = {}
        newPerson.name = name
        newPerson.age = age
       -- ## notice newPerson.introduce is actually the same function value as Person.introduce
       -- ## its main argument is the table or 'instance' of a person
        newPerson.introduce = Person.introduce
      return newPerson
    end
    
    function Person.introduce( person ) -- ## notice the argument isn't 'Person' but a 'person' instance
      return "Hi, my name is " .. person.name ..". I'm " .. person.age .. " years old."
    end
    
    -- ## Here we create a new instance of the 'Person' class named "Al" and stored in the variable 'Al'
    local Al = Person.create( "Al", 28 )
    -- ## Here we use a Class method(function) that operates on our Class instances.
    -- ## It can do this because the class knows how to treat an instance of its class.
    print( Person.introduce( Al ) ) -- > output like before but with "Al" age "28"
    -- ## Or we can call it like so from the instance:
    print( Al:introduce() ) --> notice the colon ':' syntax instead of a dot '.'
    -- ## A colon between a table and a method(function) in that table will pass the table to the function as the first argument
    -- ## Its is exactly the same as:
    print( Al.introduce( Al ) )
     

     

    Now for my main point.. Buttons. Buttons are a class. We want uniqueness and specified behavior.

    local Button = {} -- ## This is our class declaration not our instance of a button we'd use
    
    -- ## This is an 'instance constructor'. It makes making new button objects easy
    function Button.create( text, x, y, width, height, color )
      local newButton = {
         text = text, -- ## newButton.text = text(argument)
         x = x,
         y = y,
         width = width,
         height = height,
         color = color,
         draw = Button.draw
       }
    end
    
    function Button.draw( self )
      -- ## 'self' here is the reference to the button instance itself not the 'Button' class
      local oldColor = gpu.setBackground( color )
      gpu.fill( self.x, self.y, self.width, self.height, " " )
      -- ## im not centering the text here.. just an example..
      gpu.set( self.x, self.y, self.text )
      gpu.setBackground( oldColor )
      return true -- not really necessary just good to have returned something..
    end
    
    -- ## instances that we would use.
    local button1 = Button.create( 'test1', 4, 4, 10, 3, 0x00FF00 )
    local button2 = Button.create( 'test2', 4, 8, 12, 5, 0x0000FF ) -- ps i dont know wtf these colors are...
    
    button1:draw() -- ## draw button 1.
    --
    

     

    I hope this will help you understand the power of OOP like design and some of the more basic ways to use it :)

    As usual any questions or elaborations by others are welcome. If someone else can explain better please do! lua is my first language!

  10. Haha, "poorly optimized" is an understatement, and thank you for the feedback/input on it! It was a "quick and dirty" port just to get it working into OC. I am sure if you opened up the ComputerCraft version and compared it to this, you will see it is almost identical with 'just' enough changes to make it work.

     

    I find it very interesting how that whole for loop was replaced by a simple mon.fill and mon.set (if I am understanding this correctly)...I never even thought about that. Like I stated before, I know 'just' enough LUA to be dangerous with it, but I don't fully know its 'ins and outs' if you will.

     

    As for the "API" naming method, to be honest, I did that just to help myself out with what was being called from the API/Library and to help become more familiar with how tables work in general. (yea, my brain works....differently.... that way), not to mention that there is already a table in use called 'button' that gets used within the API itself.

     

    I have been looking through the various component pages of the main site to try to get better educated with what each does and how each works, I just struggle with ways on how to better utilize them, like how you did with the fill function.

     

    And finally, yes it has helped, alot. I will try testing/implementing this when I have a bit more free time (married, kids and 50~60 hr workweek leaves very little free time).

     

    Ah don't be harsh on yourself. It was a good little exercise for you to port im sure. Its a great way to improve your understanding of lua. A few months back and that woulda confused the crap out of me too. I would recommend looking into the lua pil (programming in lua). If you need any more help or have questions just ask.

  11. Sangar you sneaky bastard!! There is a very subtle yet powerful addition in the 1.3.4 update! check spoiler below > :)

    http://imgur.com/TcHMzOZ

    Yup. No, I'm not trolling. Look up Tablet Case in NEI or creative OC tab.

    Components are limited to teir 2 and you can even have some robot upgrades, although im not sure how to use them! JUST found this not 10 minutes ago!

    NOTE: There is no way to load a floppy to the hard drive from the tablet itself. It is created in the assembler like a robot and cannot be fitted with a floppy drive so you must load a boot-able image or install openOS on the hard disk on another computer before you start the assembler!

    Start writing them ftp servers boys and girls!!

    Sangar I think I love you. Have my children, or at least keep up the good work :P

  12. I've noticed that the hard drive is constantly writing. Also you have to set the right/large enough resolution for the game to load properly or you just get stuck in some weird spammy draw loop. I'm not sure but I think the event loop is being spammed in the background and I think this is leading to alot of lag on button presses and overall responsiveness. But, I freakin' love the gui and the game looks like it will be great! Great job so far mang.

  13. I could give you a few tips and critiques if you're up for it. First of good job. It needs some real work to be any good with open computers though. I understand the want for

    a familiar api from computercraft venturing into OC, but it's just very poorly optimized for OC. For instance:

    function API.fill(text, color, bData)
      mon.setBackground(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
        term.setCursor(bData["xmin"], j)
        if j == yspot then
          for k = 0, bData["xmax"] - bData["xmin"] - string.len(text) +1 do
             if k == xspot then
                term.write(text)
              else
                term.write(" ")
              end
           end
         else
           for i = bData["xmin"], bData["xmax"] do
             term.write(" ")
           end
         end
      end
      mon.setBackground(Black)
    end
    --------------------------------------------
    -- ## A much faster and easier way to draw,
    -- ## You'll notice the buttons will draw much much faster!!
    
    function API.fill(text, color, bData)
      -- ## this part works just fine
      local yspot = math.floor((bData["ymin"] + bData["ymax"]) /2)
      local xspot = math.floor((bData["xmax"] - bData["xmin"] - string.len(text)) /2) +1
      -- ## save any previous color used before, not just black
      local oldColor = mon.setBackground(color)
        -- ## gpu.fill(x,y,width,height,char) char here = " " for a blank space of color
        mon.fill(xmin, ymin, (xmin+xmax-1), (ymin+ymax-1), " ")
        -- ## write your text here from the gpu.set function instead of io.
        mon.set(xspot, yspot, text)
        -- ## reset the old color
        mon.setBackground(oldColor)
    end

    Also, naming a table of functions in the api 'API' is awkward and could be misleading or confusing for others and newer users.

     

    Check out this page for some more component functions like gpu.fill() and such.

     

    I hope this helps. Feel free to add it into the existing code for a quicker drawing update! Any questions are welcome :)

  14. http://named-data.net/project/archoverview/

     

    An interesting read on a new network protocol called NDN. Check it out. I think it could be handy for a OC networking architecture if it were made even simpler.

    What do you guys think. I'm a total network noob but iIhave been researching IP and routing protocols for the last few days so this was a nice palette cleanser from the( hellish, i think) state of IP and current routing protocol of IP packets. Please, share dem thoughts.

     

     

  15.  

    The event hooks and timers will only get called when event.pull() is called. So you need to add something like

    while true do
       event.pull()
    end
    

    I fixed my issue above. It was missing :

    function testfunc( ... )
      print( table.unpack({ ... }) ) -- this was the issue not the listener
    end
    

    I imagine event.pull() is called automatically when using event.listen( event, callback ).

    Event listeners will even persist outside of their parent program. Handy for stuff like apis signalling sister programs from the background.

    Thanks for the reply.

  16. -- Fixed: I was le tired....

     

    I'm kinda new to OC just moved over from cc and I'm loving the mod!!

    I was curious if someone who knows how event.listen handles its callback function?

    I tried to make a simple wireless network port listener just for testing and to my avail i couldnt get it to work the way i intended...

    Example below:

    local component = require "component"
    local event = require "event"
    
    local modem = component.modem
    
    modem.open( 1 )
    
    ## I was assuming that event.listen would feed the signal/event with its parameters
    ## to the callback function.. reason why not? I'm no pro but I figured maybe this was
    ## overlooked??
    local function testfunc( ... )
      print( ... ) -- modem_message and params should print 
    end
    
    event.listen( "modem_message", testfunc ) -- Why you no pass params!!
    

    Sorry if this post was out of place.. Any clarification would be nice :) I know there are other ways to do this but i was curious.

      Thanks in advance

     

     

    I was being stupid... It was late and I was a tad drunk...Nevermind me :P

×
×
  • Create New...

Important Information

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