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

I need help with Redpower

Started by Darky_Alan, 20 July 2012 - 08:56 AM
Darky_Alan #1
Posted 20 July 2012 - 10:56 AM
So, as anyone keeping an eye on general that saw my thread knows, I'm pretty new to this and still feeling my way around.

I'm working on a project and before I tie everything together I'm learning how to work all the diferent segments of what I want my program to do.

For now I'm working with Redpower.

I'm testing out making the computer make a specific color output OR reading a specific input, and doing something if it read that particular input.

Right now I'm trying to make it read inputs and I can't get my program to work at all!
What am I doing wrong?
function powertest()
	print("Listening for red input...")
	c = rs.getBundledInput( "back" )
	red = colors.test( c, colors.red )
if red == true then
	print("Receiving red.")
end
end
powertest() 

I send the output by turning on a switch, but the computer's not reading the input.
BigSHinyToys #2
Posted 20 July 2012 - 11:20 AM
Ok so your code works fine. But there is no loop so the code is not waiting for a redstone event. try running your code while red is active.

or this might help


function powertest()
    while true do -- start of loop
	    local event,pram,pram2,pram3 = os.pullEvent("redstone") -- program stops here and waits for a redstone event to happen
	    print("Listening for red input...")
	    c = rs.getBundledInput( "back" )
	    red = colors.test( c, colors.red )
	    if red == true then
		    print("Receiving red.")
	    elseif red == false then
		    print("No red")
	    end
	    return -- ends the function and returns to main loop
    end -- end of loop
end
while true do --  this makes it re run the test MAIN LOOP
    powertest()
end -- end of loop
Noodle #3
Posted 20 July 2012 - 11:24 AM
What specific error? Is it giving one?
Try this:
if colors.test( rs.getBundledInput( "back" ), colors.red ) then
EDIT: Above has a spam print No Red and event is un-necessary
BigSHinyToys #4
Posted 20 July 2012 - 11:30 AM
What specific error? Is it giving one?
Try this:
if colors.test( rs.getBundledInput( "back" ), colors.red ) then
EDIT: Above has a spam print No Red and event is un-necessary
what do you mean by that. It only prints the status of red when redstone changes. not really spaming.
Darky_Alan #5
Posted 20 July 2012 - 11:34 AM
SpoilerOk so your code works fine. But there is no loop so the code is not waiting for a redstone event. try running your code while red is active.

or this might help


function powertest()
	while true do -- start of loop
		local event,pram,pram2,pram3 = os.pullEvent("redstone") -- program stops here and waits for a redstone event to happen
		print("Listening for red input...")
		c = rs.getBundledInput( "back" )
		red = colors.test( c, colors.red )
		if red == true then
			print("Receiving red.")
		elseif red == false then
			print("No red")
		end
		return -- ends the function and returns to main loop
	end -- end of loop
end
while true do --  this makes it re run the test MAIN LOOP
	powertest()
end -- end of loop

Mind if I ask you to break down your code? I'm still not well aquainted with loops. By that, I mean explain it bit by bit?

What specific error? Is it giving one?
Try this:
if colors.test( rs.getBundledInput( "back" ), colors.red ) then
EDIT: Above has a spam print No Red and event is un-necessary

It wasn't giving me any error message, just wasn't doing anything if I flipped the switch.
BigSHinyToys #6
Posted 20 July 2012 - 11:46 AM
while true do loops are quite simple here are some examples

simplest loop

while true do -- start of loop
    sleep(3)
    print("spam spam")
end -- end of loop
print("you will never see this")
running the above will loop indefinite printing "spam spam" every 3 seconds you will never see the other print as it is out side the loop

more advanced

local bRunning = true
local counter = 0
while bRunning do -- start of loop
    counter = counter+1
    print(counter)
    if counter == 4 then
	    break -- leaves and ends the loop
    end
    sleep(1)
end-- end of loop
print("five loops")
this demonstrates how you can exit a loop and how you can use a variable as the true section

next

local bRunning = true
local counter = 0
while bRunning do -- start of loop
    counter = counter+1
    print(counter)
    if counter == 4 then
	    bRunning = false
    end
    sleep(1)
end-- end of loop
print("five loops")
works same as above but we end the loop by changing a var instead.

ALL examples are untested to report any bugs.
Darky_Alan #7
Posted 20 July 2012 - 11:55 AM
Spoilerwhile true do loops are quite simple here are some examples

simplest loop

while true do -- start of loop
	sleep(3)
	print("spam spam")
end -- end of loop
print("you will never see this")
running the above will loop indefinite printing "spam spam" every 3 seconds you will never see the other print as it is out side the loop

more advanced

local bRunning = true
local counter = 0
while bRunning do -- start of loop
	counter = counter+1
	print(counter)
	if counter == 4 then
		break -- leaves and ends the loop
	end
	sleep(1)
end-- end of loop
print("five loops")
this demonstrates how you can exit a loop and how you can use a variable as the true section

next

local bRunning = true
local counter = 0
while bRunning do -- start of loop
	counter = counter+1
	print(counter)
	if counter == 4 then
		bRunning = false
	end
	sleep(1)
end-- end of loop
print("five loops")
works same as above but we end the loop by changing a var instead.

ALL examples are untested to report any bugs.

Thanks man~! grats on the new title. +1 to you.