←  Forum Games

ComputerCraft | Programmable Computers for Minecraft

»

[CC]Code Cleanup

SuicidalSTDz's Photo SuicidalSTDz 28 Feb 2013

Code Cleanup:

The aim of the game is quite simple, as are the rules. This game is intended for fun and as a way to learn about error handling. This is not a place to post code that you are stumped on, that is why there is an Ask A Pro section. I hope you all learn something new from this and have fun too!


Your Objective!
- Post a functioncal replica of the code/script from the person before you, also state what the error was
- Post a max of 15 lines of code that will error (Not all lines have to error)

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!

Os.reboot()

SuicidalSTDz
Corrected:
os.reboot()
Lua is case sensitive, Os.reboot() should be os.reboot()

line = read()
local c = string.Len(line)
print(C)

Edited by SuicidalSTDz, 28 July 2014 - 01:28 AM.
Quote

Lyqyd's Photo Lyqyd 28 Feb 2013

I'll allow it, but I think between 3 and 15 lines is probably more reasonable.
Quote

SuicidalSTDz's Photo SuicidalSTDz 28 Feb 2013

View PostLyqyd, on 28 February 2013 - 11:08 AM, said:

I'll allow it, but I think between 3 and 15 lines is probably more reasonable.
Yeah, does sound better. Wasn't sure how many max lines for length sake.
Quote

FuuuAInfiniteLoop(F.A.I.L)'s Photo FuuuAInfiniteLoop(F.A.I.L) 28 Feb 2013

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

Code Cleanup:

The aim of the game is quite simple, as are the rules. This game is intended for fun and a way to learn handling errors. New CC Members, or old, may play this game and learn some simple errors that can cause an entire script to fail. This is not a place to post code that you are stumped on, that is why there is an Ask A Pro section. I hope you all learn something new from this and have fun too.


What do I do?
-Post a "revamp" of the code from the person before you, also state what the error was
-Post a max of 15 lines of code that will error (Not all lines have to error)

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
-Be creative. Get your thinking caps on!
-If any code is longer than 8 lines, you will be skipped
-If any code is not in "code" format, you will be skipped
-Indent your code


Os.reboot()

SuicidalSTDz:
Corrected:
os.reboot()
Lua is case sensitive, Os.reboot() should be os.reboot()

line = read()
local c = string.Len(line)
print(C)

