This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Mariomarco's profile picture

Useful changes to the turtle_API [my opinion]

Started by Mariomarco, 28 December 2012 - 01:39 PM
Mariomarco #1
Posted 28 December 2012 - 02:39 PM
Hello CC community,

[indent=1]I recently worked a lot with the computercraft mod and I realized that some additional functions would be very handy.
As an example you can view my most recent program [[topic='7643']forum post[/topic] | direct]
In the Index you can click on function checkItems() this function isn't up to date but In the newer version this code is even longer.
Whats the point you're wondering? this "checkItems" function could be a single api function,
because in the API there is only the turtle.suck() implemented and I think it would be nice to see a optional parameter to add which allows you to pick the quantity you want to select.
Another Idea I came up with was the "Advanced" turtle module which adds the ability for more API functions like the one I mentioned before.[/indent]
[indent=1]
SpoilerFeatures I'd like to see in the Advanced module:
-turtle.suck([quantity])
-turtle.compareLeft()
-turtle.compareRight()
-turtle.check(Datavalue)
etc I think you know what I mean (:
[/indent]


I hope you got the taste of my Ideas, this is only a suggestion and if you disagree with me please post your opinion in the CommandBox down below :D/>
[Also pls don't slap me ^^ I'm not native English so my language might be a bit weird i hope you can forgive me.]

Greetz. Marco
immibis #2
Posted 28 December 2012 - 09:45 PM
turtle.suck(quantity) can be implemented with turtle.suck and turtle.drop, something like this: (untested)

function advSuck(slot, quantity)
  local invBefore = {}
  for k=1,16 do invBefore[k] = turtle.getItemCount(k) end
  turtle.select(slot)
  turtle.suck()
  local anyChanged = false
  for k=1,16 do
    local old, new = invBefore[k], turtle.getItemCount(k)
    if new > old then
      anyChanged = true
      local diff = new - old
      if diff > quantity then
        turtle.select(k)
        turtle.drop(diff - quantity)
        quantity = 0
      else
        quantity = quantity - diff
      end
    end
  end
  if not anyChanged then
    return false
  end
  if quantity > 0 then
    return advSuck(slot, quantity) -- tail call
  end
  return true
end
but it would be REALLY NICE if it was built-in.

compareLeft and compareRight would be useful for speed.

What would check do?
Mariomarco #3
Posted 29 December 2012 - 12:02 AM
I think this would be useful to check the BlockID, so you don't have to compare the blocks.
In my opinion a good way to save space but a good equalizer would be if the turtle looses 4 slots of the inventory?
Cloudy #4
Posted 29 December 2012 - 12:07 AM
BlockID… Don't even go there :P/>
Mariomarco #5
Posted 29 December 2012 - 12:28 AM
maybe the module costs 3 diamonds? :D/> than it would be a tiny bit more balanced.
or maybe the advanced module adds a colored screen and/or a bigger turtle Inventory ^^
Sebra #6
Posted 29 December 2012 - 03:06 AM
-turtle.suck([quantity]) - not urgently needed in my opinion. turtle.suckTo(slot), restricted to that slot only would be more convenient.
-turtle.compareLeft(),-turtle.compareRight() - simple and convenient. .compareBack() too. Doubt it will be added :(/>
-turtle.check(Datavalue) - what is it?
immibis #7
Posted 29 December 2012 - 10:49 AM
maybe the module costs 3 diamonds? :D/>/>/>/> than it would be a tiny bit more balanced.
or maybe the advanced module adds a colored screen and/or a bigger turtle Inventory ^^
Making it cost more doesn't offset the fact that it makes no sense.
I'd much rather have these in all turtles than in a module (except for check which, as stated, doesn't make sense).

Although I still want database turtles in vanilla CC.