25 posts
Posted 08 June 2012 - 03:00 PM
Posted Today, 03:31 PM
I am using a redsotne cable that is connected to my computer or a bundled cable.
So my script goes as follows
if rs.testBundledInput("left",colours.black) then
print("Induction furnace is running")
end
So it works fine and all but,
as i am using the Eu detector cable at the bottom of my Induction furnace so that when Eu is
flowing through it emits a signal to my computer.
however to keep the furnace running at 100% heat it every now and then requires a burst of Eu.
And i dont want my Computer to display "Induction furnace is on" everytime it just gets redsonte for 1
second.
I think i have a selution to my problem but dont know how to script it so what better place to ask for help than here.
I was thinking of maing it if the computer receives a signal for 3 second or more it should
print("Inductionfurnace is running")
oherwise it should desplay nothing.
Any script that might be used for this?
please help
Sasuke
1604 posts
Posted 08 June 2012 - 05:58 PM
You could wait for a "redstone" to detect changes, and a use timer to make it print only if it's on for some time:
local sSide = "left" -- side to check input
local nColor = colors.black -- the color to check
local nTime = 3 -- the time to wait before changing the text
local lastInput = rs.testBundledInput(sSide, nColor)
local timer
while true do
local evt, arg = os.pullEvent()
if evt == "redstone" then
local in = rs.testBundledInput(sSide, nColor)
if in ~= lastInput then
if in then
timer = os.startTimer(nTime)
elseif timer ~= nil then
timer = nil
print("Furnace is Off")
end
lastInput = in
end
elseif evt == "timer" then
if arg == timer then
print("Furnace is On")
end
end
end
It's not tested, but it should wait for redstone changes, and if the furnace is on (gets input from the specified side and color) it waits to see if the pulse is of the the specified duration and it prints the message.
25 posts
Posted 08 June 2012 - 06:18 PM
ok i will test it!
I just have one question….
what does evt and arg stand for, and whats the reasone to uese ~= instead of just using ==
Thanx for the help
25 posts
Posted 08 June 2012 - 06:23 PM
Are they jsut variables u made
1604 posts
Posted 08 June 2012 - 06:24 PM
"evt" and "arg" are just variable names, I used them to store the values returned by os.pullEvent() wich are the event type and an argument. And ~= is the opposite of ==, it checks if two things are not equal, so:
if a ~= b then
means, if a is not equal to b then…
It's the same as using:
if not (a == :)/>/> then
25 posts
Posted 08 June 2012 - 06:47 PM
it gives me an error at line 11
i rechecked it and was coppied correctly
bios:206: [string "test"]:11: '<name>' expected
this is my code there
local in = rs.testBundledInput("left",black)
i pressumed if u said sSide(selectSide–>leftSide)
nColor(nameColor–>blackColour)
i dont know if that is right here is a link to a photo i added of my program on photobucket
http://s1172.photobucket.com/albums/r576/Uch1ha_Sasuke/?action=view¤t=IMG_0558.jpgdunno of thats right
25 posts
Posted 08 June 2012 - 06:48 PM
ooh ok i understand ~= basically its a shorter easier script
1604 posts
Posted 08 June 2012 - 06:51 PM
Derp, the problem is that "in" is a lua keyword, so it can't be used as a variable name.
Use this:
local sSide = "left" -- side to check input
local nColor = colors.black -- the color to check
local nTime = 3 -- the time to wait before changing the text
local lastInput = rs.testBundledInput(sSide, nColor)
local timer
while true do
local evt, arg = os.pullEvent()
if evt == "redstone" then
local input = rs.testBundledInput(sSide, nColor)
if input ~= lastInput then
if input then
timer = os.startTimer(nTime)
elseif timer ~= nil then
timer = nil
print("Furnace is Off")
end
lastInput = input
end
elseif evt == "timer" then
if arg == timer then
print("Furnace is On")
end
end
end
Don't change anything, just the values at the top (and only the values, not the variable names). If the side you use is left and the color is black, just copy the code exactly like I wrote it.
25 posts
Posted 12 June 2012 - 11:18 AM
It works but it has something i dont like
So i want it to rerun every 5 seconds cause im gonna do this script for 5 machines then it tells me which ones is running.
so i have put in at the bottom shell.run(programname)
it works but then it does not print my machine is on. only works when redstone is turned off again and then turned on otherwise does nothin
i want it to se every 5 seconds which machines are on an which are not
so if the signal stays on it should keep the printing Furnace is runing
1604 posts
Posted 12 June 2012 - 07:22 PM
It would require some changes to the code to make it work with multiple inputs. When I have some time I'll try to do it.
Also, you should avoid using shell.run when you can, cause it can cause problems if you don't know what you'r doing (like running the same program, it causes an error after some time).
25 posts
Posted 16 June 2012 - 01:31 AM
oke thanx i just dont knwo how to make it constantly change a value and not just print the value
like
On
Off
On
i want it to either say
———–
ON
———–
or
———–
OF
———–
And all i can think of is using shell.run()