Jump to content




Turtle additions


12 replies to this topic

#1 Lemur

  • Members
  • 15 posts
  • Location*.*

Posted 08 September 2014 - 05:43 AM

Not sure how many of these have been implemented quite yet, but:
  • Fix control flow operators in Lua (ie: turtle.detect() and turtle.dig() -- yes, convoluted example)
  • Compare to Block ID - No need to carry an instance of the block anymore
  • Turn around - literally turn 180
  • Add a rejection list upgrade (ie, drop all cobblestone)
  • Add a selection list upgrade (ie, keep only diamonds)
  • Allow for linking to ender chests / tesseracts / etc for instant transmission of items
  • Allow for refueling from power cells / assorted other energy sources in game
  • Allow for upgrades to capacity
  • Alias t to turtle for shorthand in the Lua shell
  • Bootstrapping options from known configurations (see my post on Chef in Ask a Pro)

If someone's working on these and needs a hand, ping me on it and I'll try and help.

#2 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 08 September 2014 - 06:36 AM

View PostLemur, on 08 September 2014 - 05:43 AM, said:

Fix control flow operators in Lua (ie: turtle.detect() and turtle.dig() -- yes, convoluted example)

Huh?

View PostLemur, on 08 September 2014 - 05:43 AM, said:

Compare to Block ID - No need to carry an instance of the block anymore
Add a rejection list upgrade (ie, drop all cobblestone)
Add a selection list upgrade (ie, keep only diamonds)

The current behaviour in regards to item identification isn't a "no one's gotten around to it" thing, it's a "this is intentional and won't be changing" thing.

Though with turtle.compareTo() you can already do the latter two points, so long as you reserve an inventory slot for the comparison object.

View PostLemur, on 08 September 2014 - 05:43 AM, said:

Turn around - literally turn 180

The "turtle" function table can be modified yourself. Run this for eg:

function turtle.aboutFace()
  turtle.turnLeft()
  turtle.turnLeft()
end

View PostLemur, on 08 September 2014 - 05:43 AM, said:

Allow for linking to ender chests / tesseracts / etc for instant transmission of items

Turtles can place and retrieve carried enderchests. It's possible one of the peripheral mods allow them to equip them, too.

View PostLemur, on 08 September 2014 - 05:43 AM, said:

Alias t to turtle for shorthand in the Lua shell

Easily done yourself:

local t = turtle

I wouldn't recommend doing this on a global basis with a single-character variable name, but if you really wanted to, you could lump that line into a startup script, or even modify bios.lua to do it.

Edit:

I feel I should be clearer on this - I'm sure you know you can do many of these things, the point is that "simpler" methods of doing them are omitted for that specific reason. ComputerCraft isn't aimed at advanced coders who want to get jobs done quickly so much as beginners who should be learning the building-blocks of coding.

Edited by Bomb Bloke, 08 September 2014 - 08:18 AM.


#3 Cranium

    Ninja Scripter

  • Moderators
  • 4,031 posts
  • LocationLincoln, Nebraska

Posted 08 September 2014 - 04:36 PM

View PostLemur, on 08 September 2014 - 05:43 AM, said:

  • Fix control flow operators in Lua (ie: turtle.detect() and turtle.dig() -- yes, convoluted example)
Again...what?

View PostLemur, on 08 September 2014 - 05:43 AM, said:

  • Compare to Block ID - No need to carry an instance of the block anymore
  • Add a rejection list upgrade (ie, drop all cobblestone)
  • Add a selection list upgrade (ie, keep only diamonds)

If you use OpenPeripheral's narcissistic turtles, they can return the item ids of anything in their own inventory.

View PostLemur, on 08 September 2014 - 05:43 AM, said:

  • Turn around - literally turn 180
  • Allow for linking to ender chests / tesseracts / etc for instant transmission of items
  • Allow for refueling from power cells / assorted other energy sources in game
  • Alias t to turtle for shorthand in the Lua shell
Pretty much everything else, BomBloke has a solution there.

