49 posts
Posted 20 April 2013 - 08:33 AM
Hello all!
I'm trying to make a on/off selector using
this API (to make the buttons), and a bundled cable, that go to my 3 ractors (each one using the white, orange and the yellow cable, respectively).
I code this, but, every time that i press "r", the reactors turn on and off, randomly!!!
UPDATED!! But not working, same problem…
Spoiler
r1 = false
r2 = false
r3 = false
lado = "front" -- lado = side ;P
function Refresh()
if r1 == true then
cc1 = rs.getBundledOutput(lado) -- Finds what colors are currently on
rs.setBundledOutput(lado, cc1 + 1) -- sets the currently on colors and the new color on
else
cc2 = rs.getBundledOutput(lado) -- Finds what colors are currently on
rs.setBundledOutput(lado, cc2 - 1) -- sets the currently on colors and the new color on
end
if r2 == true then
cc3 = rs.getBundledOutput(lado) -- Finds what colors are currently on
rs.setBundledOutput(lado, cc3 + 2) -- sets the currently on colors and the new color on
else
cc4 = rs.getBundledOutput(lado) -- Finds what colors are currently on
rs.setBundledOutput(lado, cc4 - 2) -- sets the currently on colors and the new color on
end
if r3 == true then
cc5 = rs.getBundledOutput(lado) -- Finds what colors are currently on
rs.setBundledOutput(lado, cc5 + 16) -- sets the currently on colors and the new color on
else
cc6 = rs.getBundledOutput(lado) -- Finds what colors are currently on
rs.setBundledOutput(lado, cc6 - 16) -- sets the currently on colors and the new color on
end
end
function Selection()
print("Please choose the reactors to turn on (1/2/3/all/(r)efresh:")
btnB = io.read()
if btnB == "r" then
Refresh()
end
if btnB == "1" then
print("Reator 1")
if r1 == false then
r1 = true
else
r1 = false
end
end
if btnB == "2" then
if r2 == false then
r2 = true
else
r2 = false
end
end
if btnB == "3" then
if r3 == false then
r3 = true
else
r3 = false
end
end
if btnB == "all" then
if r1 == false then
r1 = true
else
r1 = false
end
if r2 == false then
r2 = true
else
r2 = false
end
if r3 == false then
r3 = true
else
r3 = false
end
end
end
function Initialize()
term.clear()
term.setBackgroundColor(colors.white)
term.setTextColor(colors.black)
term.setCursorPos(1,1)
Selection()
sleep(0.5)
term.setCursorPos(1, 1)
Initialize()
end
Initialize()
I believe that my error is in the "Refresh" function…
Someone can help me?
Sorry for the english …
1 posts
Posted 20 April 2013 - 06:21 PM
Quick question which version of the
Mouse and graphic api i see a beta link and a major update upon checking your linkI would recommend if possible, abandon the api and write your code in the default computer-craft setupThen add it back enclosed in the button function(is that what its called?)also make sure you are using an advanced computer AND advanced monitoryou may want to try to set the colors as numbers (defined here)or if all else fails.. you could use regular redstone wire and define the on/off for all three sides in one section of code. taking up more room and being lazy but mehit would also help if you translated your comments in the code you wrote or at least tell me the language they are in–also be happy i made this account to answer your question
Edited on 20 April 2013 - 04:25 PM
49 posts
Posted 21 April 2013 - 12:15 PM
Quick question which version of the
Mouse and graphic api i see a beta link and a major update upon checking your linkI would recommend if possible, abandon the api and write your code in the default computer-craft setupThen add it back enclosed in the button function(is that what its called?)also make sure you are using an advanced computer AND advanced monitoryou may want to try to set the colors as numbers (defined here)or if all else fails.. you could use regular redstone wire and define the on/off for all three sides in one section of code. taking up more room and being lazy but mehit would also help if you translated your comments in the code you wrote or at least tell me the language they are in–also be happy i made this account to answer your question
Thanks to response my topic, i will try to replace the colors by the numbers, maybe can help, unfortunately i can't replace the bundled cable by redstone, and, the comments are in portuguese! AND i will try without the API…
645 posts
Location
'Merica
Posted 21 April 2013 - 08:01 PM
Weird… Be nice if the comments in the code were all in English, what language is that? Anyways, why do you have "term.setBackgroundColor() and "term.setTextColor()" in a comment? If your going to use them, they shouldn't be in a comment. And could you translate it ALL to English, I'm having trouble reading what variables go were… since most variables mean something, or a abbreviated so having them in a different language makes it hard to tell what the hell is going on.
49 posts
Posted 22 April 2013 - 11:39 AM
Weird… Be nice if the comments in the code were all in English, what language is that? Anyways, why do you have "term.setBackgroundColor() and "term.setTextColor()" in a comment? If your going to use them, they shouldn't be in a comment. And could you translate it ALL to English, I'm having trouble reading what variables go were… since most variables mean something, or a abbreviated so having them in a different language makes it hard to tell what the hell is going on.
I updated and translate my code, so, please, read it again in the first post!
7508 posts
Location
Australia
Posted 22 April 2013 - 11:54 AM
Ok so the reason that there is the problem every time you refresh is because you keep adding or subtracting the value from the cable, this is not how they work, and again I say to people this is where colours.combine and colours.subtract come into use instead of just simple addition and subtraction.
Off-topic about people wanting you to translate your code
Spoiler
I would like to point out, that no matter the variables and functions language it should be easy to read and understand… especially since you can just look around the code to see how it is used and its values, of course this is easier if the names make sense, but don't worry about translating everything in your code, it isn't required…
49 posts
Posted 22 April 2013 - 12:20 PM
Ok so the reason that there is the problem every time you refresh is because you keep adding or subtracting the value from the cable, this is not how they work, and again I say to people this is where colours.combine and colours.subtract come into use instead of just simple addition and subtraction.
Off-topic about people wanting you to translate your code
Spoiler
I would like to point out, that no matter the variables and functions language it should be easy to read and understand… especially since you can just look around the code to see how it is used and its values, of course this is easier if the names make sense, but don't worry about translating everything in your code, it isn't required…
Thanks to response me! I replaced
Spoiler
if r1 == true then
cc1 = rs.getBundledOutput(lado) -- Finds what colors are currently on
rs.setBundledOutput(lado, cc1 + 1) -- sets the currently on colors and the new color on
else
cc2 = rs.getBundledOutput(lado) -- Finds what colors are currently on
rs.setBundledOutput(lado, cc2 - 1) -- sets the currently on colors and the new color on
end
to
Spoiler
if r1 == true then
cc1 = rs.getBundledOutput(lado) -- Finds what colors are currently on
rs.setBundledOutput(lado, colors.combine(cc1, 1)) -- sets the currently on colors and the new color on
else
cc2 = rs.getBundledOutput(lado) -- Finds what colors are currently on
rs.setBundledOutput(lado, colors.subtract(cc2, 1)) -- sets the currently on colors and the new color on
end
but, still not working… Now when i select all, only one turn on :/
7508 posts
Location
Australia
Posted 22 April 2013 - 12:23 PM
Try
this … I modified the code a little. If you want to know why I did anything or how anything works just ask
49 posts
Posted 22 April 2013 - 12:50 PM
Try
this … I modified the code a little. If you want to know why I did anything or how anything works just ask
Thanks! Worked very well =)
And… "r2 = not r2", it inverts r2?
7508 posts
Location
Australia
Posted 22 April 2013 - 01:02 PM
And… "r2 = not r2", it inverts r2?
Exactly right. It turns that if elseif that you had into one line. the 'not' operator inverts the result, so false is true and true is false.
49 posts
Posted 22 April 2013 - 01:45 PM
And… "r2 = not r2", it inverts r2?
Exactly right. It turns that if elseif that you had into one line. the 'not' operator inverts the result, so false is true and true is false.
Ok thanks!