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

[SOLVED] Code dont work, not know why

Started by FuuuAInfiniteLoop(F.A.I.L), 19 February 2013 - 01:42 PM
FuuuAInfiniteLoop(F.A.I.L) #1
Posted 19 February 2013 - 02:42 PM
SOLVED look at my signature
FuuuAInfiniteLoop(F.A.I.L) #2
Posted 19 February 2013 - 02:53 PM
any help?
theoriginalbit #3
Posted 19 February 2013 - 03:00 PM
any help?
Y u so impatient!

http://cdn.memegener...0x/31969471.jpg
Shnupbups #4
Posted 19 February 2013 - 03:25 PM
Spoilers. Use them.
theoriginalbit #5
Posted 19 February 2013 - 03:28 PM
Also where the hell is the 'view' function?! And are you getting an error? or just an unexpected result?
ChunLing #6
Posted 19 February 2013 - 05:05 PM
Please explain exactly what you think this code should do, and exactly what it actually does (yes, this would include any error messages thrown).
FuuuAInfiniteLoop(F.A.I.L) #7
Posted 20 February 2013 - 04:11 AM
edited
FuuuAInfiniteLoop(F.A.I.L) #8
Posted 20 February 2013 - 05:09 AM
I made a few chnges to try to rsolve the error but nothing

erroR: log:382 attempt to concatenate string and nil
FuuuAInfiniteLoop(F.A.I.L) #9
Posted 20 February 2013 - 05:30 AM
If you wnat to test the function without creating a log yourselfves, i will post one log


--lol was run
%section%[Info]
runtime=0 days, 0 hours, 0 minutes, 2 seconds
times run=1
%section%[Properties]
Save Log=true
Exclude From Save Log=
Save running data=true
%section%[Code]
term.clear()
term.write("lol")
print("WUTT")
term.setCursorPos(1,6)
paintutils.drawPixel(3,3, colors.red)
print("Testing")
sleep(2)
error("finished")
%section%[Program Log]
System - rewriting term library
System - Running program
Trying - shell.run with args: lol
Screen - cleared
Screen - wrote lol at 1 2
Screen - wrote WUTT at 4 2
Screen - Set cursor pos to 1 3
Screen - Set cursor pos to 1 6
Screen - Set cursor pos to 3 3
Screen - wrote   at 3 3
Screen - wrote Testing at 4 3
Screen - Set cursor pos to 1 4
Error - finished
System - Saving Event Log
Lyqyd #10
Posted 20 February 2013 - 06:06 AM
What is the gmatch with the ".-n" pattern for? I don't think it does what you think it does.
FuuuAInfiniteLoop(F.A.I.L) #11
Posted 20 February 2013 - 06:21 AM
What is the gmatch with the ".-n" pattern for? I don't think it does what you think it does.
I founded it on the forums, is for spliting all lines into the table, and it work because when loading, it display the number of lines of my log(37) so it isnt the problem
theoriginalbit #12
Posted 20 February 2013 - 06:22 AM
I founded it on the forums, is for spliting all lines into the table, and it work because when loading, it display the number of lines of my log(37) so it isnt the problem
New lines aren't 'n' they are '\n' or in a patterns case '\\n'
FuuuAInfiniteLoop(F.A.I.L) #13
Posted 20 February 2013 - 06:25 AM
I founded it on the forums, is for spliting all lines into the table, and it work because when loading, it display the number of lines of my log(37) so it isnt the problem
New lines aren't 'n' they are '\n' or in a patterns case '\\n'
IT ISNT THE PROBLEM, the file is loaded and splitted corectly, have you runned the program, the first line when you run it say that it loaded 37 lines, the log line number

The problem is that it dont search, found and add to the respective table the sections!

and sorry for rage
FuuuAInfiniteLoop(F.A.I.L) #14
Posted 20 February 2013 - 06:30 AM
Spoilered
theoriginalbit #15
Posted 20 February 2013 - 06:52 AM
IT ISNT THE PROBLEM, the file is loaded and splitted corectly, have you runned the program, the first line when you run it say that it loaded 37 lines, the log line number

The problem is that it dont search, found and add to the respective table the sections!

and sorry for rage
No i haven't run the program. but i can tell you right now 100% that it will cause a problem! there are 37 characters 'n' in that file you supplied, there are 32 lines in the file. So yes while the incorrect splitting of the lines may not be the cause of the issue you are getting, it is AN issue.

