MiscPeripheral + Applied Energistics @ ME Bridge

Discussion in 'Mod Discussion' started by Slackerony, May 26, 2013.

  1. Slackerony

    Slackerony Active Member

    Can someone explain how this works? - I want a simple program, that, spits out a list of items on a bunch of monitors above it.
    However, i seem to not be able to make it work - Help is appreciated.

    Here's what i got:

    To start with, i just wanted it, to spit out the list on the computer at hand. Putting it up on the monitor, i believe i know how to do.

    m = Peripheral.wrap("left") -- The ME Bridge was on the left side.
    m.listAll()

    I run the program, and nothing happens, What am i missing?


    Note: I havn't used MiscPeripherals much. and my lua isn't noteworthy either :p
     
  2. ratchet freak

    ratchet freak Well-Known Member

    you may wish to do

    Code:
    for ID,amount in pairs(m.listAll())do
      print(id..": "..amount)
    end
    also was it connected to a (powered) ME network
     
  3. Slackerony

    Slackerony Active Member

    Yes, it's powered. test:6: attempt to concatenate nil and string

    Line 6 is the ...print(id..": "..amount)

    However, I tried adding another dot, so it's ... print(id...": "...amount)

    This made the error msg, change to "bios:337: [string "test"]:6: ')' expected

    I realise it's a ) that's missing, but where, i don't know.
     
  4. Platinawolf

    Platinawolf Active Member

    Hmm,,, Sure its just not capitalized the (ID.. ": " ..amount) ? Mind you, I speak JAVA and not LUA so i might be way off in that computers are bloody stupid and can't tell that id and ID are the same thing ^^*
     
  5. Slackerony

    Slackerony Active Member

    Negative - I tried changing the ID to id, and still have the same problem. Nothing has changed :-(
     
  6. Hydra

    Hydra Popular Member

    Can you post the entire blob of code in code tags? Can't help you if we can't see if you messed something up.

    The string concatenation operator is two dots by the way, don't just add dots and hope it works.
     
  7. Slackerony

    Slackerony Active Member

    Hence why i mentioned what i changed, so that if i was wrong, he could tell me, :) - Also i believe it was one of direwolfs video's where i saw him use 3 dots, And thus i thought that might fix it.
    Code:
    m = peripheral.wrap("left")
    m.listAll()
    s = peripheral.wrap("top") -- top is the monitor, havn't actually used this line for anything yet though
     
    for ID, amount in pairs (m.listAll())do
      s.print(id..": "..amount)
    end
    And with that we're back to "test:6: attempt to call concatenate nil and string

    edit: Also, Trial and error is the only way forward, if u don't know what you're doing :) or ask for help - Which i am.
     
  8. Hydra

    Hydra Popular Member

    ID is not the same as id. Case matters.
     
  9. Slackerony

    Slackerony Active Member

    Attempt to call nil. Is what i'm getting after changing ID to id.
     
  10. Hydra

    Hydra Popular Member

    Is there actually a monitor on the top?
     
  11. Slackerony

    Slackerony Active Member

    Yep - I just tried without the s. And without, it works, So now it's the monitor part, i suppose
     
  12. Hydra

    Hydra Popular Member

    I had to check the API docs but monitors actually don't have a "print" function, and that's also not what's in the example the other guy gave you. Monitors are written to through the write function.

    When learning any programming stuff it's important not to try everything at the same time. Seperate the thing in separate subproblems and work them out one by one. Learn how to write to a monitor and how to interface with the AE bridge separately and when you have figured both out combine them.
     
  13. paulwood15

    paulwood15 New Member

    ok thanks for the help above^^^
    but now im having problems with the retrieve method and i always get an error of just 3
    heres my code:
    m = peripheral.wrap("left")
    m.retrieve(1, 100, 1)
    i want to just for testing purposes retrieve 100 stone and output it through side 1.
     
  14. Hydra

    Hydra Popular Member

    I have no experience with that part of the mod, what you could try:
    - Make sure the id you have is actually in the list you get from listAll. I believe they're not block IDs but some kind of internal ID.
    - I don't know if you can actually get more than a stacksize at a time, try a number less than 100 (1 or so as a start ;)).
    - Make sure you have the right direction
     
  15. Hydra

    Hydra Popular Member

    Actually: I just tried it and I think the thing is just broken at the moment.
     
  16. ratchet freak

    ratchet freak Well-Known Member

    you need to use the same ID you get from listAll() not the item ID (they are different)
     
  17. Hydra

    Hydra Popular Member

    I tried it myself. Doesn't seem to work at all.
     
  18. snooder

    snooder Well-Known Member

    OP, try putting a "".. in front of id. So it's like (""..id.." : "..amount).

    What's probably happening, not 100% sure about lua, but it happens in other languages, is that the concatenation operator takes it's functionality from the argument to the left of the operator. In languages where this is an issue, putting an empty string "" all the way to the left forces an initial string concatenation and then that cascades forward so the entire expression is evaluated as a series of string concatenations.
     
  19. voidreality

    voidreality Member

    Force what's printed to be a string. Will stop the type errors given from print.

    Code:
    print(tostring(k)..": "..tostring(v))
    As far as the monitor. It works exactly like the term API. The API can be found here. http://computercraft.info/wiki/Term_(API)
    So in this case you could do something like
    Code:
    m = peripheral.wrap("left")
    mon = peripheral.wrap("top")
    myList = m.listAll()
     
    mon.clear()
    y = 1
    for k, v in pairs (myList) do
      mon.setCursorPos(1, y)
      mon.write(tostring(k)..": "..tostring(v))
      y = y + 1
    end
     
    Slackerony likes this.
  20. paulwood15

    paulwood15 New Member

    Ok thanks. I had a cool jdea tho where i had a second base somewhere and have my main storage at my main base and i would request an item over rednet and it would send it over on a railcart.
    Is there any other way to do this?
     

Share This Page