View PostLemur, on 08 September 2014 - 05:43 AM, said:

  • Bootstrapping options from known configurations (see my post on Chef in Ask a Pro)
  • Allow for upgrades to capacity

You can already load configurations with what you've got. Make a config file yourself, and act upon it using your own code.
The capacity thing isn't going to change. If you want the turtle to have access to more inventory space, just have it place down a chest, or better yet, an enderchest. Keep in mind, that vanilla enderchests don't work, but you can install Chickenbones' EnderStorage mod, and have it work just fine.

#4 Lemur

  • Members
  • 15 posts
  • Location*.*

Posted 09 September 2014 - 06:48 AM

On control flow, in a language like Ruby you can do something like this:
puts 'message' and return true

...which is what's called flow control. In Lua, specifically the turtles, flow control operators do not behave as they should. That example there will not work on a turtle, and it should by means of experimenting in the Lua REPL.

On terms of refueling a turtle, allowing them to interface with redstone energy or whatever other black magic industrial craft and friends have made would be extremely useful.

Any reason on the storage? Mining rigs and other such things can hook up to tesseracts and other larger storage mediums.

While it may be targeted at beginners, leaving it there is a bad idea. Ruby is great for beginners as well, but the type of power you can harness from it when you want to take that next step is what makes it as a language. Lua has that potential as well, though in the context of a bolted-on scripting language it certainly makes it harder.

If some of these things were combined with rednet, turtles would have far far more power to wield. In the hands of a more advanced coder, I could see some insane things coming out beyond anything we've seen so far.

I still envision a build that'd allow turtles to operate near autonomously, refueling themselves as needed at the nearest fuel pump, pulling new configurations as the network updates.

#5 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 09 September 2014 - 12:09 PM

View PostLemur, on 09 September 2014 - 06:48 AM, said:

On control flow, in a language like Ruby you can do something like this:
puts 'message' and return true

...which is what's called flow control. In Lua, specifically the turtles, flow control operators do not behave as they should. That example there will not work on a turtle, and it should by means of experimenting in the Lua REPL.

That has less to do with the turtle's functions as it does with funkiness in how the Lua interpreter handles functions when using that sort of syntax within certain code block structures. Or ComputerCraft's Lua interpretor, anyways - that being an outdated version of LuaJ. Whatever repl.it uses has the same issue.

View PostLemur, on 09 September 2014 - 06:48 AM, said:

Any reason on the storage? Mining rigs and other such things can hook up to tesseracts and other larger storage mediums.

If you want a turtle to interface with a container, it can do that. If you want it to magically transmit items over long distances, hand it an ender chest. Heck, even if you don't care about the magic transport thing and just want more inventory space, the ender chest can be used as additional storage for the turtle itself.

I can't speak as to why larger inventories have not been added to CC directly, but my assumption is that one reason would be because there's plenty of ways to achieve the same effects already.

View PostLemur, on 09 September 2014 - 06:48 AM, said:

While it may be targeted at beginners, leaving it there is a bad idea.

If you're talking about the default function set here, if you want to revamp the APIs available to your systems you do have that option. A large percentage of them are written in Lua and can be remodeled without any need to change the closed-source Java side of things.

View PostLemur, on 09 September 2014 - 06:48 AM, said:

I still envision a build that'd allow turtles to operate near autonomously, refueling themselves as needed at the nearest fuel pump, pulling new configurations as the network updates.

This is also all possible with what we've got available.

The first CC script I wrote had a turtle which navigated my base grabbing items from storage containers, dumping them into machines, collecting the output (after going off and doing other tasks while the machines did their jobs), and periodically going off to a charge station. It interacted with a networked server to keep tabs on which containers had items which needed processing.

Later I wrote an expanded version for a new world, that worked with a collection of turtles outside which chopped wood from various tree types. Only some of the trees, being from other mods, had a habit of growing over certain blocks (eg turtles in motion) and destroying them. That prompted the system for the turtle inside to replace the turtles outside when needed, manually collecting and crafting the components from my stores and setting the newbies up with the code to get to their workplaces and to carry on with their tasks. By that stage (a few MineCraft versions later) I'd either lost access to the charge block or hadn't caught on to its new name; no worries, I just had the turtles navigate to a barrel of charcoal instead. It was much faster anyways.