EDIT: Now as for the issue you are having. the error message tells you everything. By reading the message I looked at line 384, and noticed you were indexing the 'info' table. so then I used 'find'/'search' and found that there is a table 'info', and that you DONT add anything to the table, hence the indexing a nil value. I suggest that you read through your code a little more and see where the problem is, as I had a hard time following it, so cant suggest anything. Also while adding indenting to your code, just so I could see what was what, and where stuff started, I saw a few other issues in other areas of your code.
Edited on 20 February 2013 - 05:59 AM
FuuuAInfiniteLoop(F.A.I.L) #16
Posted 20 February 2013 - 07:30 AM
can you give me a code for splitting lines because i have tried \n and \\n and it dont work, the code where it must be inserted


a = fs.open(name, "r")
b = a.readAll()
a.close()
file = {}
for line in b:gmatch('\\n') do
table.insert(file, line)
end

EDIT:You can see i tested it because in the line it said \\n
theoriginalbit #17
Posted 20 February 2013 - 07:33 AM
-snip-
Using the string.split function you have works. its exactly the same as the one I use all the time and have release in my Extended string library. all you need to do is this


a = fs.open(name, "r")
b = a.readAll()
a.close()
file = split.string(b, "\n")
FuuuAInfiniteLoop(F.A.I.L) #18
Posted 20 February 2013 - 07:37 AM
-snip-
Using the string.split function you have works. its exactly the same as the one I use all the time and have release in my Extended string library. all you need to do is this


a = fs.open(name, "r")
b = a.readAll()
a.close()
file = split.string(b, "\n")
your code say "attempt to index ? (a nil value) "

i copy the "file = split.string(b, "\n")" instead of my "for lines in (blablabla)"
theoriginalbit #19
Posted 20 February 2013 - 07:43 AM
your code say "attempt to index ? (a nil value) "

i copy the "file = split.string(b, "\n")" instead of my "for lines in (blablabla)"
I'm assuming that error is still on line 382? because making that ONE change wasn't a fix for the other problems that are in the code.

yes, the string.split function IS a replacement for your for loop. although last time I tried to do string.split I got an "attempt to write to global" error. (off topic) I wonder if they have allowed this now…. hmmm…
LBPHacker #20
Posted 20 February 2013 - 07:59 AM
I'm not sure but… I think info["times run"] makes Lua mad too…
theoriginalbit #21
Posted 20 February 2013 - 08:04 AM
I'm not sure but… I think info["times run"] makes Lua mad too…
its all the 'info' table referencing. there is nothing in the info table.
LBPHacker #22
Posted 20 February 2013 - 08:06 AM
-snip-

I know, but you've already mentioned that. I'm just saying that a key is not a valid key with spaces in it.

… or is it?
FuuuAInfiniteLoop(F.A.I.L) #23
Posted 20 February 2013 - 08:09 AM
your code say "attempt to index ? (a nil value) "

i copy the "file = split.string(b, "\n")" instead of my "for lines in (blablabla)"
I'm assuming that error is still on line 382? because making that ONE change wasn't a fix for the other problems that are in the code.

yes, the string.split function IS a replacement for your for loop. although last time I tried to do string.split I got an "attempt to write to global" error. (off topic) I wonder if they have allowed this now…. hmmm…
yes it is in line 382, but the only thing i need is that then I will repair the othr errors, GIVE MEH THAT CODE!!!!!
theoriginalbit #24
Posted 20 February 2013 - 08:17 AM
I know, but you've already mentioned that. I'm just saying that a key is not a valid key with spaces in it.
… or is it?
Spaces are valid like this tTable["some key"] but not like this tTable.some key

yes it is in line 382, but the only thing i need is that then I will repair the othr errors, GIVE MEH THAT CODE!!!!!
I don't do demands…… and also if you read reply #15 again… (note the bold)

EDIT: Now as for the issue you are having. the error message tells you everything. By reading the message I looked at line 384, and noticed you were indexing the 'info' table. so then I used 'find'/'search' and found that there is a table 'info', and that you DONT add anything to the table, hence the indexing a nil value. I suggest that you read through your code a little more and see where the problem is, as I had a hard time following it, so cant suggest anything. Also while adding indenting to your code, just so I could see what was what, and where stuff started, I saw a few other issues in other areas of your code.
FuuuAInfiniteLoop(F.A.I.L) #25
Posted 20 February 2013 - 08:22 AM
I know, but you've already mentioned that. I'm just saying that a key is not a valid key with spaces in it.
… or is it?
Spaces are valid like this tTable["some key"] but not like this tTable.some key

yes it is in line 382, but the only thing i need is that then I will repair the othr errors, GIVE MEH THAT CODE!!!!!
I don't do demands…… and also if you read reply #15 again… (note the bold)

EDIT: Now as for the issue you are having. the error message tells you everything. By reading the message I looked at line 384, and noticed you were indexing the 'info' table. so then I used 'find'/'search' and found that there is a table 'info', and that you DONT add anything to the table, hence the indexing a nil value. I suggest that you read through your code a little more and see where the problem is, as I had a hard time following it, so cant suggest anything. Also while adding indenting to your code, just so I could see what was what, and where stuff started, I saw a few other issues in other areas of your code.
line 318:

