71 posts
Posted 19 November 2012 - 05:44 PM
Here is the full code:
http://pastebin.com/f2CHf08rError is on line 20. You can hopefully see what i'm trying to-do. I can't explain it that well, so but basically
Example:
aDirection = forward
turtle.aDirection()
This just errors attempt to call nil ofc so anyone got any ideas on how to fix this?
2088 posts
Location
South Africa
Posted 19 November 2012 - 05:49 PM
I've also tried this with term.setTextColours(colours[colour]). Does turtle[aDirection]() not work? This would help me too if someone posts how to get it to work.
1688 posts
Location
'MURICA
Posted 19 November 2012 - 05:53 PM
Short explanation:
aDirection = "forward"
turtle[aDirection]()
Longer explanation:
In the original example you've provided, the script sets variable "aDirection" to "forward", not "turtle.forward". Variable "forward" does not exist, therefore aDirection does not exist either.
On the second line, lua can't directly reference a string from a table using dot notation. It's the same as doing
turtle."forward"()
which obviously doesn't work. To get around this, you would put brackets around your string, and remove the dot.
turtle["forward"]()
71 posts
Posted 19 November 2012 - 05:54 PM
Seems it does, thanks! May I ask the reasoning behind that working? I'm just trying to learn more about lua :(/>/> Thanks KingDoro for the explanation!
2088 posts
Location
South Africa
Posted 19 November 2012 - 06:07 PM
Short explanation:
aDirection = "forward"
turtle[aDirection]()
So I was right :(/>/> Thanks from me too for the explanation.