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

Programing Help Redpower2

Started by Mikev619619, 28 May 2012 - 07:56 PM
Mikev619619 #1
Posted 28 May 2012 - 09:56 PM
Hello i am new to this and i was trying to write a program for my redpower frame machine that opens a wall and pulls out my machine then close it back up when done into just a regular wall.
i have figured out the codes to make it work but there all seperate programs and i cant figure out how to make them into one. Thanks Mike

open and close program

for x = 1,1 do
rs.setBundledOutput("back", colors.white)
sleep(0.175)
rs.setBundledOUtput("back",0)
sleep(0.175)
end

Pull Forward program

for x = 1,5 do
rs.setBundledOutput("back", colors.black)
sleep(0.175)
rs.setBundledOutput("back", 0)
sleep(0.175)
end

Pull Back program

for x = 1,5 do
rs.setBundledOutput("back", colors.purple)
sleep(0.175)
rs.setBundledOutput("back", 0)
sleep(0.175)
end
Luanub #2
Posted 28 May 2012 - 10:30 PM
Make them functions

example

function open()
--insert open code here
end

function forward()
-- insert forward code here
end

function back()
-- insert back code here
end

--to call them do
open()
forward()
back()

Then just put together a small menu that allows you to choose which one you want to do. You could even setup rednet triggers so you could operate it remotely.
Edited on 28 May 2012 - 08:31 PM
MysticT #3
Posted 28 May 2012 - 10:41 PM
And since they all do almost the same, you could make a function like:

local funcion pulse(sSide, nColors)
  rs.setBundledOutput(sSide, nColors)
  sleep(0.175)
  rs.setBundledOutput(sSide, 0)
  sleep(0.175)
end
And then use it in the other functions like:

local function forward()
  for x = 1,5 do
    pulse("back", colors.black)
  end
end
Mikev619619 #4
Posted 28 May 2012 - 11:32 PM
Thanks i am not sure if i did what you said righ because its not working i am getting this "bios 206 string michael 15 end expected (to close fuction at line 9)"



Print("Hidden Wall Open and closer")
print("(1)Open")
print("(2)Close")
print("(3)Forward")
print("(4)Backward")
input ="open"
if open then open()
end
function open()
for x = 1,1 do
rs.setBundledOutput("back", colors.white)
sleep(0.175)
rs.setBundledOutput("back", 0)
sleep(0.175)
end
function forward()
for x = 1,5 do
rs.setBundledOutput("back", colors.black)
sleep(0.175)
rs.setBundledOutput("back", 0)
sleep(0.175)
end
function forward()
for x = 1,5 do
rs.setBundledOutput("back", colors.black)
sleep(0.175)
rs.setBundledOutput("back", 0)
sleep(0.175)
end
Lyqyd #5
Posted 28 May 2012 - 11:41 PM
Try this.


function open()
    for x = 1,1 do
        rs.setBundledOutput("back", colors.white)
        sleep(0.175)
        rs.setBundledOutput("back", 0)
        sleep(0.175)
    end
end

function forward()
    for x = 1,5 do
        rs.setBundledOutput("back", colors.black)
        sleep(0.175)
        rs.setBundledOutput("back", 0)
        sleep(0.175)
    end
end

function back()
    for x = 1,5 do
        rs.setBundledOutput("back", colors.purple)
        sleep(0.175)
        rs.setBundledOutput("back", 0)
        sleep(0.175)
    end
end

print("Hidden Wall Open and closer")
print("(1)Open")
print("(2)Close")
print("(3)Forward")
print("(4)Backward")
print("(5)Exit")
while true do
    input = read()
    if input == "1" or input == "2" then
        open()
    elseif input == "3" then
        forward()
    elseif input == "4" then
        back()
    elseif input == "5" then
        return
    end
end
MysticT #6
Posted 28 May 2012 - 11:44 PM
You are missing the ends to close the functions:

function open()
  for x = 1,1 do
    rs.setBundledOutput("back", colors.white)
    sleep(0.175)
    rs.setBundledOutput("back", 0)
    sleep(0.175)
  end
end

function forward()
  for x = 1,5 do
    rs.setBundledOutput("back", colors.black)
    sleep(0.175)
    rs.setBundledOutput("back", 0)
    sleep(0.175)
  end
end
And you defined the forward function twice instead of back.
Mikev619619 #7
Posted 28 May 2012 - 11:59 PM
Thanks Lygyd! and everyone else that help me it works, i think i am starting to understand this more. :)/>/>