This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
FuuuAInfiniteLoop(F.A.I.L)'s profile picture

Multiple points

Started by FuuuAInfiniteLoop(F.A.I.L), 01 April 2013 - 08:35 AM
FuuuAInfiniteLoop(F.A.I.L) #1
Posted 01 April 2013 - 10:35 AM
edit: my program gives me that error

layout:
C computer
R redstone
RRRRR
C C

pastebin: http://pastebin.com/T4Vjx71e
remiX #2
Posted 01 April 2013 - 10:44 AM
3rd thread today? :P/>

Give me your code and i'll give it a try
FuuuAInfiniteLoop(F.A.I.L) #3
Posted 01 April 2013 - 11:11 AM
It doesnt matter now, i rewrite(other time :angry:/> :angry:/> :angry:/> :angry:/> :angry:/>) and now every character is converted into a number and then that number is converted on binary and so on, i will post it here if i found another proble(changing the title)

EDIT: And i belive that it its the 5 post today…
FuuuAInfiniteLoop(F.A.I.L) #4
Posted 01 April 2013 - 11:38 AM
code: http://pastebin.com/3rrSBaVK
send doesnt do anything
FuuuAInfiniteLoop(F.A.I.L) #5
Posted 01 April 2013 - 12:10 PM
nobody helps?
theoriginalbit #6
Posted 01 April 2013 - 04:24 PM
code: http://pastebin.com/3rrSBaVK
send doesnt do anything
wow even more complicated than the last…. why did you ditch opening the file in binary mode?
also, why did you abandon the other thread?! I was trying to help you there…
Unit158 #7
Posted 01 April 2013 - 06:29 PM
Edit: actually, I want to know why you need this first.
theoriginalbit #8
Posted 01 April 2013 - 06:34 PM
Edit: actually, I want to know why you need this first.
he is trying to make a program that sends files over redstone pulses…


how do it do it?its maybe the 7 or the 8 rewrite of a program that needs this
I am working on making a solution atm so I can help you fix your problematic program… So far I have the reading of a file and transmitting over redstone done (took about 30 mins and an hour of debugging)… all I have left is to fix the receiving end. few bugs with receiving the pulses…
theoriginalbit #9
Posted 01 April 2013 - 08:08 PM
I am very close to getting it… I seem to have some bits being dropped for some reason