function addtotable(str, t)
a = string.split(str, "=")
s = a[1]
l = a[2]
if t=="info" then info[s] = l end
if t=="ps" then ps[s] = l end
if t=="code" then code[s] = l end
if t=="plog" then plog[s] = l end
end
line 295:

tables = {}
tables["Info"] = "info"
tables["Properties"] = "ps"
tables["Code"] = "code"
tables["Program Log"] = "plog"
info = {}
ps = {}
code = {}
plog = {}
function compare(str)
for k, v in pairs(tables) do
  if str=="%section%["..k.."]" then
   return v
  end
end
end
line 353

for i=1, #file do
  v = compare(file[i])
  if not v then
   lolololollolololooll = lljljkljl
  else
   for o=i+1, #file do
    b = compare(file[o])
    if not b then
	 addtotable(b, file[i])
    else
	 break
    end
   end
  end
end
FuuuAInfiniteLoop(F.A.I.L) #26
Posted 20 February 2013 - 08:29 AM
I want to split all the lines of a file that is readed with readAll(because it can contain blank lines or not) to a table so i can work with every line, i have in my code a string.split function


function string.split(str, pat)
local t = {}
local fpat = "(.-)"..pat
local last_end = 1
local s, e, cap = str:find(fpat, 1)
while s do
  if s ~= 1 or cap ~= "" then
table.insert(t,cap)
  end
  last_end = e+1
  s, e, cap = str:find(fpat, last_end)
end
if last_end <= #str then
  cap = str:sub(last_end)
  table.insert(t, cap)
end
return t
end
theoriginalbit #27
Posted 20 February 2013 - 08:29 AM
-snip-
now let me show YOU something….. because no matter how much code you show me it doesn't change the FACTS………..

Line 381 insert this code and run the program

term.setBackgroundColor(colors.black) term.clear() term.clear() if #info > 0 then for k,v in pairs(info) do print(k..":"..v) end else print("TABLE IS EMPTY! NOTHING! NADA! THERE IS NO DATA HERE!") end sleep(4)
theoriginalbit #28
Posted 20 February 2013 - 08:31 AM
As I stated in the other thread there is nothing wrong with this function its all about the usage. I have used it well over 100 times.


local h = fs.open( <file>, "r" )
local contents = fs.readAll()
h.close()

local linesTable = string.split( contents, "\n" )
Lyqyd #29
Posted 20 February 2013 - 08:36 AM
Reading a file into a table of the lines:


local linesTable = {}
local handle = io.open("filename", "r")
if handle then
  for line in handle:lines() do
    table.insert(linesTable, line)
  end
else
  error("Could not open file!")
end

If you come here for help, you need to read, understand and accept that help. Do not tell people they are wrong without trying it first. Obviously you don't have the knowledge to fix it yourself, so set your ego aside and let those with the knowledge actually help you.
FuuuAInfiniteLoop(F.A.I.L) #30
Posted 20 February 2013 - 08:38 AM
I have tied his recomendations!! but they dont work it ives me the same error or another in the same line
theoriginalbit #31
Posted 20 February 2013 - 08:40 AM
I have tied his recomendations!! but they dont work it ives me the same error or another in the same line
Its because you have countless errors CAUSING that one error (which I know I have also told you before) and the code I provided was for just ONE of those bugs that is causing the main one…
Lyqyd #32
Posted 20 February 2013 - 08:41 AM
Threads merged. Don't start new topics because you're dissatisfied with the (useful) advice you have already been given.

Instead of just saying, "It didn't work! Wah!", try providing the code with the suggested modifications and the new full error message. We can't guess what you may have done to misapply a suggestion.
FuuuAInfiniteLoop(F.A.I.L) #33
Posted 20 February 2013 - 08:43 AM
I have used the lyqyd code and now the error is in line 56, bad argument: string expected, got boolean
code:
Spoiler

args = { ... }
term.setTextColour( colours.blue )
runType = ( args[1] == "run" or args[1] == "log" or args[1] == "data" or args[1] == "clear" or args[1] == "view") and args[1] or print( "Usage: \"run [run type] [program name]\"" ) and error()
name = (args[2] or fs.exists( args[2] )) and args[2] or print( "Usage: \"run [run type] [program name]\"" ) and error()
table.remove( args, 1 )
table.remove( args, 1 )
log = { }
log.data = { }
log.savedData = log.data
log.saveLogExcludeTypes = { }
function log.add( type, ... )
for i = 1,#log.saveLogExcludeTypes do
  if type == log.saveLogExcludeTypes[i] then return false end
