Wait for event (easy event access)

Started by Kaikaku, Apr 17, 2021, 10:19 pm

Previous topic - Next topic

Kaikaku

tWaitFor & tSend

This program(s) makes using 5 events from the ComputerCraft event system easy to use.
So it's less scary to try out those events. After knowing what you can do with it,
maybe you tackle os.pullEvent() on your own, for tailor made solutions for your program ideas?

The program uses these event to wait for:
  • rednet_message / modem_message: e.g., tWait rednet 1 "my password"
  • timer: e.g., tWaitFor timer sec 5
  • alarm: e.g., tWaitfor alarm 12.00 13.00
  • turtle_inventory: e.g., tWaitFor inventory 2 >20 (implements slot numbers and item count > = <)
  • redstone: e.g., tWaitFor redstone front true (checks specific sides and turn on/off/change

You can specify multiple events to stop waiting for events. Each event is specified with exactly 3 arguments.
If you provide one additional argument, then this will be executed in shell.run().
The program returns the number of the event that triggered, so you can build quite complex stuff with it.
When you add as last argument silenced, then tWaitFor will not mess with the screen (i.e. no print no term.clear()).
If you are using the last argument to execute a program, then add silenced right in front of the program call w/o spaces etc.
e.g., tWaitFor redstone front change "silenceddance" (I know, that's a bit wonky)
You get also ingame infos, when you call it w/o any arguments: tWaitFor

The program can be called:
  • directly e.g., tWaitfor redstone any true "go fd 5"
  • from the lua interpreter e.g., shell.run("tWait alarm 12.0 13.0") turtle.forward()
  • from within your programs e.g., returnvalue=assert(loadfile("tWaitFor"))("rednet", "1", "message", "rednet", "1000", "other message", "silenced")

To make sending rednet messages easier (to trigger events), you can use tSend. However, you can only specify the channel and the message, e.g., tSend 1 "my password"

Pastebin:
tWaitFor https://pastebin.com/9vzPCd4T
tSend https://pastebin.com/h3xcC9S1

Video:
In the video I do showcase some applications and also do some code walkthroughs, to show how to use tWaitFor in a startup program.

Hi there!
I make YouTube videos about my turtle programs (incl. pastebin). Visit me if you like :)