Output by the programs (top is sender, bottom is receiver)
01101000 01100101 01101100 01101100 01101111 00100000 01110111 01101111 01110010 01101100 01100100 00100001
01001000 01000101 01001000 01001000 01001000 00100000 01000100 01001000 01000010 01001000 01000100 00100001 00000000
no the 8 0's at the end is not a bug, it is the terminator so the receiver knows its end of stream.
theoriginalbit #10
Posted 01 April 2013 - 09:40 PM
Ok finally got it figured out…. now that I know exactly what needs to be done, post up your current code of the program and I can help you fix the bugs you had…
FuuuAInfiniteLoop(F.A.I.L) #11
Posted 02 April 2013 - 03:49 AM
Spoilerfunction getChar(str, pos)
return str:sub(pos, pos)
end
function numbertoBinary(dec)
dec = tonumber(dec)
dec=dec*2
local bin=""
for i=0,7 do
bin=bin..tostring(math.ceil(math.floor(dec/2)%2))
dec=math.floor(dec/2)
end
return string.reverse(bin)
end
function numberfromBinary(bin)
return tonumber(bin, 2)
end
function getNumber(str)
count = 0
for k,v in pairs(numbers) do
count = count+1
if v=="str" then return count end
end
end
function toBinary(str)
bin = ""
for i=1, #str do
local a = getChar(str, i)
if a=="\n" then a = "end of line" end
local b = getNumber(a)
bin = bin..numbertoBinary(B)/>
end
return bin
end
function fromBinary(str)
count = 0
temp = ""
tempt = {}
result = ""
for i=1, #str do
count = count+1
temp = temp..str
if count==8 then
table.insert(tempt, temp)
temp = ""
count = 0
end
end
for i=1, #tempt do
local a = numberfromBinary(tempt)
if a=="end of line" then a = "\n" end
result = result..temp
end
temp = nil
count = nil
tempt = nil
return result
end
numbers = {}
numbers["1"] = " "
numbers["2"] = "!"
numbers["3"] = '"'
numbers["4"] = "#"
numbers["5"] = "$"
numbers["6"] = "%"
numbers["7"] = "&"
numbers["8"] = "'"
numbers["9"] = "("
numbers["10"] = ")"
numbers["11"] = "*"
numbers["12"] = "+"
numbers["13"] = ","
numbers["14"] = "-"
numbers["15"] = "."
numbers["16"] = "/"
numbers["17"] = "0"
numbers["18"] = "1"
numbers["19"] = "2"
numbers["20"] = "3"
numbers["21"] = "4"
numbers["22"] = "5"
numbers["23"] = "6"
numbers["24"] = "7"
numbers["25"] = "8"
numbers["26"] = "9"
numbers["27"] = ":"
numbers["28"] = ";"
numbers["29"] = "<"
numbers["30"] = "="
numbers["31"] = ">"
numbers["32"] = "?"
numbers["33"] = "@"
numbers["34"] = "A"
numbers["35"] = "B"
numbers["36"] = "C"
numbers["37"] = "D"
numbers["38"] = "E"
numbers["39"] = "F"
numbers["40"] = "G"
numbers["41"] = "H"
numbers["42"] = "I"
numbers["43"] = "J"
numbers["44"] = "K"
numbers["45"] = "L"
numbers["46"] = "M"
numbers["47"] = "N"
numbers["48"] = "O"
numbers["49"] = "P"
numbers["50"] = "Q"
numbers["51"] = "R"
numbers["52"] = "S"
numbers["53"] = "T"
numbers["54"] = "U"
numbers["55"] = "V"
numbers["56"] = "W"
numbers["57"] = "X"
numbers["58"] = "Y"
numbers["59"] = "Z"
numbers["60"] = "["
numbers["61"] = "\\"
numbers["62"] = "]"
numbers["63"] = "^"
numbers["64"] = "_"
numbers["65"] = "`"
numbers["66"] = "a"
numbers["67"] = "b"
numbers["68"] = "c"
numbers["69"] = "d"
numbers["70"] = "e"
numbers["71"] = "f"
numbers["72"] = "g"
numbers["73"] = "h"
numbers["74"] = "i"
numbers["75"] = "j"
numbers["76"] = "k"
numbers["77"] = "l"
numbers["78"] = "m"
numbers["79"] = "n"
numbers["80"] = "o"
numbers["81"] = "p"
numbers["82"] = "q"
numbers["83"] = "r"
numbers["84"] = "s"
numbers["85"] = "t"
numbers["86"] = "u"
numbers["87"] = "v"
numbers["88"] = "w"
numbers["89"] = "x"
numbers["90"] = "y"
numbers["91"] = "z"
numbers["92"] = "{"
numbers["93"] = "|"
numbers["94"] = "}"
numbers["95"] = "~"
numbers["96"] = "end of line"
numbers["97"] = "ping"
line = "back"
args = {…}
result = ""
if not args==2 then
error(shell.getRunningProgram().." send/receive filename")
end
if args[1]=="send" then
file = fs.open(args[2], "r")
local rts = file.readAll()
file.close()
tosend = numbertoBinary(97)..toBinary(rts)..numbertoBinary(97)
for i=1, #tosend do
local bit = getChar(tosend, i)
if bit=="1" then
rs.setOutput(line, true)
sleep(0.2)
rs.setOutput(line, false)
else
sleep(0.2)
end
sleep(0)
end
else
os.pullEvent("redstone")
actualbit = ""
count = 0
resultb = ""
started = false
while true do
if rs.getInput(line) then
count = count+1
actualbit = actualbit.."1"
else
count = count+1
actualbit = actualbit.."0"
end
sleep(0.2)
if count==8 then
if actualbit==numbertoBinary(97) then
if started then break end
if not started then started = true end
else
resultb = resultb..actualbit
end
actualbit = ""
count = 0
end
end
actualbit = nil
count = nil
started = nil
result = fromBinary(resultb)
resultb = nil
file = fs.open(args[2], "w")
file.write(result)
file.close()
result = nil
end
Error: it doesnt send anithing
theoriginalbit #12
Posted 02 April 2013 - 03:56 AM
-snip-
gah. why no pastebin or [code][/code] tags?! you should know better… ok taking a look now…
theoriginalbit #13
Posted 02 April 2013 - 04:17 AM
ok, so why are you using your own encoding scheme? why not just stick with ASCII? since all you are sending bytes anyways, its not like your own scheme reduces it any.

the 'numbers' table needs to be declared before you are using it in "getNumber"

line 34 is missing 'b )'

