Jump to content




A Sneak Peek At Blockly Lua

lua turtle computer

33 replies to this topic

#1 blockly

  • Members
  • 41 posts
  • LocationSan Francisco, California, USA

Posted 31 October 2013 - 04:16 PM

I've been working on an extension to Blockly to make it possible to generate ComputerCraft programs by dragging and dropping blocks (similar to Scratch and App Inventor for Android). Give it a try at "http://blockly-lua.appspot.com/static/apps/code/index.html". For an idea of what can be done, here's a program I wrote to dig a spiral staircase. Feel free to play with it. (Only you will see the changes, unless you save your modified programming by clicking on the link icon in the upper right corner and share the resulting URL.)

Planned additions:
  • More of the ComputerCraft API.
  • Support for OpenPeripheral.
  • Pastebin integration.
I could use community input on what features should be highest priority. It would also be great for someone to chip in with documentation or code contributions. Feel free to PM me or post here.

Attached Thumbnails

  • Attached Image: blockly-lua-spiral.png


#2 amtra5

  • Members
  • 166 posts
  • LocationMelbourne, Australia

Posted 31 October 2013 - 04:31 PM

Very nice! Also, could you put the source on Github, as I would also like to work on this project ;)

#3 blockly

  • Members
  • 41 posts
  • LocationSan Francisco, California, USA

Posted 31 October 2013 - 04:43 PM

View Postamtra5, on 31 October 2013 - 04:31 PM, said:

Very nice! Also, could you put the source on Github, as I would also like to work on this project ;)

Already done! Here's the URL: https://github.com/e...tus/blockly-lua

#4 blockly

  • Members
  • 41 posts
  • LocationSan Francisco, California, USA

Posted 31 October 2013 - 10:16 PM

Here's a mining program created in Blockly Lua. Before running it, blocks that the player is NOT interested in should be placed in slots 12-16 of the turtle's inventory. The program digs straight down. At each step, the turtle looks around at adjacent blocks, digging any that differ from the uninteresting blocks, expanding recursively, so it follows any veins. Here's the Blockly link: "http://blockly-lua.appspot.com/static/apps/code/index.html#bv3ys8".

The code can be found in the Lua tab at the above link or at "http://pastebin.com/Ey0im3XJ".

Attached Thumbnails

  • Attached Image: blockly-dig-explore.png


#5 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 31 October 2013 - 10:26 PM

One question... in your code where you're searching for a "sensor" peripheral... why do you look for "peripheral" instead of "sensor"?

#6 amtra5

  • Members
  • 166 posts
  • LocationMelbourne, Australia

Posted 01 November 2013 - 01:23 AM

How would you add blocks? I've followed the tutorial on the wiki with no avail :(

#7 Zudo

  • Members
  • 800 posts
  • LocationUK

Posted 01 November 2013 - 02:08 AM

I thought this would be bad, but it is actually quite good! Definitely sharing with my friends, who want to learn but don't know how :P

#8 blockly

  • Members
  • 41 posts
  • LocationSan Francisco, California, USA

Posted 01 November 2013 - 12:01 PM

View Posttheoriginalbit, on 31 October 2013 - 10:26 PM, said:

One question... in your code where you're searching for a "sensor" peripheral... why do you look for "peripheral" instead of "sensor"?

Good to see you here. You know I'm a fan of yours.

I forgot that I'd left in that code. The reason for it is that I'd always interacted with a sensor by attaching it as a peripheral to a turtle and accessing it through the peripheral interface. How would you recommend that I access it?

#9 blockly

  • Members
  • 41 posts
  • LocationSan Francisco, California, USA

Posted 01 November 2013 - 12:02 PM

View Postamtra5, on 01 November 2013 - 01:23 AM, said:

How would you add blocks? I've followed the tutorial on the wiki with no avail :(

I'll start work on a Lua-specific tutorial. If you tell me what you were trying to do and where it got confusing, that would be helpful.

#10 blockly

  • Members
  • 41 posts
  • LocationSan Francisco, California, USA