line = read()
print(#line)
Error line 2 string.Len doesnt exist, string.len do

cleared the code

a = fs.list("/rom")
for k, v in a do
	  print(k)
end
Quote

CastleMan2000's Photo CastleMan2000 28 Feb 2013

a = fs.list("/rom")
for k, v in pairs(a) do
		  print(v)
end
FTFY. You need to iterate through the files.

red = colors.red()
blue = colors.blue()
green = colors.green()
Term.setbackgroundcolor(red)
Term.setcolor(blue)
print(Hello!)
Quote

SuicidalSTDz's Photo SuicidalSTDz 28 Feb 2013

red = colors.red
blue = colors.blue
green = colors.green
term.setBackgroundColor(red)
term.setTextcolor(blue)
print("Hello!")
Remove the parenthesis (Do not have to indicate a call on a paramater)
Lua is case sensitive; term.setBackgroundColor() and term.setTextColor()
"Forgot" to add "Text" in term.setTextColor()
Quotations for print()
Pretty sure that's all ;)

line = io.read()
data = {(line)}
for i = 1,100
  table.Insert(data line)
end
for k,v in pairs(Data) do
  print(v)
end
Quote

GravityScore's Photo GravityScore 01 Mar 2013

View PostSuicidalSTDz, on 28 February 2013 - 02:11 PM, said:

line = io.read()
data = {(line)}
for i = 1,100
  table.Insert(data line)
end
for k,v in pairs(Data) do
  print(v)
end

line = read()
data = {line}
for i = 1, 100 do
  table.insert(data, line)
end

for k, v in pairs(data) do
  print(v)
end

Just use read() for CC, not io.read()
No parenthesis needed for converting to an array
Missing do.
Needed comma in table.insert.
Lua is case sensitive. table.insert, not table.Insert
Lua is case sensitive. data, not Data

EDIT: whoops, forgot my own error code:

for i, 20 do
  print("MUFFINS)
end

trem.setCursroPos(1, "3")
term.write('hello!")

x == 1
while True do
  print(x)
  if x => 10 then break end
  x += 1
end
end
Quote

CastleMan2000's Photo CastleMan2000 01 Mar 2013

for i, 20 do
  print("MUFFINS")
end

term.setCursorPos(1, 3)
term.write("hello!")

x = 1
while true do
  print(x)
  if x => 10 then
    break
  end
  x = x + 1
end
end

FTFY. You forgot a quote, mismatched a quote, incorrectly defined a variable, did it again and capitalized true.

function = waffle(x y)
  waffle = 2
  pancake = waffle + x X y
  returd (waffle)
end function
waffle(3. 2)
Quote

1lann's Photo 1lann 01 Mar 2013

You missed the for i = 1, 20 do on the first line. He didn't put a = 1
Also => isn't valid, it needs to be >=


Fix for yours:
function = waffle(x, y)
  waffleAmount = 2
  pancake = waffleAmount + x*y
  return waffle -- Seems strange, probably return pancake
end
waffle(3, 2)

Problems:
Overriding variables
incorrect way to end a function
x X y - I assume you mean x*y

Here's my broken code

print('I like trains')
if (http) {
  System.out.println("HTTP API is present');
else {
  printf("No http! D:
}
pcall(print("THIS CANNOT "CRASH"! (Almost)"))
for k,v in term do
print(k)
end
Quote

Kingdaro's Photo Kingdaro 01 Mar 2013

For some reason I feel as though this thread was created for the sole purpose of making me cringe.

But anyway,
print('I like trains')
if (http) then
  print('HTTP API is present');
else
  print("No http! D:")
end
pcall(function() print("THIS CANNOT \"CRASH\"! (Almost)") end)
for k,v in pairs(term) do
print(k)
end

Replaced { with then and } with end.
There is no System.out.println.
Replaced double quote with single.
There is no printf.
Added double quotes and a right bracket.
Passed a function to pcall instead of a function call.
Escaped quotes.
Passed function to for statement instead of table.

My tuuuuurn.

def hello():
  for i in range(0,20):
    print('Hello,')
  for i in range(0,20):
    print('World!')
Quote

Tiin57's Photo Tiin57 01 Mar 2013

Quote

def hello():
  for i in range(0,20):
    print('Hello,')
  for i in range(0,20):
    print('World!')
What
I don't even
IT'S NOT EVEN LUA.
public class Hello@World {
public static void Main(String[] args) {
System.out.println("Hello")
}
}
Take that.
Quote

CastleMan2000's Photo CastleMan2000 01 Mar 2013

View Posttiin57, on 01 March 2013 - 05:51 AM, said:

Quote

def hello():
  for i in range(0,20):
	print('Hello,')
  for i in range(0,20):
	print('World!')
What
I don't even
IT'S NOT EVEN LUA.
public class Hello@World {
public static void Main(String[] args) {
System.out.println("Hello")
}
}
Take that.

Is that java? I don't know java.
Quote

SuicidalSTDz's Photo SuicidalSTDz 01 Mar 2013

Hmm, let's stick with Lua. Whoever want's to start off again, go for it. (Not relevant, but my cat is licking me as I type this post)

EDIT: I am, however, glad to see some creativity ;)
Quote

CastleMan2000's Photo CastleMan2000 01 Mar 2013

Print(oh hi/hey there!
Quote

Dlcruz129's Photo Dlcruz129 01 Mar 2013

View PostCastleMan2000, on 01 March 2013 - 10:22 AM, said:

Print(oh hi/hey there!

print("oh hi/hey there!")
Lowercase
Quotation marks
End parenthesis

yo computer I need you to like say wut yo name to the guy and then if the guys name is Jim you gotta open dat door. Kthxbai
Quote

1lann's Photo 1lann 01 Mar 2013

Kingdaro:
for i = 1, 20 do print("Hello,") end
for i = 1, 20 do print("World!") end
tiin57:
function main(...)
  print("Hello")
end
main()
Dlcruz:
name = "Dlcruz"
while true do
print("What is your name?")
if read() == name then
for k,v in pairs(rs.getSides()) do rs.setOutput(v, true) end
sleep(3)
for k,v in pairs(rs.getSides()) do rs.setOutput(v, false) end
else
print("Go away!")
end
end

My broken code:
while true do
  for i = 1, 1000
  print("IM SOOO DIGHGEEN BORED")
  bordem = bordem+1
  if bordem < 9000 then print("BORDEM LEVEL OVER 9000!") end
  end
sleep(0.1)
end
Quote

Mads's Photo Mads 02 Mar 2013

while true do
    for i = 1, 1000 do
[...]

Broken code:

std::ifstream in(argv[1]);

in.seekg (0, std.ios::end);
int length = in->tellg();
in.seekg (0, std.ios::beg);

int pos = new int[10];
pos = length - &(in.seegk(0, std::ios::binary);
std::cout << *pos << std::endl;
Quote

Kingdaro's Photo Kingdaro 02 Mar 2013

fs.delete 'nonLuaProgram'

Should fix it up quite nicely.

Broken code:

function loop
  i is 0
  print i and increment i until i is 10

do loop
Quote

ardera's Photo ardera 02 Mar 2013

View PostKingdaro, on 02 March 2013 - 03:18 AM, said:

fs.delete 'nonLuaProgram'

Should fix it up quite nicely.

Broken code:

function loop
  i is 0
  print i and increment i until i is 10

do loop
function loop()
  i=0
  for i=i, 10 do

    print(i)
  end
end
loop()

my broken code:
function write(txt) do
  term:write(tyt)
end
write(tyt)
Quote

Shnupbups's Photo Shnupbups 03 Mar 2013

View Postardera, on 02 March 2013 - 03:40 AM, said:

function write(txt) do
  term:write(tyt)
end
write(tyt)
function write(txt)
  term.write(txt)
end
write("txt")
* No do is used for function
* tyt hasn't been defined
* Again, tyt hasn't been defined, so I put a small string

My code:
pie == "apple"
funtion pie{apples}
  if apples = pie do
   print i like apple pie
  wrong do
   print i do not like that pie you gave me i want applez
end
pieType is input
pie(pieType)
Lol I tried to break it as much as possible.
Quote