Jump to content




[CC]Code Cleanup


170 replies to this topic

#1 SuicidalSTDz

    Permutator of Strings

  • Members
  • 1,308 posts
  • LocationPennsylvania

Posted 28 February 2013 - 09:38 AM

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.


#2 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,462 posts

Posted 28 February 2013 - 11:08 AM

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

#3 SuicidalSTDz

    Permutator of Strings

  • Members
  • 1,308 posts
  • LocationPennsylvania

Posted 28 February 2013 - 11:10 AM

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.

#4 FuuuAInfiniteLoop(F.A.I.L)

  • Banned
  • 435 posts
  • LocationThe left part of this post

Posted 28 February 2013 - 11:16 AM

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


#5 CastleMan2000

  • Members
  • 195 posts
  • LocationThe trashcan where all Undertale trash is

Posted 28 February 2013 - 11:30 AM

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!)


#6 SuicidalSTDz

    Permutator of Strings

  • Members
  • 1,308 posts
  • LocationPennsylvania

Posted 28 February 2013 - 02:11 PM

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


#7 GravityScore

  • Members
  • 796 posts
  • LocationLand of Meh

Posted 01 March 2013 - 04:51 AM

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


#8 CastleMan2000

  • Members
  • 195 posts
  • LocationThe trashcan where all Undertale trash is

Posted 01 March 2013 - 05:04 AM

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)


#9 1lann

  • Members
  • 516 posts
  • LocationAustralia

Posted 01 March 2013 - 05:10 AM

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


#10 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 01 March 2013 - 05:16 AM

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!')


#11 Tiin57

    Java Lunatic

  • Members
  • 1,412 posts
  • LocationIndiana, United States

Posted 01 March 2013 - 05:51 AM

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 [email protected] {
public static void Main(String[] args) {
System.out.println("Hello")
}
}
Take that.

#12 CastleMan2000

  • Members
  • 195 posts
  • LocationThe trashcan where all Undertale trash is

Posted 01 March 2013 - 05:55 AM

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 [email protected] {
public static void Main(String[] args) {
System.out.println("Hello")
}
}
Take that.

Is that java? I don't know java.

#13 SuicidalSTDz

    Permutator of Strings

  • Members
  • 1,308 posts
  • LocationPennsylvania

Posted 01 March 2013 - 09:11 AM

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 ;)

#14 CastleMan2000

  • Members
  • 195 posts
  • LocationThe trashcan where all Undertale trash is

Posted 01 March 2013 - 10:22 AM

Print(oh hi/hey there!


#15 Dlcruz129

    What's a Lua?

  • Members
  • 1,423 posts

Posted 01 March 2013 - 01:00 PM

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


#16 1lann

  • Members
  • 516 posts
  • LocationAustralia

Posted 01 March 2013 - 01:29 PM

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


#17 Mads

  • Members
  • 604 posts
  • LocationCopenhagen, Denmark

Posted 02 March 2013 - 03:09 AM

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;


#18 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 02 March 2013 - 03:18 AM

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


#19 ardera

  • Members
  • 503 posts
  • LocationGermany

Posted 02 March 2013 - 03:40 AM

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)


#20 Shnupbups

  • Members
  • 596 posts
  • LocationThat place over there. Y'know. The one where I am.

Posted 03 March 2013 - 06:26 PM

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.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users