Posted 01 November 2013 - 02:30 PM

I've started on a tutorial: https://github.com/e...w-to-Add-Blocks

#11 amtra5

  • Members
  • 166 posts
  • LocationMelbourne, Australia

Posted 01 November 2013 - 05:30 PM

View Postblockly, on 01 November 2013 - 12:02 PM, said:

View Postamtra5, on 01 November 2013 - 01:23 AM, said:

How would you add blocks? I've followed the tutorial on the wiki with no avail :(/>

I'll start work on a Lua-specific tutorial. If you tell me what you were trying to do and where it got confusing, that would be helpful.
I had a bit of spare time and I was going to finish the OS api for you ;)

#12 blockly

  • Members
  • 41 posts
  • LocationSan Francisco, California, USA

Posted 01 November 2013 - 07:33 PM

View Postamtra5, on 01 November 2013 - 05:30 PM, said:

I had a bit of spare time and I was going to finish the OS api for you ;)

Super! I've been cleaning up the code and working on the documentation, so you may be able to get started. Don't be shy about asking me questions.

#13 Zudo

  • Members
  • 800 posts
  • LocationUK

Posted 02 November 2013 - 12:31 AM

Error: Not Found

The requested URL /static/apps/code/index.html was not found on this server.


...

#14 amtra5

  • Members
  • 166 posts
  • LocationMelbourne, Australia

Posted 02 November 2013 - 01:44 AM

Also, you may want to somehow disable the default blockly colour blocks from being able to interact with CC logic blocks.

Edit: What would I add to template.soy so that it recognises my block?

#15 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 02 November 2013 - 02:54 AM

View Postblockly, on 01 November 2013 - 12:01 PM, said:

I forgot that I'd left in that code. The reason for it is that I'd always interacted with a sensor by attaching it as a peripheral to a turtle and accessing it through the peripheral interface. How would you recommend that I access it?
Like this

#16 blockly

  • Members
  • 41 posts
  • LocationSan Francisco, California, USA

Posted 02 November 2013 - 02:49 PM

View PostZudoHackz, on 02 November 2013 - 12:31 AM, said:

Error: Not Found The requested URL /static/apps/code/index.html was not found on this server. ...

Yikes! Thanks for letting me know. Fixed.

#17 blockly

  • Members
  • 41 posts
  • LocationSan Francisco, California, USA

Posted 02 November 2013 - 02:57 PM

View Postamtra5, on 02 November 2013 - 01:44 AM, said:

Also, you may want to somehow disable the default blockly colour blocks from being able to interact with CC logic blocks.

Great idea!

View Postamtra5, on 02 November 2013 - 01:44 AM, said:

Edit: What would I add to template.soy so that it recognises my block?

Copy one of the existing definitions between lines 94 and 116, changing the name to that of your block. Make sure you place it in the right category.

Update: I removed template.soy and generated/en.js. Instead, copy an existing block definition from between lines 106 and 128 of index.html.

The reason some blocks have VALUE children is so they come with an inner number/text block.

Then run the command at the top of the file to re-generate en.js. (I'm going to see if I can eliminate that step.)

I'll document in full later but wanted to give you a reply ASAP. I hope it's understandable. If not, ask again.

Thanks for helping out.

#18 blockly

  • Members
  • 41 posts
  • LocationSan Francisco, California, USA

Posted 03 November 2013 - 12:29 PM

I've completed (the initial version of) How to Add a Block.

#19 blockly

  • Members
  • 41 posts
  • LocationSan Francisco, California, USA

Posted 04 November 2013 - 11:21 PM

Thanks to theoriginal bit, all of the turtle functions have been added.

#20 Skydyn

  • Members
  • 4 posts

Posted 05 November 2013 - 02:30 AM

Neat. I tried making an IDE type thing sorta like this for a different language, but gave up because I didn't find it particularly useful. Typing is just easier. Do you think it'll have an impact on beginners?

Also, have you ever used ALICE?





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users