3 posts
Location
Sweden
Posted 28 December 2012 - 06:21 AM
Hi :)/>
I´m pretty new to using Lua and CC. I have learnd the basics and is trying to make stuff on my own but there is one thing I cant figure out. I want to run multipel programs at the same time.
Ex. If I have created one program that turns my lights on and then want to open a door. When I run the program for opening the door my lamps turns of.
I want the lamps to still be on when the door opens. I guess I have to make something that first reads what programs thar allredy is running and ad them to the one I´m starting. But I have no idea how to make this happen :)/>
It would be simpel if them all was one program, then I could use colors.combine(color1, color2).
Would be aswesome if some one would give me some help in the right direction :D/>
Peace
8543 posts
Posted 28 December 2012 - 06:37 AM
Well, if all you're really trying to accomplish is to have bundled outputs not change the state of other colors, you can use a fairly simple function to accomplish that. Use the first function on this page:
http://www.computercraft.info/forums2/index.php?/topic/5698-useful-snippets to change just one color. Give it the side, the color and the state. It will set just that color without affecting any other colors. For instance, you might call setBundledColor("left", colors.red , true), which would set red to true without changing anything else.
3 posts
Location
Sweden
Posted 28 December 2012 - 07:55 AM
Thanks Lyqyd! I don´t realy get it to work do. I can´t realy se where I shoud write my values and where not.
I will try to post my codes here so you can see how many horrible misstakes I have made :D/>
Peace
function setBundledColor(back, color.white, true)
if state then
if not colors.test(rs.getBundledOutput(side), color) then
rs.setBundledOutput(side, colors.combine(rs.getBundledOutput(side), color))
end
else
if colors.test(rs.getBundledOutput(side), color) then
rs.setBundledOutput(side, colors.subtract(rs.getBundledOutput(side), color))
end
end
end
818 posts
Posted 28 December 2012 - 08:08 AM
How are you actually calling the function?
BTW, eftersom jag vet att du är svensk, du kan skicka mig ett PM på ulfcraft om du vill ha hjälp ;)/>
8543 posts
Posted 28 December 2012 - 08:54 AM
Thanks Lyqyd! I don´t realy get it to work do. I can´t realy se where I shoud write my values and where not.
I will try to post my codes here so you can see how many horrible misstakes I have made :D/>/>
Peace
function setBundledColor(back, color.white, true)
if state then
if not colors.test(rs.getBundledOutput(side), color) then
rs.setBundledOutput(side, colors.combine(rs.getBundledOutput(side), color))
end
else
if colors.test(rs.getBundledOutput(side), color) then
rs.setBundledOutput(side, colors.subtract(rs.getBundledOutput(side), color))
end
end
end
Ah, I see the miscommunication. What you should actually do is put that function at the top of your code, without changing it at all, then call it in your code. Something like this:
--function declaration goes here
function setBundledColor(side, color, state)
if state then
if not colors.test(rs.getBundledOutput(side), color) then
rs.setBundledOutput(side, colors.combine(rs.getBundledOutput(side), color))
end
else
if colors.test(rs.getBundledOutput(side), color) then
rs.setBundledOutput(side, colors.subtract(rs.getBundledOutput(side), color))
end
end
end
print("Turn Lights On/Off?")
input = read()
if input:lower() == "on" then
--we use the function here.
setBundledColor("back", colors.white, true)
elseif input:lower() == "off" then
setBundledColor("back", colors.white, false)
end
3 posts
Location
Sweden
Posted 28 December 2012 - 09:48 AM
Yeah I think I got it now. Doyle was so kinde to login on the server I´m playing on and helped me in game. But still, thanks Lyqyd. I will probably use this allot of times so it realy helped med big time!
Peace