bin = bin..numbertoBinary(

the sleep(0) at line 182 is kind of redundant.

other than that, I can't really visually see where any problems are… as long as the "numbertoBinary" function works correctly… I'm going to add some print statements in and actually run it to see what else is going on…
FuuuAInfiniteLoop(F.A.I.L) #14
Posted 02 April 2013 - 05:06 AM
pastebin: http://pastebin.com/5TTJB2tR

This is the ode where im working on notepad++
FuuuAInfiniteLoop(F.A.I.L) #15
Posted 02 April 2013 - 05:08 AM
pastebin: http://pastebin.com/5TTJB2tR

This is the ode where im working on notepad, but i cant tested cause im using 1.4.6 for playing in a server

Stills sending nothing…
FuuuAInfiniteLoop(F.A.I.L) #16
Posted 02 April 2013 - 06:16 AM
I corrected a bit the code

now the error is: test:104: attempt to perform aritmethic __mul on nil and number

the pastebin is the same: http://pastebin.com/5TTJB2tR
theoriginalbit #17
Posted 02 April 2013 - 06:21 AM
unrelated bugs…

but… you need to fix this

if not args==2 then
to be either


if not (args==2) then
or


if args ~=2 then

and if you put a ,0 in the error like so

error(shell.getRunningProgram().." send/receive filename", 0)

it will not put the file name and line number in the error message.
theoriginalbit #18
Posted 02 April 2013 - 06:59 AM
now the error is: test:104: attempt to perform aritmethic __mul on nil and number
ok your problem is in this function


function getNumber(str)
  count = 0
  for k,v in pairs(numbers) do
    count = count+1
    if v=="str" then return count end
  end
end

specifically with this line

if v=="str" then return count end

should be

if v==str then return count end

and at the end of the function you should add


error('Unsupported character found in file', 0)
FuuuAInfiniteLoop(F.A.I.L) #19
Posted 02 April 2013 - 07:48 AM
Now it send things!

But it dontn stop receiving…
theoriginalbit #20
Posted 02 April 2013 - 07:50 AM
Now it send things!
Indeed it is… :)/>
FuuuAInfiniteLoop(F.A.I.L) #21
Posted 02 April 2013 - 08:00 AM
Yeak but apparently the ping command isnt sended/received correctly so the receiver doesnt stop receiving
theoriginalbit #22
Posted 02 April 2013 - 08:39 AM
maybe just add a timeout to the receiver? after say 2 seconds of no pulses stop receiving…
FuuuAInfiniteLoop(F.A.I.L) #23
Posted 02 April 2013 - 09:35 AM
maybe just add a timeout to the receiver? after say 2 seconds of no pulses stop receiving…

I assigned a byte to the ping command so when then file ends it sends that and the receiver must stop
theoriginalbit #24
Posted 02 April 2013 - 09:38 AM
I assigned a byte to the ping command so when then file ends it sends that and the receiver must stop
Maybe have a backup timeout?
I'm not too sure why that PING is not getting received…. the only reason I can think is if the bits are not being detected correctly (a problem I had) and thus it doesn't see it as the PING… try adding some debug messages to the receiver to print the byte it has received…
FuuuAInfiniteLoop(F.A.I.L) #25
Posted 02 April 2013 - 09:39 AM
I will recode it other tim :(/> can somwbody give a way to read all the file in binary and write it in binary so i can start all over
theoriginalbit #26
Posted 02 April 2013 - 09:45 AM
you can open the file like normal and then just convert each character into its byte representation with string.byte
or you can read the file in binary mode which reads a byte at a time…

Here is a chapter on Binary files: http://www.lua.org/pil/21.2.2.html
FuuuAInfiniteLoop(F.A.I.L) #27
Posted 02 April 2013 - 11:20 AM
http://pastebin.com/bbxwEXjk
Error: the receiver doesnt recive anything
theoriginalbit #28
Posted 02 April 2013 - 11:45 AM
http://pastebin.com/bbxwEXjk
Error: the receiver doesnt recive anything
Uhhh could be because of this

os.pullEvent("key")
correct me if im wrong. but pretty sure that should be 'timer' not key
FuuuAInfiniteLoop(F.A.I.L) #29
Posted 02 April 2013 - 11:52 AM
http://pastebin.com/bbxwEXjk
Error: the receiver doesnt recive anything
Uhhh could be because of this

os.pullEvent("key")
correct me if im wrong. but pretty sure that should be 'timer' not key
no it itsnt i replaced it with that and i didnt edit the part saying that it must be a timer so is correct, the thing is that the receiver doesnt say and 1 that says that it received that
theoriginalbit #30
Posted 02 April 2013 - 12:01 PM
no it itsnt i replaced it with that and i didnt edit the part saying that it must be a timer so is correct, the thing is that the receiver doesnt say and 1 that says that it received that
huh?
FuuuAInfiniteLoop(F.A.I.L) #31
Posted 02 April 2013 - 12:09 PM
The sender sends the file but the receiver doesnt show that is receiving anything, and now it uses two lines of redstone, one connected to the back of them and other to the front
theoriginalbit #32
Posted 02 April 2013 - 12:18 PM
Ahhh ok… I'm not too sure… and I'm not too sure why you need 3 functions to do it… all you need is a timer loop that checks the redstone every 0.1 seconds…. why do you need 3 functions and 3 loops doing this?

Yeh i noticed the two independent lines… might be a good idea to do, speed up transfer, since the transfer speed on a single line is 1 byte every 0.8 seconds. or if you prefer 5 bytes every 4 seconds…. That means "Hello World!" would take 9.6 seconds to send from one computer to another… so adding a second line would halve the amount of time taken to send data…
FuuuAInfiniteLoop(F.A.I.L) #33
Posted 02 April 2013 - 12:19 PM
I use two lines cause i detect the redstone event so i need to have 2 lines one for 1 and one for 0
theoriginalbit #34
Posted 02 April 2013 - 12:22 PM
I know that…….. I can read code…. but you don't actually need to… the solution I got to work used only one line… it used a timer that triggered every 0.1 seconds, and when it triggered the redstone input was checked…
FuuuAInfiniteLoop(F.A.I.L) #35
Posted 02 April 2013 - 02:41 PM
I edited the first post so is easier