187 posts
Location
attempt to index "location" (a nil value)
Posted 22 January 2016 - 04:57 AM
I am working on a ComputerCraft peripheral addon, and one of my planned peripherals requires consuming items from a stack in the turtle's inventory (specifically the selected slot), but I cannot find a method to modify the turtle's inventory in ITurtleAccess (you can read it, but there seems to be no setInventory(). Is there a way to do this with a different part of the API, or will I have to abuse turtle.drop() to make this work?
For more specific details, I am making a "claw" peripheral that allows a turtle to right click blocks (such as levers, buttons, ore berry bushes, etc.), but in some cases I actually need to consume one of the held item, such as when placing an item in a sieve from Ex Nihilo.
8543 posts
Posted 22 January 2016 - 05:22 AM
Why won't ITurtleAccess' getInventory method work?
187 posts
Location
attempt to index "location" (a nil value)
Posted 22 January 2016 - 09:45 PM
Does that allow you to modify the original object? I am used to lua where function returns just give you a copy of the data rather than the original.
8543 posts
Posted 23 January 2016 - 01:14 AM
That's not how Lua works.
The IInventory object that the getInventory method returns has methods to change the contents of the inventory, which is what you'd use to modify the turtle's inventory.
187 posts
Location
attempt to index "location" (a nil value)
Posted 23 January 2016 - 03:21 AM
Alright, I'll look into the methods of IInventory. (and I guess I am still a little confused on the way lua works as well) Thanks for the help!
7083 posts
Location
Tasmania (AU)
Posted 23 January 2016 - 03:44 AM
(and I guess I am still a little confused on the way lua works as well)
The point Lyqyd's presumably getting at is that Lua doesn't have any rules as to whether its functions return copies of objects or not. That's entirely up to the functions in concern - but as a general rule, you'd quite rightly expect that a function/method/whatever named "getObject" will get you
that object, regardless as to the language you're using.
187 posts
Location
attempt to index "location" (a nil value)
Posted 23 January 2016 - 04:39 AM
The point Lyqyd's presumably getting at is that Lua doesn't have any rules as to whether its functions return copies of objects or not. That's entirely up to the functions in concern - but as a general rule, you'd quite rightly expect that a function/method/whatever named "getObject" will get you that object, regardless as to the language you're using.
My main reason for confusion was the fact that nearly every other function had a "set" and "get" variant, just not that one function. I should probably read up a bit more on objects too then.