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

Creating a basic telegraph that goes both ways. Help?

Started by minz1, 29 July 2016 - 08:47 PM
minz1 #1
Posted 29 July 2016 - 10:47 PM
http://pastebin.com/rDX7eRAZ

My issue is that I can't figure out how to take a string, and translate each character to decimal, then binary, and then transmit it over redstone.

I don't want to be shown "oh here's the code" I really want to figure this out, but i haven't been able to figure this one out yet

I figured I could also have the computer waiting in the background waiting first for some sort of 5 second long signal, then
open itself up to messages until another 5 second long signal is given.
KingofGamesYami #2
Posted 29 July 2016 - 11:02 PM
You may want to look at this thread.

Some quick tips:

* tonumber can convert from decimal to binary or back, I don't remember which
* string.byte converts from string to decimal
* on the redstone side, you can time the changes in redstone using os.clock (minimum is 0.05s)
minz1 #3
Posted 29 July 2016 - 11:32 PM
You may want to look at this thread.

Some quick tips:

* tonumber can convert from decimal to binary or back, I don't remember which
* string.byte converts from string to decimal
* on the redstone side, you can time the changes in redstone using os.clock (minimum is 0.05s)

right now, my main problem is that the redstone doesn't show any change. i don't really know why. this is what i've been doing.
http://pastebin.com/KD21sUWV

also, that thread was one of my main sources, but thanks! i should look at that thread again
Emma #4
Posted 30 July 2016 - 06:11 AM
The reason your redstone doesn't change from what I can see is because you're calling decBin with the char's byte value (which is correct), but then you check if it's a 1 or a 0, it won't be either.
Your decBin function returns a string containing a whole binary sequence which is 15 values (why not 16?), not 1.
To fix this, try placing your redstone code in a loop which iterates through the string returned by decBin.
Here is the code with the proper adjustments:

for c in input:gmatch(".") do
    local decChar = string.byte(c)
    local binSeq = decBin(decChar)
    for binChar in binSeq:gmatch(".") do
        if binChar == "0" then
            redstone.setOutput("right",false)
        elseif binChar == "1" then
            redstone.setOutput("right",true)
        end
        os.sleep(0.5)
    end
end
Edited on 30 July 2016 - 04:32 PM
Lyqyd #5
Posted 30 July 2016 - 06:32 PM
Don't bump topics unless there's been no activity for multiple weeks.