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

Bundled cable IO question

Started by L00K3, 12 February 2014 - 03:03 AM
L00K3 #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 or colours
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 or colours
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 or colours
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


– The control API

– This is my program to control the SDD


api = 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)
redstone.output("top", true)
redstone.output("top", false)
output.set("magenta", false)
elseif
print ("This has not been implemented yet") then
end


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!
CometWolf #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.

os.loadAPI("/API file path")
L00K3 #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
L00K3 #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.
theoriginalbit #5
Posted 24 February 2014 - 11:38 PM
The io functions are for handling files stored on your computer, mainly reading and writing these files.
Nope, the IO library is a standard Input & Output library, meaning io.write acts the same as write, and io.read acts the same as read, it is only when these functions are used on a file handle that it acts differently. Try it open the lua prompt and type in io.write("Input: "..io.read().."\n") it will behave in the exact same manner as write("Input: "..read().."\n") the only thing you cannot do with io.read is make use of input masks or history like you can with read, which is something the OP is not doing anyway

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.
As CometWolf stated please try and use [code][/code] tags around your code when you post it to the forums, and/or make use of pastebin especially for longer scripts.

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 on 24 February 2014 - 10:39 PM
L00K3 #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"
theoriginalbit #7
Posted 06 March 2014 - 11:13 PM
The error im getting is "attempted to call nil"
*sigh* what is the full error message? It should say a file and line number.
L00K3 #8
Posted 11 March 2014 - 12:01 AM
The output is…

> Binary
Please Input Signal [1-9]: Binary:5: attempt to
call nil

>_
theoriginalbit #9
Posted 11 March 2014 - 12:21 AM
Binary:5: attempt to call nil
okay so how to read error messages…

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()
L00K3 #10
Posted 12 May 2014 - 03: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).