Jump to content




[CC]Code Cleanup


170 replies to this topic

#21 Dlcruz129

    What's a Lua?

  • Members
  • 1,423 posts

Posted 03 March 2013 - 06:54 PM

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)

favPie = "apples"
function pie(apples)
  if apples == favPie then
   print ("i like apple pie")
  else
   print ("i do not like that pie you gave me i want applez")
end
pieType = read()
pie(pieType)

Not even gonna bother listing every single thing I did here.

Edit: forgot code:
army = turtle.craftTurtleArmy()
army.kill(players.all)

Good luck. ;)

#22 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 03 March 2013 - 07:04 PM

View PostDlcruz129, on 03 March 2013 - 06:54 PM, said:

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)

favPie = "apples"
function pie(apples)
  if apples == favPie then
   print ("i like apple pie")
  else
   print ("i do not like that pie you gave me i want applez")
end
pieType = read()
pie(pieType)

Not even gonna bother listing every single thing I did here.
Where is your code?

Also, ternary statements FTW!
function pie(apples) then
  print( apples == favPie and "i like apple pie" or "i do not like that pie you gave me i want applez" )
end


#23 Dlcruz129

    What's a Lua?

  • Members
  • 1,423 posts

Posted 03 March 2013 - 07:08 PM

View PostTheOriginalBIT, on 03 March 2013 - 07:04 PM, said:

View PostDlcruz129, on 03 March 2013 - 06:54 PM, said:

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)

favPie = "apples"
function pie(apples)
  if apples == favPie then
   print ("i like apple pie")
  else
   print ("i do not like that pie you gave me i want applez")
end
pieType = read()
pie(pieType)

Not even gonna bother listing every single thing I did here.
Where is your code?

Also, ternary statements FTW!
function pie(apples) then
  print( apples == favPie and "i like apple pie" or "i do not like that pie you gave me i want applez" )
end

Whoops. Added code.

#24 Tiin57

    Java Lunatic

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

Posted 04 March 2013 - 08:54 AM

View PostDlcruz129, on 03 March 2013 - 06:54 PM, said:

army = turtle.craftTurtleArmy()
army.kill(players.all)
Um...
turtle = os.getTurtle()
players = server.getPlayers()
army = turtle:craftTurtleArmy()
for i=1, #players:all do
army:kill(players[i])
end
Mine:
print(Hi guys);
global x = read("?")
print("x")


#25 Dlcruz129

    What's a Lua?

  • Members
  • 1,423 posts

Posted 04 March 2013 - 09:35 AM

View Posttiin57, on 04 March 2013 - 08:54 AM, said:

print(Hi guys);
global x = read("?")
print("x")

print("Hi guys")
x = read("?")
print(x)

Edit: Damn, why do I always forget code?
for i=1,10 in pairs() do
  print("i")


#26 Tiin57

    Java Lunatic

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

Posted 04 March 2013 - 09:42 AM

You need code.

#27 MudkipTheEpic

  • Members
  • 639 posts
  • LocationWhere you'd least expect it.

Posted 04 March 2013 - 11:04 AM

View PostDlcruz129, on 04 March 2013 - 09:35 AM, said:

View Posttiin57, on 04 March 2013 - 08:54 AM, said:

print(Hi guys);
global x = read("?")
print("x")

print("Hi guys")
x = read("?")
print(x)

Edit: Damn, why do I always forget code?
for i=1,10 in pairs() do
  print("i")

for i=1,10  do
  print(i)
end

You don't need in pairs.

No quotation marks around a value.

Needs an end for the for loop.

