7 posts
Posted 26 January 2013 - 06:07 PM
I've been trying to make a quarry script for a while now and I was in the progress in making a function where I pass coords in and the turtle would go to the coords I tell it. But I can't figure out why I am getting the error message.
soup:93: attempt to index ? (a nil value)
I think it must be something to do with the tables but I can't find any information on functions inside tables etc.
Here is my code.
http://pastebin.com/c3r7ue2DThis is my first post so please treat me all noobish if you need to.
1190 posts
Location
RHIT
Posted 26 January 2013 - 06:19 PM
You forgot to pass self into the function on line 93.
Here is your code:
setDirection = function(strFacing)
repeat
self.setDirection()
until coord.direction == strFacing
end
Here is what it should be:
setDirection = function(self, strFacing) --You would need to pass the 'smart' table into the function in order to use setDirection in this case. A bit of a pain if you ask me.
repeat
self.setDirection()
until coord.direction == strFacing
end
Just as a side note, why are you using self.funcs() rather than just calling smart.funcs()? It's easier to just call the table as if it were an api unless you want this to have multiple variations in the form of objects.
7 posts
Posted 26 January 2013 - 07:09 PM
I tried putting in the self argument but still the same error.
7508 posts
Location
Australia
Posted 26 January 2013 - 07:24 PM
Try it with self:setDirection() shouldn't make a difference but it might.
Edit: uhhh why are you recursively calling the function without changing the coord.direction for you repeat condition?
1190 posts
Location
RHIT
Posted 27 January 2013 - 03:26 AM
Just to clarify Bit's response above, self:setDirection(arg) is essentially the same thing as doing self.setDirection(self, arg). And yeah, as it is right now, your will just call itself infinitely and never actually turn the turtle.