3 posts
Posted 11 November 2012 - 01:13 AM
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?
386 posts
Location
France
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
536 posts
Posted 11 November 2012 - 02:00 AM
or:
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.
3 posts
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.
8543 posts
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.
536 posts
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.
2447 posts
Posted 12 November 2012 - 01:28 AM
Nah. If you want this create it yourself - not going to get into CC.
3 posts
Posted 13 November 2012 - 11:15 PM
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.
I think I get what you mean that it complicates the code. Thank you all for the answers.