Bundled cable IO question
Started by L00K3, Feb 12 2014 04:03 AM
9 replies to this topic
#1
Posted 12 February 2014 - 04:03 AM
I was wondering, i am making an api to read/write to a solid state drive using two bundle cables, output on the left and input on the right. I am having the problem where the 'io.write' writes to input and is not lining input up with the correct line.
This is the code (I am using an API to assist with controlling the wires):
-- output API
-- this isn't my work BTW
local side = "back"
function alloff()
rs.setBundledOutput(side, 0)
end
function set(color, state)
color = colors[color] or colours[color]
if not color then
error("Invalid colour", 2)
end
local func = (state and colors.combine or colors.subtract)
rs.setBundledOutput(side, func(rs.getBundledOutput(side), color))
end
function get(color)
color = colors[color] or colours[color]
return rs.testBundledInput(side, color)
end
function toggle(color)
cstate = get(color)
if cstate == false then
set(color, true)
end
if cstate == true then
set(color, false)
end
end
--[[
function setadv(sided, color, state)
color = colors[color] or colours[color]
if not color then
error("Invalid colour", 2)
end
local func = (state and colors.combine or colors.subtract)
rs.setBundledOutput(sided, func(rs.getBundledOutput(sided), color))
end
--]]
function setside(s)
side = s
end
[color=#b22222]-- The control API[/color]
[color=#b22222]-- This is my program to control the SDD[/color]
[color=#b22222]api = output[/color]
[color=#b22222]-- output information[/color]
[color=#b22222]io.write("Please Input Signal [1-9]: ")[/color]
[color=#b22222] term.setCursorPos(27,2)[/color]
[color=#b22222] Input = io.read()[/color]
[color=#b22222] if Input == 1 then[/color]
[color=#b22222] output.setside("left")[/color]
[color=#b22222] output.set("magenta", true)[/color]
[color=#b22222] redstone.output("top", true)[/color]
[color=#b22222] redstone.output("top", false)[/color]
[color=#b22222] output.set("magenta", false)[/color]
[color=#b22222] elseif[/color]
[color=#b22222] print ("This has not been implemented yet") then[/color]
[color=#b22222]end[/color]
And the output is:
> Binary output
Please Input Signal [1-9]:1
This has not been implemented yet
> _
The 1 is my Input and should lead to output on magenta!
This is the code (I am using an API to assist with controlling the wires):
-- output API
-- this isn't my work BTW
local side = "back"
function alloff()
rs.setBundledOutput(side, 0)
end
function set(color, state)
color = colors[color] or colours[color]
if not color then
error("Invalid colour", 2)
end
local func = (state and colors.combine or colors.subtract)
rs.setBundledOutput(side, func(rs.getBundledOutput(side), color))
end
function get(color)
color = colors[color] or colours[color]
return rs.testBundledInput(side, color)
end
function toggle(color)
cstate = get(color)
if cstate == false then
set(color, true)
end
if cstate == true then
set(color, false)
end
end
--[[
function setadv(sided, color, state)
color = colors[color] or colours[color]
if not color then
error("Invalid colour", 2)
end
local func = (state and colors.combine or colors.subtract)
rs.setBundledOutput(sided, func(rs.getBundledOutput(sided), color))
end
--]]
function setside(s)
side = s
end
[color=#b22222]-- The control API[/color]
[color=#b22222]-- This is my program to control the SDD[/color]
[color=#b22222]api = output[/color]
[color=#b22222]-- output information[/color]
[color=#b22222]io.write("Please Input Signal [1-9]: ")[/color]
[color=#b22222] term.setCursorPos(27,2)[/color]
[color=#b22222] Input = io.read()[/color]
[color=#b22222] if Input == 1 then[/color]
[color=#b22222] output.setside("left")[/color]
[color=#b22222] output.set("magenta", true)[/color]
[color=#b22222] redstone.output("top", true)[/color]
[color=#b22222] redstone.output("top", false)[/color]
[color=#b22222] output.set("magenta", false)[/color]
[color=#b22222] elseif[/color]
[color=#b22222] print ("This has not been implemented yet") then[/color]
[color=#b22222]end[/color]
And the output is:
> Binary output
Please Input Signal [1-9]:1
This has not been implemented yet
> _
The 1 is my Input and should lead to output on magenta!
#2
Posted 12 February 2014 - 11:10 AM
When asking for help in Ask a pro, please use code tags and post your error message!
Im gonna take a quick guess and say you mixed up io.read and io.write with the global read function and term.write respectively. The io functions are for handling files stored on your computer, mainly reading and writing these files. Based on your code, i believe what you want instead is just read() which accepts user input, and write, which writes text to the screen.
Also, you're loading the API wrong.
Im gonna take a quick guess and say you mixed up io.read and io.write with the global read function and term.write respectively. The io functions are for handling files stored on your computer, mainly reading and writing these files. Based on your code, i believe what you want instead is just read() which accepts user input, and write, which writes text to the screen.
Also, you're loading the API wrong.
os.loadAPI("/API file path")
#3
Posted 21 February 2014 - 02:02 AM
Neither was the case, this is the entire code for the main read/write system, but you did help
me correct the load api function, as that would have just lead to miss read/writes in the system.
os.loadAPI("output")
-- output information
io.write("Please Input Signal [1-9]: ")
term.setCursorPos(27,2)
Input = io.read()
if Input == 1 then
output.setside("left")
output.set("magenta", true)
output.set("white", true)
output.set("white", false)
output.set("magenta", false)
elseif
print ("This has not been implemented yet") then
end
me correct the load api function, as that would have just lead to miss read/writes in the system.
os.loadAPI("output")
-- output information
io.write("Please Input Signal [1-9]: ")
term.setCursorPos(27,2)
Input = io.read()
if Input == 1 then
output.setside("left")
output.set("magenta", true)
output.set("white", true)
output.set("white", false)
output.set("magenta", false)
elseif
print ("This has not been implemented yet") then
end
#4
Posted 24 February 2014 - 10:56 PM
Anyone, please help. As far as I've looked the coding is right, and while i'm at it i have a menu program converted from a basic program in my programming class and it randomly picks up an error on one of the term.write lines.
#5
Posted 24 February 2014 - 11:38 PM
CometWolf, on 12 February 2014 - 11:10 AM, said:
The io functions are for handling files stored on your computer, mainly reading and writing these files.
L00K3, on 24 February 2014 - 10:56 PM, said:
Anyone, please help. As far as I've looked the coding is right, and while i'm at it i have a menu program converted from a basic program in my programming class and it randomly picks up an error on one of the term.write lines.
well considering you have no term.write lines I'm not exactly sure how it could "pick up an error" on it... please edit your posts to make the code easier to read (using the above suggestion) and also make sure to post the error messages exactly how it appears, if there is no actual error message make sure to post what it is doing and what you expect it to do in as much detail as possible so that we can better help you.
Now to a problem, the read functions within Lua/ComputerCraft both return the user input as a string, not as a number, as such you need to convert their input to a number before making a comparison (or just compare against "1" instead)
You also have a useless elseif in your code. here is how if ... elseif statements work
a standard if is like so
if input == "1" then --# code here when input is "1" end
now if you want to do something when that condition is false you do the following
if input == "1" then --# code here if input is "1" else --# code here if input is anything except "1" end
now lets assume you're checking multiple input values
if input == "1" then --# code when input is "1" elseif input == "2" then --# code when input is "2" else --# code when input is not "1" or "2" end
so basically your print("This has not been implemented yet") should not be inside the conditional, it should be the code that comes after an else.
your last problem will be that you're changing the redstone and bundled cable states so quickly that they may not actually interact in the way you want them, i.e. the device at the other end may not get a pulse, as such you should add a delay between turning on and off the signal.
Edited by theoriginalbit, 24 February 2014 - 11:39 PM.
#6
Posted 06 March 2014 - 11:10 PM
I've fixed the code a bit, but am still getting the error, i have a link to the files:
https://drive.google...dit?usp=sharing
https://drive.google...dit?usp=sharing
https://drive.google...dit?usp=sharing
https://drive.google...dit?usp=sharing
https://drive.google...dit?usp=sharing
(Some are for other test forum pieces)
The error im getting is "attempted to call nil"
https://drive.google...dit?usp=sharing
https://drive.google...dit?usp=sharing
https://drive.google...dit?usp=sharing
https://drive.google...dit?usp=sharing
https://drive.google...dit?usp=sharing
(Some are for other test forum pieces)
The error im getting is "attempted to call nil"
#8
Posted 11 March 2014 - 12:01 AM
The output is...
> Binary
Please Input Signal [1-9]: Binary:5: attempt to
call nil
>_
> Binary
Please Input Signal [1-9]: Binary:5: attempt to
call nil
>_
#9
Posted 11 March 2014 - 12:21 AM
L00K3, on 11 March 2014 - 12:01 AM, said:
Binary:5: attempt to call nil
the bit at the start is the filename where the problem has occurred, the next bit is the line number it has occurred on, and the final section is what is wrong.
in this case what it is saying is "in the file 'Binary' on line 5 you're attempting to call a function that does not exist" taking a look at the file `Binary` you'll find that you're invoking term.read() which does not exist you're after read()
#10
Posted 12 May 2014 - 02:44 AM
Yeah i know how to read error messages but i don't understand why it doesn't display ¨This has not been implemented yet¨. And why I am at it, i would like to know how to set a multiway selection to make it easier to make case's like selecting the 1 - 10 (As now there are 10 strands).
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