end
if type == nil then
  type = "Undefined"
end
arg = { ... }
table.insert( log.data, { type = type, unpack( arg ) } )
return true
end
function log.save( tSave )
log.add( "System", "Saving Event Log" )
if #log.data > 1 then
  table.insert( tSave, "%section%[Program Log]")
  for i = 1, #log.data do
   log.toWrite = true
   for m = 1,#log.saveLogExcludeTypes do
    if log.data[i]["type"] == log.saveLogExcludeTypes[m] then
	 log.toWrite = false
    end
   end
   if log.toWrite then
    local str = ""
    for k = 1,#log.data[i] do
	 str = str..tostring( log.data[i][k] ).." "
    end
    table.insert( tSave, tostring( log.data[i]["type"] ).." - "..str )
   end
  end
end
return tSave
end
function string.split(str, pat)
local t = {}
local fpat = "(.-)"..pat
local last_end = 1
local s, e, cap = string.find(str, fpat, 1)
while s do
  if s ~= 1 or cap ~= "" then
table.insert(t,cap)
  end
  last_end = e+1
  s, e, cap = str:find(fpat, last_end)
end
if last_end <= #str then
  cap = str:sub(last_end)
  table.insert(t, cap)
end
return t
end
function try( strName, name, ... )
local args = { ... }
log.add( "Trying", strName, "with args:", unpack ( args ) )
err = { pcall( name, unpack( args ) ) }
ok = err[1]
if not ok then
  log.add( "Error", "with function:", strName, "with args:", unpack( args ) )
  return false
end
return unpack( err )
end
defaultProperties = { true, "", true, { } }
programProperties = { [1] = "", [2] = "", [3] = "", [4] = "" }
function getProperties( tContent )
for i = 1,#programProperties do
  programProperties[i] = defaultProperties[i]
end
for i = 1,#tContent do
  if tContent[i] == "%section%[Properties]" then
   local z = 1
   while tContent[z+i] ~= nil do
    m = string.split( tContent[z+i], "=" )
    if m[2] ~= nil then
	 if z == 1 then
	  local m = m[2]
	  if m == "false" then
	   programProperties[1] = false
	  else
	   programProperties[1] = true
	  end
	 elseif z == 2 then
	  log.saveLogExcludeTypes = string.split( m[2], "," )
	  programProperties[3] = log.saveLogExcludeTypes
	 elseif z == 3 then
	  local m = m[2]
	  if m == "false" then
	   programProperties[3] = false
	  else
	   programProperties[3] = true
	  end
	 end
    end
    z = z+1
   end
   break
  end
end
end
function insertInformation( tFile )
if tFile[1] ~= "--"..name.." was run" then
  table.insert( tFile, 1, "%section%[Code]" )
  table.insert( tFile, 1, "Save running data="..tostring( programProperties[3] ) )
  table.insert( tFile, 1, "Exclude From Save Log="..tostring( programProperties[2] ) )
  table.insert( tFile, 1, "Save Log="..tostring( programProperties[1] ) )
  table.insert( tFile, 1, "%section%[Properties]" )
end
if tFile[1] ~= "--"..name.." was run" then
  table.insert( tFile, 1, "times run=1" )
  table.insert( tFile, 1, "runtime="..tostring( run.d ).." days, "..tostring( run.h ).." hours, "..tostring( run.m ).." minutes, "..tostring( run.s ).." seconds" )
  table.insert( tFile, 1, "%section%[Info]" )
  table.insert( tFile, 1, "--"..name.." was run")
else
  if programProperties[3] then
   tFile[3] = "runtime="..tostring( run.d ).." days, "..tostring( run.h ).." hours, "..tostring( run.m ).." minutes, "..tostring( run.s ).." seconds"
   tFile[4] = "times run="..( type( tonumber( string.split( tFile[4], " = " )[2]) ) == "number" and tostring( tonumber( string.split( tFile[4], " = " )[2])+1 ) or "1" )
  else
   tFile[3] = "runtime=enable in properties"
   tFile[4] = "times run=enable in properties"
  end
end
oldTFile = tFile
tFile = {}
for i = 1,#oldTFile do
  if oldTFile[i] ~= "%section%[Program Log]" then
   table.insert( tFile, oldTFile[i] )
  else
   break
  end
end
if programProperties[1] == true then
  tFile = log.save( tFile )
end
k = fs.open( name, "w" )
for i = 1,#tFile do
  k.writeLine( tFile[i] )
end
k.close( )
return true
end
function timer( )
local s = 0
local m = 0
local h = 0
local d = 0
local ms = 0
while true do
  ms = ms+1
  if ms >= 10 then
   ms = 0
   s = s+1
  end
  if s >= 60 then
   s = 0
   m = m+1
  end
  if m >= 60 then
   m = 0
   h = h+1
  end
  if h >= 24 then
   h = 0
   d = d+1
  end
  run.s = s
  run.m = m
  run.h = h
  run.d = d
  sleep( 0.1 )