The "end goal", should I ever get around to it, would be to finally have a construction turtle which clears a space near my base, then starts hauling out the resources gathered by the other turtles to build a castle. Preferably a randomised one made out of various pre-defined modules (walls, rooms, courtyards, towers, etc). It's all quite do-able.

#6 Sebra

  • Members
  • 726 posts

Posted 09 September 2014 - 05:10 PM

1. Lua is good enough for CC and in my opinion is the_best for CC.
2. More powers for turtles often means overpowered turtles.
3. I think things like power cells, tesseracts and external mod's items can be changed to allow any interaction wanted - suggest it to the corresponding mod authors.

#7 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 09 September 2014 - 06:55 PM

I'm not even sure what you think the issue is with Lua's operators. If you use them as intended, they work great. You need an assignment to evaluate an expression outside of something like a conditional (if, while, until).

local _ = turtle.detect() and turtle.dig()


#8 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 10 September 2014 - 01:52 AM

View PostLyqyd, on 09 September 2014 - 06:55 PM, said:

If you use them as intended

What's "intended" to work depends on who you ask - the "if/else as an expression" section of this page suggests the like of "turtle.detect() and turtle.dig()" should work just fine on its own. And indeed, similar constructs do - though again, it's not just ComputerCraft that chokes on it.

#9 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 10 September 2014 - 02:04 AM

By "as intended", I meant in an expression being evaluated, not as part of a standalone statement.

#10 Lemur

  • Members
  • 15 posts
  • Location*.*

Posted 10 September 2014 - 02:08 AM

View PostBomb Bloke, on 10 September 2014 - 01:52 AM, said:

View PostLyqyd, on 09 September 2014 - 06:55 PM, said:

If you use them as intended
What's "intended" to work depends on who you ask - the "if/else as an expression" section of this page suggests the like of "turtle.detect() and turtle.dig()" should work just fine on its own. And indeed, similar constructs do - though again, it's not just ComputerCraft that chokes on it.

http://lua-users.org/wiki/LuaHacks - These guys know how to have some fun with it.

Coming from Ruby though, we have a bit too much power on things. Dang handy when needed though. I'd mention a fork of CC in Ruby but that's completely impractical. I've already hacked in parts of Enumerable from Ruby in the APIs section.

#11 electrodude512

  • Members
  • 167 posts
  • LocationEastern USA

Posted 14 September 2014 - 06:50 PM

View PostBomb Bloke, on 09 September 2014 - 12:09 PM, said:

That has less to do with the turtle's functions as it does with funkiness in how the Lua interpreter handles functions when using that sort of syntax within certain code block structures. Or ComputerCraft's Lua interpretor, anyways - that being an outdated version of LuaJ. Whatever repl.it uses has the same issue.

I've been pretty annoyed by this before as well. But, for once, it's not LuaJ's fault.

$ lua
Lua 5.2.3  Copyright (C) 1994-2013 Lua.org, PUC-Rio
> print('a') and print('b')
stdin:1: unexpected symbol near 'and'
>

The standard Lua 5.2.3 interpreter doesn't even support it. Just do what Lyqyd says with the local _ = stuff

Edited by electrodude512, 14 September 2014 - 06:52 PM.


#12 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 15 September 2014 - 07:05 PM

View PostBomb Bloke, on 10 September 2014 - 01:52 AM, said:

View PostLyqyd, on 09 September 2014 - 06:55 PM, said:

If you use them as intended

What's "intended" to work depends on who you ask - the "if/else as an expression" section of this page suggests the like of "turtle.detect() and turtle.dig()" should work just fine on its own. And indeed, similar constructs do - though again, it's not just ComputerCraft that chokes on it.

For whatever reason, I had missed this link when I originally replied to this comment. If you look at what they're doing in the examples there, you'll note that they have an `=` preceding each line. They're not using the and/or/not keywords in standalone statements.

#13 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 16 September 2014 - 01:15 AM

Well spotted - I'd indeed missed that.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users