Jump to content




[CC]Code Cleanup


170 replies to this topic

#161 MKlegoman357

  • Members
  • 1,170 posts
  • LocationKaunas, Lithuania

Posted 06 March 2015 - 07:03 AM

You've both missed my point on the second loop. It was supposed to reverse the table, not just copy it. Also, what do you mean by that "bad practice" exactly?

#162 cptdeath58

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

Posted 06 March 2015 - 09:02 AM

local hugs = "YEAH" -- defined hugs
If hugs == nil then
print("You dun wunt hugs?") -- fixed prinl
elseif Hugs ~= nil then -- changed if to elseif
print("YUS, HUGGERS") --fixed bracket/parenthesis and add quotation
end


Bugs!
Pie =
If Pie = Yes then
print("YEAH! PIE IS GREAT!")
eles Pie = No then
print(Get out of my sight)
dne

Edit: God I hate the color bug...

Edited by cptdeath58, 06 March 2015 - 09:10 AM.


#163 Lupus590

  • Members
  • 2,029 posts
  • LocationUK

Posted 08 March 2015 - 08:01 PM

Pie = --no value here for initulise
If Pie = Yes then --unless Yes is a var, then should be "Yes"
print("YEAH! PIE IS GREAT!") --just to have a comment on every line
eles Pie = No then --see comment about yes --else, not eles
print(Get out of my sight) --need quote marks here
dne --should be end

--language = lua
while true doh
{
	print("Loop ".."= "..loop);
	loop++;
}
end;

bug count

Edited by Lupus590, 08 March 2015 - 08:05 PM.


#164 SquidDev

    Frickin' laser beams | Resident Necromancer

  • Members
  • 1,427 posts
  • LocationDoes anyone put something serious here?

Posted 08 March 2015 - 08:48 PM

while true do
	print("Loop ".."= "..loop);
	loop = loop + 1;
end;
  • No braces
  • do not doh
  • loop = loop + 1 not loop++
  • "Loop " .. "= " could be combined into one. I don't think Lua implements constant folding...
  • Loop isn't defined.
Of course you can always just do: error("Too long without yielding") It would have the same effect.

-- Lets calculate Fibonacci numbers!
do
  local a, b = 1

  fur i = 0, 100, -1 do
	a, b = a, a + b
  end for
end
print(a)

There are ~6 bugs, maybe more maybe less.

Edited by SquidDev, 08 March 2015 - 08:51 PM.


#165 Konlab

  • Members
  • 595 posts
  • LocationKerbin

Posted 13 August 2015 - 12:23 PM

--Lets calculate Fibonacci numbers!
do
 a, b =1,1

 for i = 0,100 do
a,b = a, a + b
b,a = b, a + b
 end
end
print(a)
1. the fur loop
2. the for after the end
3. b is not defined
4. The for loop will never end
5. var called 'a' is not changing
My code:
--This code downloads a file and saves its first line into a log (should)
local a = http.get("a random url")
local b = fs.open("log.txt")
b.writeLine(a.readLine())
5 + 1 bugs
EDIT: the url is NOT a bug

Edited by Konlab, 13 August 2015 - 12:27 PM.


#166 Waitdev_

  • Members
  • 432 posts
  • LocationAdelaide

Posted 21 August 2015 - 09:30 AM

View PostKonlab, on 13 August 2015 - 12:23 PM, said:

-snip-
My code:
--This code downloads a file and saves its first line into a log (should)
local a = http.get("a random url")
local b = fs.open("log.txt")
b.writeLine(a.readLine())
5 + 1 bugs
EDIT: the url is NOT a bug

well, i haven't done lua for a while. here i go.

local a = http.get("url")
local b = fs.open("log.txt","w") --choose mode
b.write(a.readAll()) --readLine doesn't exist
b.close() --you forgot to close it after
--your gonna have to write the whole thing. deal with it.

i think thats it?

#167 H4X0RZ

  • Members
  • 1,315 posts
  • LocationGermany

Posted 21 August 2015 - 04:29 PM

View PostWait_, on 21 August 2015 - 09:30 AM, said:

View PostKonlab, on 13 August 2015 - 12:23 PM, said:

-snip-
My code:
--This code downloads a file and saves its first line into a log (should)
local a = http.get("a random url")
local b = fs.open("log.txt")
b.writeLine(a.readLine())
5 + 1 bugs
EDIT: the url is NOT a bug

well, i haven't done lua for a while. here i go.

local a = http.get("url")
local b = fs.open("log.txt","w") --choose mode
b.write(a.readAll()) --readLine doesn't exist
b.close() --you forgot to close it after
--your gonna have to write the whole thing. deal with it.

i think thats it?

You can write the first line.
local t = {a.readAll():gsub("(.+)\n.+")}
b.write(t[1])


And I failed another time...

Edited by H4X0RZ, 22 August 2015 - 11:17 PM.


#168 Dog

  • Members
  • 1,179 posts
  • LocationEarth orbit

Posted 28 February 2016 - 12:11 AM

Well, since nobody posted any bad code after solving the last one, here's some bad code:
locla variable = os.pullEvent("redstone")
if variable == true or variable == false then
  if variable == true then
    rs,setAnanlogOutput(15)
  else
    rs,setAnanlogOutput(0)
  end
end

At least 6 bugs and sloppy code to boot

#169 Creator

    Mad Dash Victor

  • Members
  • 2,168 posts
  • LocationYou will never find me, muhahahahahaha

Posted 28 February 2016 - 10:26 AM

local variable = os.pullEvent("redstone")
  if variable == true then
	rs.setAnanlogOutput(15)
  else
	rs.setAnanlogOutput(0)
  end


local event = {corotine.yielld("anything")}
if evnet[1] == "wow" then
  print(wow)
end

Edited by Creator, 28 February 2016 - 03:35 PM.


#170 Dog

  • Members
  • 1,179 posts
  • LocationEarth orbit

Posted 28 February 2016 - 03:20 PM

View PostCreator, on 28 February 2016 - 10:26 AM, said:

local variable = os.pullEvent("redstone")
  if variable == true then
	rs,setAnanlogOutput(15)
  else
	rs,setAnanlogOutput(0)
  end
...

I still see at least 5 bugs :P

#171 jv110

  • Members
  • 108 posts
  • LocationIn front of my PC

Posted 28 February 2016 - 05:20 PM

os.pullEvent("redstone")

[color=black][font=monospace, Courier]for k, v in pairs(redstone.getSides()) do[/font][/color]
  if rs.getInput(v) then
    rs.setOutput(true)
    break
  else
    rs.setOutput(false)
  end
end

local, not locla!
The redstone event doesn't return anything, and the first return value would be "redstone".
You don't need to check if something is true or false, and you don't need to == true.
You don't need analog output if you're only going to set it to max or min.
Dot, not comma!
Analog is not spelt like that.

lolcal vec == vetcor\nil{#4 ;%6 :$2]
locla n == ('x´ .´y` ;"z´)

f0ur u == 9 .7 ;-1 dO
  widowns,turm:pirnt[vce{m(10 - u]}]
amd






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users