end
end
function event( )
while true do
  ev = { os.pullEvent( "mouse_click" ) }
  if ev[2] == 2 and ev[3] == 51 and ev[4] == 19 then
   draw = true
  elseif ev[2] == 1 and ev[3] == 51 and ev[4] == 18 and draw == true then
   os.queueEvent( "terminate" )
  elseif draw == true then
   draw = false
  end
end
end
oldTerm = { }
oldTerm.write = _G["term"]["write"]
oldTerm.setCursorPos = _G["term"]["setCursorPos"]
oldTerm.clear = _G["term"]["clear"]
oldTerm.setBackgroundColour = _G["term"]["setBackgroundColour"]
oldTerm.setTextColour = _G["term"]["setTextColour"]
olderror = _G["error"]
log.add( "System", "rewriting term library" )
function error(...)
local arg = { ... }
log.add("Error", unpack( arg ) )
end
function term.write( ... )
local arg = { ... }
x, y = term.getCursorPos( )
log.add( "Screen", "wrote", unpack( arg ), "at", x, y )
oldTerm.write( unpack( arg ) )
oldTerm.setCursorPos( 51, 19 )
oldTerm.write( "^" )
oldTerm.setCursorPos(x,y)
oldTerm.write(unpack( arg ))
if draw then
  oldTerm.setCursorPos( 50, 18 )
  oldTerm.write( "_X" )
end
end
function term.clear( )
log.add( "Screen", "cleared")
oldTerm.clear( )
end
function term.setCursorPos( x, y )
log.add( "Screen", "Set cursor pos to", x, y )
oldTerm.setCursorPos( x, y )
end
run = { }
draw = false
runProg = function( )
try( "shell.run", shell.run, name, unpack( args ) )
end
k = fs.open( name, "r" )
t = { }
m = k.readLine( )
while m do
table.insert( t, m )
m = k.readLine( )
end
k.close()
if runType == "run" then
getProperties( t )
log.add( "System", "Running program" )
parallel.waitForAny( runProg, timer, event )
insertInformation( t )
end
term.write = oldTerm.write
term.clear = oldTerm.clear
term.setCursorPos = oldTerm.setCursorPos
error = olderror
if runType == "log" then
m = { }
isInLog = false
for i = 1,#t do
  if isInLog then
   table.insert( m, t[i] )
  end
  if t[i] == "%section%[Program Log]" then
   isInLog = true
  end
