Dog, on 12 June 2015 - 12:56 AM, said:
What you're doing is calling the functions and thus setting a, b, c, & d to the output returned by the functions you're trying to set them equal to. Removing the brackets will allow you to set your variables the way you wish, like so
local a = turtle.forward
local b = turtle.turnRight
local c = turtle.turnLeft
local d = turtle.back
a()
b()
c()
d()
Thank you Dog, so the brackets make the function start? Sorry if im not understanding it right, maybe it might be a language problem. But anyway, did what i wrote make any sence? I dont need it for my program, but i would like to know, if that could be in any way useful.
flaghacker, on 12 June 2015 - 05:14 AM, said:
But renaming functions isn't really a good practise. It may save some typing, but it makes the code harder to read in most cases.
Ye flaghacker, i'm trying to get more used to the longer text, for me, the renaming was usefull, because i could simply write my code without any loops etc. just to make the writing easier when im thinking about using more commands. I already understood, that this way of writing is not the "right" or the optimal one, but thats how i want to see, it, from a very primitive program to a better and better program :-)
Thanks
Assyrianos
Bomb Bloke, on 12 June 2015 - 05:28 AM, said:
It... depends. I don't like the readability aspect of it, not one bit. I also hate people writing functions when they don't have to (whereas some coders seem to like using function names as if they were comments, and so define them where there's absolutely no other point in doing so).
There is a potential benefit though, at least, in this case: Calling a() is faster than calling turtle.forward(), because the latter requires a table lookup whereas the former effectively has the table lookup result pre-cached.
However, that's a micro-optimisation, and you could argue that there's a time and a place for it. That is, to an extent, a matter of taste.
Certainly, though, if you're going to assign the function to a different variable, there's no excuse not to use a descriptive name for that variable.
True, esp when it gets longer. In this case, this program is more a kind of learning process for me, im just gimping around with diffrent ways to the same goal. I'll change from a,b,c,d to something like up, down, left, right..
Thanks for the advice and fast answers guys!
Cheers
Assyrianos