This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Malakai030's profile picture

A pullEvent(redstone) question

Started by Malakai030, 25 August 2012 - 01:16 AM
Malakai030 #1
Posted 25 August 2012 - 03:16 AM
Hey folks, me again :D/>/>


This time I wanted to make my computer compute by an external redstone signal, like a button.

I tried:


local event, param1 = os.pullEvent(redstone)
if param1 == true then
do the rest()

I also tried things like


local sEvent = os.pullEvent()
if sEvent == redstone and param1 == true then
and so on()

I tried to used the values as strings, as booleans, but nothing really worked.

I really dont wanna use a "loop-if" for that, cause that causes lags and is not very useful for I want to use that button maybe once a day…


[ger]
Ich wette, es gibt wieder eine verblödend einfache Lösung dafür.


Malakai
Grim Reaper #2
Posted 25 August 2012 - 07:06 AM
When you pass a parameter without quotations like in:

local sSide = "left"

local event, param1 = os.pullEvent(redstone)
if param1 == sSide then
 -- Whatever...
end
You're suggesting that redstone is an identifier, not a string.

The code you first tried would work if you signal that it was a string:

local sSide = "left"

local event, param1 = os.pullEvent("redstone")

if param1 == sSide then
 -- Whatever...
end

When you pull a redstone event, the only value returned other than the event name is the side the pulse occurred on.
Malakai030 #3
Posted 25 August 2012 - 03:07 PM
Thanks for the answer, but that didnt help :/

I wrote exactly what you wrote, now the script stops in the moment I send the rs signal. Dont know the exact point, coz no lua error occures.

I gave the code an own error message (like "error: machine is off"), but it doesnt seem to get to that point.

Further suggestions? :D/>/>
BigSHinyToys #4
Posted 25 August 2012 - 03:34 PM
I have helped with a similar problem before here

Here is the code I gave then it is well commented and may help.
Spoiler

local sSide = "left" -- the side on input
local pState = false -- this shows if it was on before so er dont have to print again
while true do -- start of a loop
    local e,e1,e2,e3,e4,e5 = os.pullEvent() -- waits for somthign to happen
    if e == "redstone" and rs.getInput(sSide) and not pState then -- checks if somthing redstone has changes also checks if it was the side we selected an cheches wether it was on bofore
		    print(sSide.." Turned On") -- prints to screen
		    pState = true -- stores its previous state
    elseif e == "redstone" and not rs.getInput(sSide) and pState then  -- checks if somthing redstone has changes also checks if it was the side we selected an cheches wether it was on bofore
		    print(sSide.." Turned Off") -- prints to screen
		    pState = false -- stores its previous state
    end -- end of IF statent
end -- end of while loop