end
table.remove( m, #m )
term.clear( )
term.setCursorPos( 1, 1 )
y = 1
for i = 1,#m do
  term.write( m[i] )
  y = y+1
  term.setCursorPos( 1, y )
end
end
tables = {}
tables["Info"] = "info"
tables["Properties"] = "ps"
tables["Code"] = "code"
tables["Program Log"] = "plog"
info = {}
ps = {}
code = {}
plog = {}
function compare(str)
result = false
for k, v in pairs(tables) do
  if str=="%section%["..k.."]" then
   result = v
  end
end
return result
end
function header(str)
print("")
x, y = term.getCursorPos()
paintutils.drawLine(x, y, #str, y, colors.green)
print(str)
print("")
end
function addtotable(str, t)
a = string.split(str, "=")
s = a[1]
l = a[2]
if t=="info" then info[s] = l end
if t=="ps" then ps[s] = l end
if t=="code" then code[s] = l end
if t=="plog" then plog[s] = l end
end
if runType == "clear" then
oldTFile = t
tFile = { }
for i = 1,#oldTFile do
  if oldTFile[i] ~= "%section%[Program Log]" then
   table.insert( tFile, oldTFile[i] )
  else
   break
  end
end
while tFile[1] ~= "%section%[Code]" do
  table.remove( tFile, 1 )
end
table.remove( tFile, 1 )
k = fs.open( name, "w" )
for i = 1,#tFile do
  k.writeLine( tFile[i] )
end
k.close( )
end
if runType == "view" then
local file = {}
local handle = io.open(name, "r")
if handle then
    for line in handle:lines() do
	   table.insert(file, line)
	 end
else
    error("Could not open file!")
end
save = {}
for i=1, #file do
  v = compare(file[i])
  if not v then
   lolololollolololooll = lljljkljl
  else
   for o=i+1, #file do
    b = compare(file[o])
    if not b then
	 addtotable(b, file[i])
    else
	 break
    end
   end
  end
end
print("Readed "..#file.." lines")
print("4 section")
print("Processing...")
sleep(2)
print("Press any key to continue")
os.pullEvent("key")
term.setBackgroundColor(colors.lightBlue)
term.setTextColor(colors.white)
term.clear()
term.setCursorPos(1,1)
header("Runtime information")
print("Runned in "..info["runtime"])
print("Runned "..info["times run"].." times" )
header("Program configuration")
if ps["Save Log"] then
  print("Saving logs")
else
  print("Not saving logs")
  print("You have edited the log dont you ;)/>")
end
if not ps["Exclude From Save Log"] then
  print("Excluding nothing")
else
  print("Excluding "..ps["Exclude From Save Log"])
end
if not ps["Save running data"] then
  print("Not saving running data")
else
  print("Saving running data")
end
header("Code debugged")
for i=1, #code do
  print(code[i])
end
header("Log")
for i=1, #plog do
  a = string.split(plog[i], " - ")
  print(a[1]..":   "..a[2])
end
term.setCursorPos(1,1)
print("Press a key to go down, terminate this program to exit")
while true do
  os.pullEvent("key")
  term.scroll()
end
end
theoriginalbit #34
Posted 20 February 2013 - 08:46 AM
If you are using Lyqyd's solution you don't need to use my one. they are 2 implementations to do the same thing and they don't work well together.
FuuuAInfiniteLoop(F.A.I.L) #35
Posted 20 February 2013 - 08:48 AM
I use string.split for another function so i can delete it and you solution didnt wirk for me(in cc-emu)
theoriginalbit #36
Posted 20 February 2013 - 08:52 AM
Do whatever you wish, its your code, but I can tell you right now, whether you go for the solution I told you with string.split or the one Lyqyd told you, neither will magically fix your problem.

Side note. My solution didn't work to fix the problem your having for me either, and you know why, its like 10% of the problem, the INFO TABLE is empty. meaning its empty, there is nothing in it, Lua isn't magic, it cant know what you meant to mean, you need to put data in there, and before you say that you are, you aren't. and that one line of code I supplied before should have proved that you didn't!
FuuuAInfiniteLoop(F.A.I.L) #37
Posted 20 February 2013 - 09:32 AM
rewriting code, unknown error

code:



args = { ... }

term.setTextColour( colours.blue )

runType = ( args[1] == "run" or args[1] == "log" or args[1] == "data" or args[1] == "clear" or args[1] == "view") and args[1] or print( "Usage: \"run [run type] [program name]\"" ) and error()

name = (args[2] or fs.exists( args[2] )) and args[2] or print( "Usage: \"run [run type] [program name]\"" ) and error()

table.remove( args, 1 )
table.remove( args, 1 )

log = { }
log.data = { }
log.savedData = log.data
log.saveLogExcludeTypes = { }

function log.add( type, ... )
for i = 1,#log.saveLogExcludeTypes do
if type == log.saveLogExcludeTypes[i] then return false end
end
if type == nil then
type = "Undefined"
end
arg = { ... }
table.insert( log.data, { type = type, unpack( arg ) } )
return true
end

function log.save( tSave )
log.add( "System", "Saving Event Log" )
if #log.data > 1 then
table.insert( tSave, "%section%[Program Log]")
for i = 1, #log.data do
log.toWrite = true
for m = 1,#log.saveLogExcludeTypes do
if log.data[i]["type"] == log.saveLogExcludeTypes[m] then
log.toWrite = false
end
end
if log.toWrite then
local str = ""
for k = 1,#log.data[i] do
str = str..tostring( log.data[i][k] ).." "
end
table.insert( tSave, tostring( log.data[i]["type"] ).." - "..str )
end
end
end
return tSave
end

function string.split(str, pat)
local t = {}
local fpat = "(.-)"..pat
local last_end = 1
local s, e, cap = string.find(str, fpat, 1)
while s do
if s ~= 1 or cap ~= "" then
table.insert(t,cap)
end
last_end = e+1
s, e, cap = str:find(fpat, last_end)
end
if last_end <= #str then
cap = str:sub(last_end)
table.insert(t, cap)
end
return t
end

function try( strName, name, ... )
local args = { ... }
log.add( "Trying", strName, "with args:", unpack ( args ) )
err = { pcall( name, unpack( args ) ) }
ok = err[1]
if not ok then
log.add( "Error", "with function:", strName, "with args:", unpack( args ) )
return false
end
return unpack( err )
end

defaultProperties = { true, "", true, { } }
programProperties = { [1] = "", [2] = "", [3] = "", [4] = "" }

function getProperties( tContent )
for i = 1,#programProperties do
programProperties[i] = defaultProperties[i]
end
for i = 1,#tContent do
if tContent[i] == "%section%[Properties]" then
local z = 1
while tContent[z+i] ~= nil do
m = string.split( tContent[z+i], "=" )
if m[2] ~= nil then
if z == 1 then
local m = m[2]
if m == "false" then
programProperties[1] = false
else
programProperties[1] = true
end
elseif z == 2 then
log.saveLogExcludeTypes = string.split( m[2], "," )
programProperties[3] = log.saveLogExcludeTypes
elseif z == 3 then
local m = m[2]
if m == "false" then
programProperties[3] = false
else
programProperties[3] = true
end
end
end
z = z+1
end
break
end
end
end

function insertInformation( tFile )
if tFile[1] ~= "--"..name.." was run" then
table.insert( tFile, 1, "%section%[Code]" )
table.insert( tFile, 1, "Save running data="..tostring( programProperties[3] ) )
table.insert( tFile, 1, "Exclude From Save Log="..tostring( programProperties[2] ) )
table.insert( tFile, 1, "Save Log="..tostring( programProperties[1] ) )
table.insert( tFile, 1, "%section%[Properties]" )
end
if tFile[1] ~= "--"..name.." was run" then
table.insert( tFile, 1, "times run=1" )
table.insert( tFile, 1, "runtime="..tostring( run.d ).." days, "..tostring( run.h ).." hours, "..tostring( run.m ).." minutes, "..tostring( run.s ).." seconds" )
table.insert( tFile, 1, "%section%[Info]" )
table.insert( tFile, 1, "--"..name.." was run")
else
if programProperties[3] then
tFile[3] = "runtime="..tostring( run.d ).." days, "..tostring( run.h ).." hours, "..tostring( run.m ).." minutes, "..tostring( run.s ).." seconds"
tFile[4] = "times run="..( type( tonumber( string.split( tFile[4], " = " )[2]) ) == "number" and tostring( tonumber( string.split( tFile[4], " = " )[2])+1 ) or "1" )
else
tFile[3] = "runtime=enable in properties"
tFile[4] = "times run=enable in properties"
end
end
oldTFile = tFile
tFile = {}
for i = 1,#oldTFile do
if oldTFile[i] ~= "%section%[Program Log]" then
table.insert( tFile, oldTFile[i] )
else
break
end
end
if programProperties[1] == true then
tFile = log.save( tFile )
end
k = fs.open( name, "w" )
for i = 1,#tFile do
k.writeLine( tFile[i] )
end
k.close( )
return true
end

function timer( )
local s = 0
local m = 0
local h = 0
local d = 0
local ms = 0
while true do
ms = ms+1
if ms >= 10 then
ms = 0
s = s+1
end
if s >= 60 then
s = 0
m = m+1
end
if m >= 60 then
m = 0
h = h+1
end
if h >= 24 then
h = 0
d = d+1
end
run.s = s
run.m = m
run.h = h
run.d = d
sleep( 0.1 )
end
end

function event( )
while true do
ev = { os.pullEvent( "mouse_click" ) }
if ev[2] == 2 and ev[3] == 51 and ev[4] == 19 then
draw = true
elseif ev[2] == 1 and ev[3] == 51 and ev[4] == 18 and draw == true then
os.queueEvent( "terminate" )
elseif draw == true then
draw = false
end
end
end

oldTerm = { }

oldTerm.write = _G["term"]["write"]
oldTerm.setCursorPos = _G["term"]["setCursorPos"]
oldTerm.clear = _G["term"]["clear"]
oldTerm.setBackgroundColour = _G["term"]["setBackgroundColour"]
oldTerm.setTextColour = _G["term"]["setTextColour"]
olderror = _G["error"]
log.add( "System", "rewriting term library" )
function error(...)
local arg = { ... }
log.add("Error", unpack( arg ) )
end
function term.write( ... )
local arg = { ... }
x, y = term.getCursorPos( )
log.add( "Screen", "wrote", unpack( arg ), "at", x, y )
oldTerm.write( unpack( arg ) )
oldTerm.setCursorPos( 51, 19 )
oldTerm.write( "^" )
oldTerm.setCursorPos(x,y)
oldTerm.write(unpack( arg ))
if draw then
oldTerm.setCursorPos( 50, 18 )
oldTerm.write( "_X" )
end
end

function term.clear( )
log.add( "Screen", "cleared")
oldTerm.clear( )
end

function term.setCursorPos( x, y )
log.add( "Screen", "Set cursor pos to", x, y )
oldTerm.setCursorPos( x, y )
end

run = { }
draw = false

runProg = function( )
try( "shell.run", shell.run, name, unpack( args ) )
end

k = fs.open( name, "r" )
t = { }
m = k.readLine( )
while m do
table.insert( t, m )
m = k.readLine( )
end
k.close()

if runType == "run" then
getProperties( t )
log.add( "System", "Running program" )
parallel.waitForAny( runProg, timer, event )
insertInformation( t )
end

term.write = oldTerm.write
term.clear = oldTerm.clear
term.setCursorPos = oldTerm.setCursorPos
error = olderror
if runType == "log" then
m = { }
isInLog = false
for i = 1,#t do
if isInLog then
table.insert( m, t[i] )
end
if t[i] == "%section%[Program Log]" then
isInLog = true
end
end
table.remove( m, #m )
term.clear( )
term.setCursorPos( 1, 1 )
y = 1
for i = 1,#m do
term.write( m[i] )
y = y+1
term.setCursorPos( 1, y )
end
end
tables = {}
tables["Info"] = "info"
tables["Properties"] = "ps"
tables["Code"] = "code"
tables["Program Log"] = "plog"
info = {}
ps = {}
code = {}
plog = {}
function compare(str)
result = false
for k, v in pairs(tables) do
if str=="%section%["..k.."]" then
result = v
end
end
return result
end
function header(str)
print("")
x, y = term.getCursorPos()
paintutils.drawLine(x, y, #str, y, colors.green)
print(str)
print("")
end
function addto(str, v)
if v=="info" then table.insert(info, str) end
if v=="ps" then table.insert(ps, str) end
if v=="code" then table.insert(code, str) end
if v=="plog" then table.insert(plog, str) end
end
if runType == "clear" then
oldTFile = t
tFile = { }
for i = 1,#oldTFile do
if oldTFile[i] ~= "%section%[Program Log]" then
table.insert( tFile, oldTFile[i] )
else
break
end
end
while tFile[1] ~= "%section%[Code]" do
table.remove( tFile, 1 )
end
table.remove( tFile, 1 )
k = fs.open( name, "w" )
for i = 1,#tFile do
k.writeLine( tFile[i] )
end
k.close( )
end
if runType == "view" then
local file = {}
local handle = io.open(name, "r")
if handle then
 for line in handle:lines() do
     table.insert(file, line)
   end
else
 error("Could not open file!")
end
handle:close()
fileload = {}
for i=1, #file do
v = compare(file[i])
if not v then
afsdfsfs="lsdksfksfs"
else
actual = v
for o=i, #file do
d = compare(file[o])
if not d then
addto(file[o], actual)
else
actual = d
end
end
end
end
print("info")
for i=1, #info do
os.pullEvent("key")
print(info[i])
end
sleep(3)
term.clear()
print("ps")
for o=1, #ps do
os.pullEvent("key")
print(ps[o])
end
sleep(3)
term.clear()
print("code")
for e=1, #code do
os.pullEvent("key")
print(code[e])
end
sleep(3)
term.clear()
print("plog")
for u=1, #plog do
os.pullEvent("key")
print(plog[u])
end
end
info is displayed 1 time
ps is displayed two times
code is displayed 3 times
and plog is displayed 4 times

I dont understand why
theoriginalbit #38
Posted 20 February 2013 - 09:56 AM
- code snip -
info is displayed 1 time
ps is displayed two times
code is displayed 3 times
and plog is displayed 4 times

I dont understand why
Well I'm getting each once, I think. seems to only be once.
FuuuAInfiniteLoop(F.A.I.L) #39
Posted 20 February 2013 - 09:59 AM
- code snip -
info is displayed 1 time
ps is displayed two times
code is displayed 3 times
and plog is displayed 4 times

I dont understand why
Well I'm getting each once, I think. seems to only be once.
running the ode, if you see, it display more times
theoriginalbit #40
Posted 20 February 2013 - 10:01 AM
running the ode, if you see, it display more times
ode? im assuming you mean code…….. and I did run the code. I wouldn't have replied that I was getting it only once (I think) if I hadn't run it.
FuuuAInfiniteLoop(F.A.I.L) #41
Posted 20 February 2013 - 10:01 AM
I have tested a little and i found that the repetition are in the table
theoriginalbit #42
Posted 20 February 2013 - 10:02 AM
I have tested a little and i found that the repetition are in the table
Oh you meant what it printed was showing multiple times. I thought you meant the screens. this is why clarity is important!
FuuuAInfiniteLoop(F.A.I.L) #43
Posted 20 February 2013 - 10:06 AM
repaired, I have replaced a for loop

back to coding
FuuuAInfiniteLoop(F.A.I.L) #44
Posted 20 February 2013 - 10:35 AM
Program rewrited
theoriginalbit #45
Posted 20 February 2013 - 10:40 AM
SOLVED look at my signature
What am I looking for exactly?
LBPHacker #46
Posted 20 February 2013 - 06:05 PM
Oh my God, this is not gonna end…

What am I looking for exactly?
You're looking for this, I suppose.

He got some "nice" comments already…