I wanted to make make a function whenever I typed in a specific command. Like for say I wanted to do this without typing this in all over again.
rs.setBundledOutput("back", 1)
sleep(1)
rs.setBundledOutput("back", 0)
sleep(1)
I wanted to label it pulse or something of that sort how would I do that?
Creating a New Computercraft Function.
Started by SNWLeader, Jan 26 2013 09:28 AM
8 replies to this topic
#1
Posted 26 January 2013 - 09:28 AM
#2
Posted 26 January 2013 - 09:33 AM
Nevermind..
Got an error..
Please Delete this!
Got an error..
Please Delete this!
#3
Posted 26 January 2013 - 09:37 AM
I meant to write this:
function rs(side,t1,t2)
rs.setBundledOutput(side, t1)
sleep(1)
rs.setBundledOutput(side, t2)
sleep(1)
end
--Then Call it Like This Or Something
rs("back",1,0)
#4
Posted 26 January 2013 - 10:41 AM
in your case this would be sufficient though..
click here for more info about functions
function pulse()
rs.setBundledOutput("back",1)
sleep(1)
rs.setBundledOutput("back",0)
sleep(1)
end
--run it by simply putting pulse() in the code
click here for more info about functions
#5
Posted 26 January 2013 - 10:52 AM
function pulseCol(col, side, lengthOn, lengthOff, nTimes)
if type(col) ~= "number" then error("Bad argument #1, number expected - got " .. type(col))
elseif type(side) ~= "string" then error("Bad argument #2, string expected - got " .. type(side))
elseif type(lengthOn) ~= "number" then error("Bad argument #3, number expected - got " .. type(lengthOn))
elseif type(lengthOff) ~= "number" then error("Bad argument #4, number expected - got " .. type(lengthOff))
elseif type(nTimes) ~= "number" then error("Bad argument #5, number expected - got " .. type(nTimes)) end
nTimes = nTimes or 1
lengthOn = lengthOn or 1
lengthOff = lengthOff or 1
col = col or colours.white
for i = 1, #nTimes do
c = rs.getBundledInput() + col
rs.setBundledOutput(side, c)
sleep(lengthOn)
rs.setBundledOutput(side, c - col)
sleep(lengthOff)
end
end
Something like that... not sure if the redstone part is correct though, forgot how to do it as I hardly ever do..
#6
Posted 27 January 2013 - 05:38 AM
Why do you make it so complicated for someone who doesn't know how a function works xD
#7
Posted 27 January 2013 - 06:27 AM
remiX, on 26 January 2013 - 10:52 AM, said:
elseif type(lengthOn) ~= "string" then error("Bad argument #3, number expected - got " .. type(lengthOn))
elseif type(lengthOff) ~= "string" then error("Bad argument #4, number expected - got " .. type(lengthOff))
elseif type(nTimes) ~= "string" then error("Bad argument #5, number expected - got " .. type(nTimes))
I would say avoid type checking where possible - it violates the principle of duck typing.
#8
Posted 27 January 2013 - 07:16 AM
Eric, on 27 January 2013 - 06:27 AM, said:
remiX, on 26 January 2013 - 10:52 AM, said:
elseif type(lengthOn) ~= "string" then error("Bad argument #3, number expected - got " .. type(lengthOn))
elseif type(lengthOff) ~= "string" then error("Bad argument #4, number expected - got " .. type(lengthOff))
elseif type(nTimes) ~= "string" then error("Bad argument #5, number expected - got " .. type(nTimes))
I would say avoid type checking where possible - it violates the principle of duck typing.
Super fail... I copied and pasted and forgot to change "string" to "number" xD
Will fix now...
#9
Posted 27 January 2013 - 01:40 PM
Easy its just:
P.S. Put the function at the top of your code and if this help click my
please
function Pulse()
rs.setBundledOutput("back", 1)
sleep(1)
rs.setBundledOutput("back", 0)
sleep(1)
end
and when you want the program you put this in just type Pulse() on a new line.P.S. Put the function at the top of your code and if this help click my
please
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