for #=10, 1 true do
term.print(number)
if number = 3 do
term.textColr("blue")
term.slowPrint(Oh my Gosh It's 3!!)

Edit: I guess nobody wants their head to explode trying to decipher my fail code... :( ( :P )

Edited by MudkipTheEpic, 04 March 2013 - 12:30 PM.


#28 SuicidalSTDz

    Permutator of Strings

  • Members
  • 1,308 posts
  • LocationPennsylvania

Posted 04 March 2013 - 03:07 PM

New Rule:

If the above users code does not fit criteria of the other rules, find a nice/constructive way to terminate it!


Side Note: Keep up the creativity, i'm loving all of these errors :D


(Wish someone would make some code that returns an outOfBoundsException or Too long without yielding, as these are common problems while looping :P)



#29 Mailmanq!

  • Members
  • 123 posts
  • LocationI am omnipresent... DUH

Posted 04 March 2013 - 03:11 PM

View PostMudkipTheEpic, on 04 March 2013 - 11:04 AM, said:

for #=10, 1 true do
term.print(number)
if number = 3 do
term.textColr("blue")
term.slowPrint(Oh my Gosh It's 3!!)

for i = 1, 10 do 
  term.write(i)
  if i == 3 then
     term.setTextColor(colors.blue)
     textutils.slowPrint("Oh my gosh, it's a 3!!")
  end
end

hello = "hello"
hello = string.gmatch(hello, ".")
for k, v inpairs(hello) do
   o.s.qevent("char", "v")
end


#30 SuicidalSTDz

    Permutator of Strings

  • Members
  • 1,308 posts
  • LocationPennsylvania

Posted 05 March 2013 - 08:21 PM

View PostDlcruz129, on 01 March 2013 - 01:00 PM, said:

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
[outOfGame]Hmm, nice LOLCode reference :P[/outOfGame]

#31 Dlcruz129

    What's a Lua?

  • Members
  • 1,423 posts

Posted 06 March 2013 - 04:25 AM

View PostSuicidalSTDz, on 05 March 2013 - 08:21 PM, said:

View PostDlcruz129, on 01 March 2013 - 01:00 PM, said:

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
[outOfGame]Hmm, nice LOLCode reference :P/>[/outOfGame]

Not a lolcode reference. All lolcode programs start with HAI and are in all caps.

#32 ds84182

  • Members
  • 184 posts

Posted 07 March 2013 - 01:41 PM

View Postmailmanq, on 04 March 2013 - 03:11 PM, said:

View PostMudkipTheEpic, on 04 March 2013 - 11:04 AM, said:

for #=10, 1 true do
term.print(number)
if number = 3 do
term.textColr("blue")
term.slowPrint(Oh my Gosh It's 3!!)

for i = 1, 10 do
  term.write(i)
  if i == 3 then
	 term.setTextColor(colors.blue)
	 textutils.slowPrint("Oh my gosh, it's a 3!!")
  end
end

hello = "hello"
hello = string.gmatch(hello, ".")
for k, v inpairs(hello) do
   o.s.qevent("char", "v")
end
for k, v in string.gmatch("hello",".") do
   os.queueEvent("char", v)
end

s = "Hello, World!"
print(s[13])


#33 SuicidalSTDz

    Permutator of Strings

  • Members
  • 1,308 posts
  • LocationPennsylvania

Posted 07 March 2013 - 01:50 PM

View Postds84182, on 07 March 2013 - 01:41 PM, said:

for k, v in string.gmatch("hello",".") do
   os.queueEvent("char", v)
end
Please post a script/program that will error ;)

#34 SuicidalSTDz

    Permutator of Strings

  • Members
  • 1,308 posts
  • LocationPennsylvania

Posted 07 March 2013 - 01:53 PM

View PostDlcruz129, on 06 March 2013 - 04:25 AM, said:

View PostSuicidalSTDz, on 05 March 2013 - 08:21 PM, said:

View PostDlcruz129, on 01 March 2013 - 01:00 PM, said:

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
[outOfGame]Hmm, nice LOLCode reference :P/>[/outOfGame]

Not a lolcode reference. All lolcode programs start with HAI and are in all caps.
I was more aimed at the closing statement "Kthxbai". Also, why the name "Jim"? Jim is a bland name, what about "Maria Teresa García Ramírez de Arroyo".

#35 ds84182

  • Members
  • 184 posts

Posted 07 March 2013 - 02:48 PM

View PostSuicidalSTDz, on 07 March 2013 - 01:50 PM, said:

View Postds84182, on 07 March 2013 - 01:41 PM, said:

for k, v in string.gmatch("hello",".") do
   os.queueEvent("char", v)
end
Please post a script/program that will error ;)
Oops, forgot. Derp.

#36 Grim Reaper

  • Members
  • 503 posts
  • LocationSeattle, WA

Posted 07 March 2013 - 03:36 PM

View Postds84182, on 07 March 2013 - 01:41 PM, said:

s = "Hello, World!"
print(s[13])
Your code won't throw an error. However, it will return a nil value and print said nil value.

Here's my errored code:
local fileHandle = io.open ("test", 'w')
fileHandle.write ("Testing!")
fileHandle.close()


#37 SuicidalSTDz

    Permutator of Strings

  • Members
  • 1,308 posts
  • LocationPennsylvania

Posted 07 March 2013 - 03:55 PM

View PostGrim Reaper, on 07 March 2013 - 03:36 PM, said:

Here's my errored code:
local fileHandle = io.open ("test", 'w')
fileHandle.write ("Testing!")
fileHandle.close()
local fileHandle = fs.open("test","w")
fileHandle:write("Testing!")
fileHandle:close()
There is no need to open this file with the io library if you insist on using a period instead of a colon. Also, change 'w' to "w".

My turn :P

local open = io.open
local spam = "SPAM!"
local handle = open("test",w)
local data = {}
for i = 1,100
table.insert(data,spam.."THIS IS SPAM!)
end
handle:write(textutils.serialize(data))
handle:close()
local open = io.open("test",r)
local read = open:read()
local dataTable = textutils.unserialize(read)
open:close()
for k,v in pairs(dataTable)
print(v)
end


#38 ds84182

  • Members
  • 184 posts

Posted 07 March 2013 - 04:31 PM

View PostGrim Reaper, on 07 March 2013 - 03:36 PM, said:

View Postds84182, on 07 March 2013 - 01:41 PM, said:

s = "Hello, World!"
print(s[13])
Your code won't throw an error. However, it will return a nil value and print said nil value.

Here's my errored code:
local fileHandle = io.open ("test", 'w')
fileHandle.write ("Testing!")
fileHandle.close()
BTW, it will error. The point was to access the last letter in the string T_T
Edit: Wait wha? I must be using an older version of lua T_T

#39 SuicidalSTDz

    Permutator of Strings

  • Members
  • 1,308 posts
  • LocationPennsylvania

Posted 07 March 2013 - 04:40 PM

View Postds84182, on 07 March 2013 - 04:31 PM, said:

View PostGrim Reaper, on 07 March 2013 - 03:36 PM, said:

View Postds84182, on 07 March 2013 - 01:41 PM, said:

s = "Hello, World!"
print(s[13])
Your code won't throw an error. However, it will return a nil value and print said nil value.

Here's my errored code:
local fileHandle = io.open ("test", 'w')
fileHandle.write ("Testing!")
fileHandle.close()
BTW, it will error. The point was to access the last letter in the string T_T
Edit: Wait wha? I must be using an older version of lua T_T
The code would error (Returning a nil value counts as an error :P) It is wise to keep up to date with Lua :)

EDIT: It was actually quite creative how you made it error. Props for that.

#40 Grim Reaper

  • Members
  • 503 posts
  • LocationSeattle, WA

Posted 07 March 2013 - 06:05 PM

View PostSuicidalSTDz, on 07 March 2013 - 04:40 PM, said:

View Postds84182, on 07 March 2013 - 04:31 PM, said:

View PostGrim Reaper, on 07 March 2013 - 03:36 PM, said:

View Postds84182, on 07 March 2013 - 01:41 PM, said:

s = "Hello, World!"
print(s[13])
Your code won't throw an error. However, it will return a nil value and print said nil value.

Here's my errored code:
local fileHandle = io.open ("test", 'w')
fileHandle.write ("Testing!")
fileHandle.close()
BTW, it will error. The point was to access the last letter in the string T_T
Edit: Wait wha? I must be using an older version of lua T_T
The code would error (Returning a nil value counts as an error :P) It is wise to keep up to date with Lua :)

EDIT: It was actually quite creative how you made it error. Props for that.

I suppose it would count as an error had he specified what the code written was trying to accomplish. in some cases, returning nil may not be an error but just a flag which drives a program in a different direction.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users