Jump to content




[CC]Code Cleanup


  • You cannot reply to this topic
170 replies to this topic

#121 Konlab

  • Members
  • 595 posts
  • LocationKerbin

Posted 29 May 2014 - 09:32 AM

View Postcptdeath58, on 29 May 2014 - 01:35 AM, said:

line 2
for amount, v in ipairs(self:gsub(%a*%.+%w*%a+) do
Unexpected symbol?


--Read this
os.pullEvent() = os.pullEventRaw()
read = fs.open( "programs/Hello" )
if read then
 Cookies = read.readLine()
 read.close()
end
term.clear
term.setCursorPos(1,1)
term.write( "I have "..Cookies" in my cookie jar!" )
Jarhead() LOL
end

Error #1: attempt to call nil:the solution: os.pullEvent = os.pullEventRaw
Error#2: "=" expexted solution: term.clear() instead of term.clear
Error#3: <eof> expected: there is an 'end' at end of program, you must remove that
Error#4: "=" expected: remove 'Lol' from code or comment it --Lol
Error#5: I dont know what is Jarhead()

And another error: = expected: solution: ..Cookies.. Instead of ..Cookies

#122 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 01 June 2014 - 11:54 AM

View Posttheoriginalbit, on 29 May 2014 - 03:16 AM, said:

My challenge (20 problems)


#123 Lua.is.the.best

  • Members
  • 76 posts

Posted 23 June 2014 - 02:40 AM

fs.delete("tooLong")
Should be good!
print(''Hi there!'')
local hi == "hi"
for i and v in 100 then
print''Loaded '' .. i .. ''%''
end
end
Good luck!

#124 H4X0RZ

  • Members
  • 1,315 posts
  • LocationGermany

Posted 23 June 2014 - 01:32 PM

print('Hi there!')
local hi == "hi"
for i =1,100,1 do
print('Loaded ' .. i .. '%')
end
end
Should work :D

local function Main(...)
  local args  = {..)
  for k,v in pair(args) doo
	printt(v)
  end
  print("Total amount of args:''.. ##args)
end
main("t","e","s'',''t"
Take that! :D

Edited by Freack100, 23 June 2014 - 01:33 PM.


#125 cptdeath58

  • Members
  • 139 posts
  • LocationError 404: Could not find.

Posted 23 June 2014 - 10:25 PM

Line 3: "doo" needs to be "do"
Line 4: "printt" needs to be "print"
print("Total amount of args:'' ..##args)
needs to be
print("Total amount of args:" ..#args)
Line 8: End Parenthesis (or Brackets if you live in those certain areas) and
"s'',''t"
needs to be
"s","t"

Fix this:
function start()
wile true doo
  term.stCursorPos(1,1)
  term.write("Hello'')
  x = "x" + 1
until "x" == 10
end

Edited by cptdeath58, 25 June 2014 - 09:31 PM.


#126 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 24 June 2014 - 02:21 PM

function start()
 do
  term.setCursorPos(1, 1)
  term.write("Hello")
  x = x + 1
 until x == 10
end

even better

Fix this:
local wait = fumction()
 local event = os.pullEvent( "modem_message" )
 print( message[5] )
end
local send = funclion()
 local stuff = read()
 modem.transnit( 10, 10, stuff )
end
local csend, cwait = corutine.create( send ), corutine.create( wait )
while true do
 coroutine.resume( csend, event )
 coroutine.resume( cwait, event )
 event = { os.pullEvent() }
end


#127 Carrots084

  • Members
  • 46 posts

Posted 30 June 2014 - 12:50 AM

To fix the last code ==
local wait = function()
local event = os.pullEvent( "modem_message" )
print( message[5] )
end
local send = function()
local stuff = read()
modem.transmit( 10, 10, stuff )
end
local csend, cwait = coroutine.create( send ), coroutine.create( wait )
while true do
coroutine.resume( csend, event )
coroutine.resume( cwait, event )
event = { os.pullEvent() }
end

My code:
prnit("What did you name this file(case sensitive)?")
local name= io.read()
shell.rnu("delete "..file)
print("Go ahead and reinstall it ;)/>/>")

Edited by Carrots084, 30 June 2014 - 12:51 AM.


#128 Saldor010

  • Members
  • 467 posts
  • LocationThe United States

Posted 01 July 2014 - 03:01 AM

View PostCarrots084, on 30 June 2014 - 12:50 AM, said:

To fix the last code ==
local wait = function()
local event = os.pullEvent( "modem_message" )
print( message[5] )
end
local send = function()
local stuff = read()
modem.transmit( 10, 10, stuff )
end
local csend, cwait = coroutine.create( send ), coroutine.create( wait )
while true do
coroutine.resume( csend, event )
coroutine.resume( cwait, event )
event = { os.pullEvent() }
end

My code:
prnit("What did you name this file(case sensitive)?")
local name= io.read()
shell.rnu("delete "..file)
print("Go ahead and reinstall it ;)/>/>/>/>/>/>")

First line : Mispelled "print", other then that, it should work.
Second line : You need to have a space in between "name" and the equals sign, and you gave no parameter for io.read() to read from. I don't know much about the io library, so I can't help you much with this one.
Third line: Mispelled "shell.run", there is no variable called "file", I think you meant "name".
Fourth line: Looks good to me.

All in all, here is your corrected code.

print("What did you name this file(case sensitive)?")
local name = "LOL, IDK HOW TO USE THE IO LIBRARY" --io.read()
shell.run("delete "..name)
print("Go ahead and reinstall it ;)/>/>/>/>/>/>")

Now for my screwed up code.

printt("Hi! This is my program! Hope you like it!")
function Test(mister wiggles, wuv
   while true
     drawPixel(9,9,blue)
   end
end
Test(twelve,nein)

Edited by Jiloacom, 01 July 2014 - 03:04 AM.


#129 cptdeath58

  • Members
  • 139 posts
  • LocationError 404: Could not find.

Posted 02 July 2014 - 09:42 PM

This should help
print( "Hi! This is my program! Hope you like it!")
function Test(no,wuv)
 while true do
  drawPixel(9,9,colours.blue)
 end
end
Test(12,9)
--or
Test("Twelve","Nein")

Now for my mess
function no(
 while true do
  print(no)
  print("no)
  print("no)
  print("How about...)
  print("no")
 end
end

no(


#130 Saldor010

  • Members
  • 467 posts
  • LocationThe United States

Posted 03 July 2014 - 02:09 PM

View Postcptdeath58, on 02 July 2014 - 09:42 PM, said:

This should help
print( "Hi! This is my program! Hope you like it!")
function Test(no,wuv)
while true do
  drawPixel(9,9,colours.blue)
end
end
Test(12,9)
--or
Test("Twelve","Nein")

You failed to explain what bugs I had in the code, and you also forgot a bug on the 4th line.

Edited by Jiloacom, 03 July 2014 - 02:10 PM.


#131 Lua.is.the.best

  • Members
  • 76 posts

Posted 05 July 2014 - 10:43 PM

View Postcptdeath58, on 02 July 2014 - 09:42 PM, said:

Now for my mess
function no(
while true do
  print(no)
  print("no)
  print("no)
  print("How about...)
  print("no")
end
end

no(
function no()
while true do
  print("no")
  print("no")
  print("no")
  print("How about...")
  print("no")
end
end

no()
Line 1 & 12: ( should be ()
Line 4: Put it in a set of quotes.
Line 5-7: You didn't end the strings.

Fix 2:
print("Hi! This is my program! Hope you like it!")
function Test(no,wuv)
while true do
  paintutils.drawPixel(9,9,colours.blue)
end
end
Test(12,9)
drawPixel is part of the paintutils API, so you put paintutils.drawPixel
drawPixel does not support strings, but it supports numbers (or if you want to call them that, integers).
Edit: Is this a bug, or did he put that space there?
Edit 2: The arguments no and wuv on function Test aren't being used, is that intentional?
Edit 3: Forgot code
Edit 4: LOL, the size tags decided to sneak into my code..
table == {1,2}
for k and v in table then
  print(table(k))
end
function hi
  for i==1,51 then
	while i>>25 then
	  print i
	end
  end
end
hi

Edited by Lua.is.the.best, 10 July 2014 - 01:23 AM.


#132 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 10 July 2014 - 03:03 PM

local table = {1, 2} --#forgot localization
for k, v in pairs( table ) do --# replace and with ",", added pairs, replaced then with do
  print( v ) --#it looks like you want to print the variable from your code
end
function hi() --#need ()
  for i = 1, 51 do --#don't compare i, do instead of then
    if i > 25 then  --#get rid of while loop, use if statement instead.  fixed comparison as well
      print( i )
    end
 end
end
hi() --#calling a function needs ()

function derp( string )
  for word in pairs( string:gmatch( "[^/n/ra]+" ) do
   term.setTextColor(  2 ^ math.floor( math.random( 0, 16 ) )
   term.write( word,." " )
  end
end
function randomString( len )
 local result = "'
 for i = 1, len do
  result = result + string.char( math.random( 1, 128 ) )
 end
 return result
end
local str
for i = 1, 10 do
 str = str + " "..randomString( math.random( 1, 10 )
end
derp( str )


#133 Lua.is.the.best

  • Members
  • 76 posts

Posted 20 July 2014 - 04:13 PM

18 lines! Skipped.
Anyways:
function hi a,b,c
  print Hi..a..b..c
end
hi " ","Hello ","World!"
for i in 1,100 do
  hi i, "Hello " , "World!"
end


#134 computercraftprogrammer

  • Members
  • 122 posts
  • Location$house->Earth->MilkyWay->Universe;

Posted 21 July 2014 - 08:14 PM

Attempt to call nil "Hi"

p={1,2,3,4,7,2,532,3,581,2,,76233} c=1 for i,v in pairs(p) do print(i+v-x) c=i+v end if c == 34 then io.read("What do?) elseif c==32 then print(''Hello") end


#135 Carrots084

  • Members
  • 46 posts

Posted 27 July 2014 - 06:11 PM

View PostJiloacom, on 01 July 2014 - 03:01 AM, said:

View PostCarrots084, on 30 June 2014 - 12:50 AM, said:

-snip-

io.read() runs exactly like read() read() is just a shortened version.

To UMayBleed: not even gonna fix your code. format it

Edited by Carrots084, 27 July 2014 - 06:13 PM.


#136 SuicidalSTDz

    Permutator of Strings

  • Members
  • 1,308 posts
  • LocationPennsylvania

Posted 28 July 2014 - 01:30 AM

Cleaned up the main post. To go along with it, here is a reminder of the rules. Please follow them.

View PostSuicidalSTDz, on 28 February 2013 - 09:38 AM, said:

What are the rules?
- Follow forum guidelines as always
- Do not post malicious code
- Do not post code that does not error -- you will be skipped
- Do not post code that someone has already posted -- you will be skipped
- If any script is longer than 15 lines -- you will be skipped
- If any code is not in code format -- you will be skipped
- Indent your code
- If a script posted is not in Lua format -- you will be skipped
If the previous user's code does not fall under the above criteria then find a nice/constructive way to terminate it!

It's also nice to see this game take rise :)

#137 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 28 July 2014 - 02:27 AM

Because there doesn't seem to be any code to fix..

local function log( api, key, ... )
  local file = fs.open( "log", "a" )
  file.writeLine( "["..os.time().."]".."["..api.."]: "..key.."( ".. textutils.serialize( { ... } )..")"
  file.close()
end
for k, v in pairs( _G ) do
 if type( v ) == "table" and v ~= _G then
  for x, y in pairs( v ) do
   if type( y ) == "function" then
   _G[k][x] = function( .., ) y( ... ) log( k, x, ... ) end
   end
  end
 end
end


#138 Dog

  • Members
  • 1,179 posts
  • LocationEarth orbit

Posted 02 March 2015 - 06:08 PM

Because this thread hasn't seen any lovin' in awhile...

View PostKingofGamesYami, on 28 July 2014 - 02:27 AM, said:

Because there doesn't seem to be any code to fix..

local function log( api, key, ... )
  local file = fs.open( "log", "a" )
  file.writeLine( "["..os.time().."]".."["..api.."]: "..key.."( ".. textutils.serialize( { ... } )..")"
  file.close()
end
for k, v in pairs( _G ) do
if type( v ) == "table" and v ~= _G then
  for x, y in pairs( v ) do
   if type( y ) == "function" then
   _G[k][x] = function( .., ) y( ... ) log( k, x, ... ) end
   end
  end
end
end

Not sure about the rest, but I think I found two problems - you missed a closing bracket on line 3 and had a comma instead of a period on line 10...
local function log( api, key, ... )
  local file = fs.open( "log", "a" )
  file.writeLine( "["..os.time().."]".."["..api.."]: "..key.."( ".. textutils.serialize( { ... } )..")")
  file.close()
end
for k, v in pairs( _G ) do
if type( v ) == "table" and v ~= _G then
  for x, y in pairs( v ) do
   if type( y ) == "function" then
   _G[k][x] = function( ... ) y( ... ) log( k, x, ... ) end
   end
  end
end
end


#139 Lupus590

  • Members
  • 2,028 posts
  • LocationUK

Posted 02 March 2015 - 06:47 PM

you forgot your own 'bugged' code

#140 Dog

  • Members
  • 1,179 posts
  • LocationEarth orbit

Posted 02 March 2015 - 08:26 PM

Good point :)
local mon = perihperal.find(monitor)
term.setTextColor(type(mon) == "table" and colors.green or colors.red)
term.write(type(mon) == "table" and "Monitor found" or "No monitor found")
if type(mon) == "table" then mon.write("Hello World!")






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users