I didn't manage to find proof for otherwise, but the default functions doesn't accept parameters. For example:
turtle.forward(3) would move 3 and so on.
Is there something I am missing or that is not implemented? One easy API would most likely add that, but wouldn't it be better for everyone if it is native?
Default API accepting parameters
Started by morbeo, Nov 11 2012 01:13 AM
7 replies to this topic
#1
Posted 11 November 2012 - 01:13 AM
#2
Posted 11 November 2012 - 01:54 AM
I think that work but as I can't test it you can do that :
a = 0 While a <= 3 do turtle.forward() a = a+1 end
#3
Posted 11 November 2012 - 02:00 AM
or:
however, there are several programs/APIs which add different ways or shortened ways of moving turtles around.
for i=1,3 do turtle.forward() end
however, there are several programs/APIs which add different ways or shortened ways of moving turtles around.
#4
Posted 11 November 2012 - 02:00 AM
Well, yes, there are brazzilion ways to make such a loop and do stuff, but I'm inquiring about native support of parameters. And it's not just about the movement of the turtle. A lot of functions can use a parameter.
#5
Posted 11 November 2012 - 07:12 AM
This is not implemented and it would be bad if it were. The current system uses a Boolean return value to indicate success or failure of the movement attempt. Changing the behavior to loop with a parameter means also changing the return values, which means that the niceness of shortening a quick for loop down to a single line is offset by having to figure out where exactly in that movement the movement failed, etc. This would not be a useful change. You could always create a quick API to wrap the turtle movements in a for loop if you really want.
#6
Posted 11 November 2012 - 12:18 PM
you could made it return two values so you could still use it normally:
return success, n_before_failure
where success is whether or not the turtle finished it's movement and
n_before_failure is -1 if success = true or the number of times it moves until it failed.
return success, n_before_failure
where success is whether or not the turtle finished it's movement and
n_before_failure is -1 if success = true or the number of times it moves until it failed.
#7
Posted 12 November 2012 - 01:28 AM
Nah. If you want this create it yourself - not going to get into CC.
#8
Posted 13 November 2012 - 11:15 PM
Lyqyd, on 11 November 2012 - 07:12 AM, said:
This is not implemented and it would be bad if it were. The current system uses a Boolean return value to indicate success or failure of the movement attempt. Changing the behavior to loop with a parameter means also changing the return values, which means that the niceness of shortening a quick for loop down to a single line is offset by having to figure out where exactly in that movement the movement failed, etc. This would not be a useful change. You could always create a quick API to wrap the turtle movements in a for loop if you really want.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











