Jump to content




[1.31] Turtle Events

api turtle

  • You cannot reply to this topic
No replies to this topic

#1 Espen

    Curious Explorer

  • Members
  • 708 posts

Posted 21 March 2012 - 02:04 PM

Description
It's a small utility API which extends the native turtle functions with events.

Posted Image


Whenever you execute one of these turtle functions, it creates an event along with some additional information.
I used this primarily for my own purposes, but thought someone might get a use out of it as well.
http://en.wikipedia.org/wiki/WTFPL

Exposed Functions
forward() (or any other movement function)
  • Event-Values: "turtle", "forward", < true | false > (where "forward" changes depeding on the move function you used)
  • Return-Values: < true | false > (like the native function)
select( slot )
  • Event-Values: "turtle", "select", < true | false >, < slot >
  • Return-Values: < true | false > (like the native function)
drop() or drop( quantity )
  • Event-Values: "turtle", "drop", < true | false >, < slot >, < dropped amount >
  • Return-Values: < true | false >, < slot >, < dropped amount >
Color Legend:
String
Boolean
Number




How to use?
  • Save the API Code and make note of the filename, e.g. 'tev'
  • Load the API within the program where you want to make use of it via os.loadAPI, e.g. os.loadAPI( "tev" )
  • Then to call the API's functions just like the native turtle functions, but replace 'turtle' with 'tev', e.g.: tev.digDown()
  • To listen to turtle events, create an event loop and pull four parameters from the event, e.g.:
    local event, operation, success, slot, amount = os.pullEvent()
    (See example program below for details)


API - Code
Pastebin: http://pastebin.com/tcNZNZyK
Direct-View:
Spoiler



Example Program to try out the API
Save the API from above as "tev".
Then run the program below. Pressing "e" will exit the program.
For all other keys see the code, there are quite a few. I mapped every turtle function to a key.
Pastebin: http://pastebin.com/mKsVVPFL
Direct-View:
Spoiler






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users