Example 1: You have a redstone wire right side of a computer/turtle, but not currently activated. But imagine you only want to do something when the redstone wire is activated. That would require an if statement, right? Wrong! See below example code:
while true do
rshelp.pullEvent(false, true, "right", "rs", true)
print("Redstone on the right side activated!")
end
First, let me explain the arguments that I passed to the function.
false - this is an optional argument which specifies if the pullEvent can be terminated. Because I've specified false (the default) then it
CAN be terminated.
true - this is an optional argument which specifies if it will exclusively return redstone events. As I've specified true, it will only wait for redstone events.
"right" - the side to listen on.
"rs" - the type of signal to listen to. Can be "rs" or any colour.
true - the type of value to listen to. Can be true or false. It is possible to only do something when a signal is turned OFF by specifying false.
The above code loops, and prints "Redstone on the right side activated!" whenever the redstone on the right side is, well, activated.
Example 2: You have a bundled cable, and wish to listen only for a yellow signal on the front side. However, you also want to listen for "q" being pressed, but do not wish to allow termination using Ctrl+T. The use of this API simplifies the code needed. See below example code:
local event, param1
while true do
event, param1 = rshelp.pullEvent(true, false, "front", "yellow", true)
if event == "char" and param1 == "q" then
break
elseif event == "redstone" then
print("Yellow wire activated!")
end
end