ComputerCraft

ComputerCraft

21M Downloads

[Suggestion] turtle.getFacing();

MattB52 opened this issue ยท 13 comments

commented

Add a function to get the direction a turtle is facing such that it would return 0 for north, 1 for east, 2 for south, and 3 for west.

commented

It's worth noting you can already emulate this with turtle.inspect() and placing torches against a wall. Whilst this is a clever work around, it isn't quite the same as having functionality baked in.

I'm not sure using 0-3 as return values would be the best solution, especially as Lua tables start at 1. I'd personally prefer string literals, but each to their own :).

commented

I've seen this done as a peripheral before (using a compass), not sure how well it fits as its own feature.

I actually think 0-3 is a good idea as then you can do something like (direction + x) % 4 and still have a valid direction. Might be weird for tables, though its a little hard to handle as typically 1 index is not normal

commented

Turtle orientation pretty much fall in the same class than GPS coordinates, and with some cleverness, you can figure out your orientation using only two GPS.locate, I don't think it would be nessesary to add a function or a peripheral for it.

commented

I believe that this would be a good function to add. It wouldn't be hard to implement.

commented

It's less a question of "how it should be implemented" and more a question as to "whether it should be implemented".

Assuming the point of the mod is to get users to write code, this runs counter to that by removing the need for them to figure out their turtle's facing on their own.

There's also the "realism" aspect - using a peripheral for it is one thing (and as things stand, GPS already makes it trivial to get facing), but having turtles simply know their direction without an appropriate sensor is a different story.

commented

I think turtles should be able to do most of the things a player can do to improve the potential for automation. A player can read a compass, why can't a turtle? I don't think it should be built into the turtle without a peripheral however.

@BombBloke if the point of the mod is to get users to write code, then why is GPS code built into computers by default such that it's trivial to get a turtle's location with a minor physical setup?

@SquidDev and @xAnavrins, while it is possible to do already, it's just awkward. Why not just add the peripheral? It's hardly bloat, it doesn't unbalance anything, it just makes it easier to control turtles, and might even encourage more programming because the work required for a seemingly simple action is proportional to the action itself.

commented

I'm not the one to ask about the presence of GPS, though my guess is it's there because asking the average coder to do anything trig-related would be a bit of a turn-off - they still wouldn't write their own code for that if a first-party API were not available.

commented

@Lupus590 That would be a problem, if you run a program outside the shell environment e.g. os.run(). That would break compatibility with old programs.

commented

@Wilma456 Wojbie and I are adding the compatibility in such a way that the APIs are still os.loadAPI compatible. Which is the main reason we haven't been able to convert the rednet and term APIs yet.

commented

Another thing regarding, what BombBloke has called, first party code.

The Lua code built into CC not only help people do things with the mod easier and earlier but also serve and an example of how to do things.

That last point of being an example is why I'm trying to get the APIs to be require compatible as require is the proper way to load APIs now.

commented

require is the proper way to load APIs now

... is it?

commented

@BombBloke Probably not the best phrasing, but I recall Dan saying that if he could have figured out how to do require in the sandbox originally then he would have done so. I also recall that he would encourage new users of the mod to use require over os.loadAPI as it fits with how Lua is meant to work.

commented

Please keep this issues page for bugs, not feature requests. Historically CC has avoided giving computers/turtles "magic" knowledge of the world though.