How to Use - espertus/blockly-lua GitHub Wiki

Getting started

  1. Buy and install the PC or Mac version of Minecraft. :-)

  2. Download and install ComputerCraft 1.57, which adds computers and turtles to Minecraft. Work through one of the provided tutorials, but don't worry too much about how to create Lua programs.

  3. Get familiar with Blockly by playing with its Puzzle or Maze apps.

  4. Visit the Blockly Lua application, and create this simple program with blocks from the "Text" category: Blockly program to print "I am a turtle."

  5. Click "Lua". You should see this Lua code: print('I am a turtle.')

  6. Click on the PASTEBIN button on the upper-right.

  7. You should see this window:
    pastebin window
    Change the name and expiration date to whatever you like, then click on "Save program to Pastebin". This will store your program on the Pastebin website. (If you're already a Pastebin member, you may prefer to copy and paste it using your own account.) After a short delay, you should see the URL for your program, as in this picture: pastebin window with result
    You can use the URL to view or share your program, but what's most important is the part after "http://pastebin.com/". That's your program's ID ("tMmuyKmP" in this example).

  8. Find a file named ComputerCraft.cfg on your computer, and find a line B:enableAPI_http=false. Replace false with true, and save the file. This will enable you to use pastebin in the following step. You only need to do this once (unless you reinstall ComputerCraft).

  9. Create a mining turtle in Minecraft (which you should have learned to do in step 2). Right-click on it and enter get pastebin XXX hello, but replace XXX with your program's ID from the end of step 7. This should fetch the program from the Pastebin website, put it onto the turtle, and name it "hello".

  10. Type "hello" (and press enter/return) into the turtle in Minecraft. It should print "I am a turtle."

Troubleshooting

[To be added.]

You can ask for help at the Blockly Lua thread at the ComputerCraft forum.

Programming tips

Saving programs

You can save your Blockly programs for sharing or later modification by clicking on the chain button on the upper right. You will be provided a URL you can use to revisit your program or share it with with others.

Reading existing programs

Read through existing programs, such as spiral staircase and dig. Feel free to modify them. Only you will see the changes (unless you save them and share the URL).

Statements and expressions

One important thing to know is that blocks can either represent expressions or statements. Expression blocks (such as numbers and addition) have a plug on the left side for providing the value, while statement blocks (such as print statements) do not produce a value. Note that statement blocks generally have a notch on top and a bump on bottom to connect to other statements; expression blocks never do.

print statement with add statement plugged into it

Many of the [Turtle API](http://computercraft.info/wiki/Turtle_(API\)) functions, such as Turtle.forward return a boolean value indicating success or failure, which is frequently ignored. If you don't want to use the return value, you can convert the expression to a statement through the context menu, which can be reached by right-clicking on the block. Specifically, the bottom-most option on the expression version (left) is "Remove Output" (not shown), while the statement version (right) has the option "Add Output" (shown).

Expression and statement versions of "move forward"

⚠️ **GitHub.com Fallback** ⚠️