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

Suck From Slot Fails Without Robot Moving Away, Is This Intended?

Question

I've run into a weird situation, I have a robot trying to put items into a machine and retrieve them. I have this set up in a loop that while there is still materials to insert or materials being processed, or materials in the output the robot tries to execute a series of functions. This works flawlessly until the last loop. At this point, there is no more materials within the Robot's inventory, there is no more materials in the input slot of the machine, and only materials in the output slot. If I understand my logic correctly, it should try to pull items out of the machine. In fact when checking the robot logs, it does. It will infinitely loop printing "Sucking items from slot" and then "Sucked items:false". Now keep in mind the robot hasn't changed directions or moved and it has successfully inserted and extracted many resources within this loop. Am I missing something here?

function fillSmasherAndGetShards()
  local inputSlot = 2
  local outputSlot = 3

  local inputSlotDetails = getExternalSlotDetails(sides.front, inputSlot)
  local outputSlotDetails = getExternalSlotDetails(sides.front, outputSlot)

  -- While we still have potash to process or there is something in either the input or output slot
  while findSlotByItem("Potash") ~= nil or inputSlotDetails.size > 0 or outputSlotDetails.size > 0 do
    -- Try to put more potash in
    if inputSlotDetails.size < inputSlotDetails.maxSize then
      local potashSlot = findSlotByItem("Potash")
      if potashSlot ~= nil then
        robot_api.select(potashSlot)
        inventory.dropIntoSlot(sides.front, inputSlot, 1)
      end
    end

    -- Try to take potash shards out
    if outputSlotDetails.size > 0 then
      print("Sucking items from slot")
      local suckTest = inventory.suckFromSlot(sides.front, outputSlot, outputSlotDetails.size)
      print("Sucked items:" .. tostring(suckTest))
    end

    -- Update slot details
    inputSlotDetails = getExternalSlotDetails(sides.front, inputSlot)
    outputSlotDetails = getExternalSlotDetails(sides.front, outputSlot)

    os.sleep(1)
  end
end

 

Share this post


Link to post
Share on other sites

6 answers to this question

Recommended Posts

  • 0

Hey,

The issue seems to be related to the 'inventory.suckFromSlot' method, as you can see from your log 'Sucked items:false'. The 'false' indicates that the method was called, but failed. There are several reasons why this method could fail, but since it works in the beginning, parameters like the slot-number should be correct. So I guess either there is not enough inventory space in your robot or there is a calculation error within your 'getExternalSlotDetails' function.

You could provide the code for your other utility functions, then I can have a look at them.

Share this post


Link to post
Share on other sites
  • 0
4 hours ago, CptMercury said:

Hey,

The issue seems to be related to the 'inventory.suckFromSlot' method, as you can see from your log 'Sucked items:false'. The 'false' indicates that the method was called, but failed. There are several reasons why this method could fail, but since it works in the beginning, parameters like the slot-number should be correct. So I guess either there is not enough inventory space in your robot or there is a calculation error within your 'getExternalSlotDetails' function.

You could provide the code for your other utility functions, then I can have a look at them.

Sure, below is the code for that function. What's interesting to note: is if I add a print statement before my suckFromSlot

print("Size of inputSlot:"..inputSlotDetails.size)
print("Size of outputSlot:"..outputSlotDetails.size)

It will print:
Size of inputSlot:0
Size of outputSlot:6
And that will print out every time it loops. So tit does seem to be seeing the outputslot of the machine has something in it.

function getExternalSlotDetails(side, slotNum)
  local returnTable = {}
  local slotTable = inventory.getStackInSlot(side, slotNum)
  if slotTable == nil then
    returnTable.size = 0
    returnTable.maxSize = 100
  else
    for tableKey, tableValue in pairs(slotTable) do
      if tableKey == "size" then
        returnTable.size = tableValue
      elseif tableKey == "maxSize" then
        returnTable.maxSize = tableValue
      end
    end
  end

  return returnTable
end

 

Share this post


Link to post
Share on other sites
  • 0

Yeah, so the 'suckFromSlot'-method does not move items.

I haven't found bugs in your code, so I assume it works. So here are a few questions:

- Is the inventory of your robot full?

- Were items sucked from the output slot in the loops before? Maybe you cannot extract items from that side of the machine?

- What is the standard stack size of the output slot? try to read it when there are no items in this slot

Share this post


Link to post
Share on other sites
  • 0
1 hour ago, CptMercury said:

Yeah, so the 'suckFromSlot'-method does not move items.

I haven't found bugs in your code, so I assume it works. So here are a few questions:

- Is the inventory of your robot full?

- Were items sucked from the output slot in the loops before? Maybe you cannot extract items from that side of the machine?

- What is the standard stack size of the output slot? try to read it when there are no items in this slot

1. It is not, many slots are empty.

2. Yes plenty of items have been sucked in that loop until the last iteration.

3. Max size is 64.

Share this post


Link to post
Share on other sites
  • 0
On 4/30/2020 at 11:01 AM, CptMercury said:

Yeah, so the 'suckFromSlot'-method does not move items.

I haven't found bugs in your code, so I assume it works. So here are a few questions:

- Is the inventory of your robot full?

- Were items sucked from the output slot in the loops before? Maybe you cannot extract items from that side of the machine?

- What is the standard stack size of the output slot? try to read it when there are no items in this slot

I'm truly starting to think this is some weird edge case bug but I don't have any clue why it is. I should note the machine is from ExtraPlanets so maybe there's something wrong with how that is interfacing with OC? I'm far from knowledgeable when it comes to Scala so I'm not sure.

Share this post


Link to post
Share on other sites
  • 0

Yea, probably some weird bug with the machine.

Did the slot you're currently sucking into fill up before that last loop? I mean if the slot is full the robot should search for an empty one but this could be bugged as well. Can't test it atm tho.

With standard stack size I meant what stack info do you get if you run inventory.getStackInSlot() on the machine with an empty output slot?

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

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