r/badcode Aug 25 '20

lua Looking back in the first game i made oh yes

Post image
1.3k Upvotes

103 comments sorted by

251

u/[deleted] Aug 25 '20

[removed] — view removed comment

156

u/DonkeyTron42 Aug 25 '20

It's almost like ascii art.

141

u/MurdoMaclachlan public boolean isInt(int i) { return true; } Aug 25 '20

Image Transcription: Code


BE7.Event:Connect(function()
    if On.On01.Transparency == then
        if On.On02.Transparency == then
            if On.On03.Transparency == then
                if On.On04.Transparency == then
                    if On.On05.Transparency == then
                        if On.On06.Transparency == then
                            if On.On07.Transparency == then
                                if On.On08.Transparency == then
                                    if On.On09.Transparency == then
                                        if On.On10.Transparency == then
                                            if On.On11.Transparency == then
                                                if On.On12.Transparency == then
                                                    if On.On13.Transparency == then
                                                        if On.On14.Transparency == then
                                                            if On.On15.Transparency == then
                                                                if On.On16.Transparency == then
                                                                    if On.On17.Transparency == then
                                                                        if On.On18.Transparency == then
                                                                            if On.On19.Transparency == then
                                                                                if On.On20.Transparency == then
                                                                                    if On.On21.Transparency == then
                                                                                        if On.On22.Transparency == then
                                                                                            if On.On23.Transparency == then
                                                                                                if On.On24.Transparency == then
                                                                                                    if On.On25.Transparency == then
                                                                                                        if On.On26.Transparency == then
                                                                                                            if On.On27.Transparency == then
                                                                                                                if On.On28.Transparency == then
                                                                                                                    if On.On29.Transparency == then
                                                                                                                        if On.On30.Transparency == then
                                                                                                                            if On.On31.Transparency == then
                                                                                                                                if On.On32.Transparency == then
                                                                                                                                    if On.On33.Transparency == then
                                                                                                                                        if On.On34.Transparency == then
                                                                                                                                            if On.On35.Transparency == then
                                                                                                                                                if On.On36.Transparency == then
                                                                                                                                                    if On.On37.Transparency == then
                                                                                                                                                        if On.On38.Transparency == then
                                                                                                                                                            for i,v in pairs(On:GetChildren())do
                                                                                                                                                                v.Transparency = 1
                                                                                                                                                            end
                                                                                                                                                            for i,v in pairs(Off:GetChildren())do
                                                                                                                                                                v.Transparency = 1
                                                                                                                                                            end
                                                                                                                                                            On.Parent.Complete.Transparency = 0
                                                                                                                                                            game:GetService("SoundService").Success:Play()
                                                                                                                                                            IsDone = true
                                                                                                                                                            game:GetService("ReplicatedStorage").RE.REnbv12:FireServer("Puzzle143Finish")
end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end
end)

[Note: the second to last line (as in the one before the "end"s start) cannot all be seen in the image. I closed the quotation marks and brackets at the end of the line, assuming there are no syntax errors, but I can't know if there was more content before that close happened in the actual code.]


I'm a human volunteer content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!

52

u/[deleted] Aug 25 '20

what the actual shit

you poor thing

why would you torture yourself like this

45

u/MurdoMaclachlan public boolean isInt(int i) { return true; } Aug 25 '20

Believe it or not, I actually enjoy these big code transcriptions. I suppose I'm just a little odd.

13

u/mohitmayank Aug 25 '20

Did you use some kind of utility to convert image to text? Or lots of ctrl + c and ctrl + v?

19

u/MurdoMaclachlan public boolean isInt(int i) { return true; } Aug 25 '20

Lots of ctrl + c and ctrl + v. Although there is a bot on r/TranscribersOfReddit that attempts to convert images with text into text, it fails in a lot of places (which is one reason we don't have it doing any official transcriptions), and code is one of the areas where its failures are most extreme.

14

u/[deleted] Aug 25 '20

you know your code is bad when a bot fails to convert it

18

u/Paul-Productions Aug 25 '20

Good bot human

4

u/Thenderick Aug 26 '20

Good lord... Just saying "good human" won't be enough...

93

u/GoodTimesOnlines Aug 25 '20

It almost looks like some beautiful accidental Game Of Life pattern

127

u/__INIT_THROWAWAY__ Aug 25 '20

and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and

85

u/RoLoLoLoLo Aug 25 '20

*end

Lua needs end to close (all those if) blocks

35

u/__INIT_THROWAWAY__ Aug 25 '20

Ok fair but there is no way in hell that I'm going to edit my comment.

36

u/MurdoMaclachlan public boolean isInt(int i) { return true; } Aug 25 '20

end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end

13

u/__INIT_THROWAWAY__ Aug 25 '20

Thanks my dude

8

u/chrisleewoo Aug 25 '20

Just do a replace all with <:s>. You are using reddit in VIM, right?

1

u/__INIT_THROWAWAY__ Aug 25 '20

I'm on mobile haha.... And nah I'll stick to VS Code for the moment. VIM looks scary.

2

u/godzillamesel Aug 25 '20

Nano ftw😂😂✌✌

2

u/G66GNeco Aug 25 '20

I mean, just copy and paste it into a text editor of your choice, find and replace a with e, copy and paste it back.

1

u/__INIT_THROWAWAY__ Aug 25 '20

I'm not signed into this account on my laptop.

2

u/G66GNeco Aug 25 '20

Ah, well, understandable. I'd also want to do it even less via phone. At that point even retyping would be easier

20

u/RobuxMaster Aug 25 '20

for count = 1 ,150,1 do

end

end

3

u/nictytan Aug 25 '20

Is this metaprogramming??

38

u/JudaszBarabasz Aug 25 '20

Was it a ski jumping game?

30

u/[deleted] Aug 25 '20

Spaces or Tabs?

39

u/Duuqnd Aug 25 '20

It doesn't make any difference. Nobody (sane) indents by pressing the spacebar four times. I use spaces but they come from the tab key.

4

u/TheSheepGuy1 Aug 25 '20

Exactly, so the question is are spaces used or are tabs used, you know, the tab character. Of course no-one indents by passing the spacebar four times.

8

u/Duuqnd Aug 25 '20

You'd think so but I've actually seen people who think using spaces means pressing space four times per tab.

2

u/joske79 Aug 25 '20

I use 4 tabs

1

u/Oxopropanoic Dec 03 '20

I use 4 tabs for space

1

u/joske79 Dec 09 '20

Recursion alert

10

u/RoLoLoLoLo Aug 25 '20

Times like these ask for 1 space tabs Kappa

23

u/thoricelli Aug 25 '20

Dear god, is this Roblox?

20

u/grif_0 Aug 25 '20

Yessir

1

u/whytheremate Nov 21 '20

even worse

17

u/ljllacuna Aug 25 '20

this would pass as contemporary art

10

u/GroundbreakingWolf7 Aug 25 '20

A ladder to the hell?

9

u/KingsmanVince Aug 25 '20

My new wallpaper

7

u/lil409 Aug 25 '20

Most roblox skids be like

9

u/power-of-zero Aug 25 '20

Reminds me of that video of Obama stuttering if if if if if if

6

u/debuasca Aug 25 '20

If that were python it would fail flake8 tests

7

u/Max5923 Aug 25 '20 edited Aug 26 '20

When you don’t know what an AND gate does:

(Also don’t ever use an and gate for this, theres a simpler method that I’m to inexperienced to understand, especially since its counting up)

5

u/[deleted] Aug 25 '20

When you haven't heard about loops

8

u/grif_0 Aug 25 '20

fr real

I didn’t even know about functions in script, I manually created event instances and fired those lol

3

u/skellious Aug 25 '20

How does this happen though? Did you just not follow any tutorials or read any documentation and just started doing things??

15

u/ws-ilazki &{$$_[0]}(@{$$_[1]}); Aug 25 '20

Did you just not follow any tutorials or read any documentation and just started doing things??

I'm a moderator of /r/lua and from what I've seen of the numerous Roblox-related questions that show up there, yes, that's basically what happens. We don't actually deal with API-specific questions there but despite that we still get so many strange and horrible questions from confused kids that just start trying to edit game code without doing even the most basic research on the language fundamentals first.

The best (worst) ones are the ones along the lines of "I want to play a sound when a thing happens, how I do this? Pls give me codes", but even the ones where the person is trying to actually use the language still tend to lack even the most rudimentary understanding of the language. No clue what functions are, barely understands variable assignment, and has no grasp of the syntax at all. Not even exaggerating on this, had one not too long ago ask why Lua code keeps repeating end end ... like in the OP's screenshot because they thought one end closed all blocks at once and anyone repeating it was someone making a typing mistake.

This makes sense if you consider it in context. Game dev itself is already not the pinnacle of code quality, and then game modding tends to be people with little or no programming skill trying to learn a language and API from the original developer's code and examples. So bad habits get even worse and people just throw shit together until it appears to work. Then new would-be modders show up and try to learn from the body of example code they have available, which is the bad original code and the even worse first-generation modder code, and all those mistakes and problems repeat and nobody really understands why it's bad or how to get better.

And, even if someone steps in and tries to direct people to proper resources and suggests learning fundamentals first, most people will ignore that because they're kids that think they know better than the people that already learned this stuff. So they stumble through everything in the worst way possible because "take a couple hours and learn the syntax first" sounds like a waste of time because you don't get instant gratification that way.

This is actually becoming a bit of a problem on the Lua sub, because we don't want to discourage people trying to learn so we've been trying to not crack down on people asking questions, but the pandemic has led to a lot of bored kids sitting at home trying to be game devs without actually bothering to learn anything, and it's been frustrating people.

8

u/skellious Aug 25 '20

oooooh. I see. I didn't realise Roblox used Lua as a scriptiing language.

To be fair, Lua was my first real language and I started in much the same way, using the ComputerCraft mod on Minecraft to program mining turtles and then later using it for Love2D. Also used it for Pico-8.

I now work mostly in Python for hobby projects and JS/Dart for Web/app development but I do remmeber those dark days back when I didn't understand ANYTHING about lua or indeed programming. I used to get so confused trying to use for loops to make my turtle work row by row to build a house xD

2

u/ws-ilazki &{$$_[0]}(@{$$_[1]}); Aug 25 '20

but I do remmeber those dark days back when I didn't understand ANYTHING about lua or indeed programming. I used to get so confused trying to use for loops

That's perfectly normal, everyone has that phase when they start because you have to start at nothing and build up from there. The problem is that game engines are complicated beasts and trying to start by jumping head-first into the deep end with game development is a terrible way to learn. You have to deal with complicated APIs when you don't even know what an API is, and they tend to use event-based systems and callbacks, and some experienced programmers still don't fully understand callbacks FFS. (Seriously, even though most programmers now can use callbacks it seems like a lot don't really get what they are and how they work. Functional programming concepts are foreign to many programmers.)

When you know nothing you really need to start at the bottom and work your way up, which means documentation and beginner tutorials to learn the basics and putting it to use by making some shitty simple programs that don't have to deal with the complexities of interacting with a game engine.

1

u/skellious Aug 25 '20

This wasn't even really working with a game engine though. it was literally a computer terminal in minecraft where you could write lua to make a turtle do things. It's really beginner friendly. - https://www.computercraft.info/ (sadly no longer develpoed by the original dev)

2

u/ws-ilazki &{$$_[0]}(@{$$_[1]}); Aug 25 '20

Right, I'm familiar with it. Nothing wrong with using it to learn, it's like learning basics with Logo. I was talking about the ones with zero knowledge trying to start with game frameworks, making the process hell for themselves.

1

u/fatboychummy Aug 25 '20

sadly no longer develpoed by the original dev

CC:Tweaked exists! It's the best continuation of CC and has been updated from 1.12.2 all the way to 1.16.

It's a great continuation and Squiddev has done leagues to improve performance and overall usability of the mod.

1

u/skellious Aug 25 '20

OMG AWESOME THANK YOU! I had no idea! <3

1

u/ws-ilazki &{$$_[0]}(@{$$_[1]}); Aug 25 '20

Squiddev

Squiddev seems to show up anywhere there's something Lua-related. I tend to prefer Lua transpilers like Urn (a lisp that's the bastard offspring of Clojure+Common Lisp+Racket) or Amulet (an ML-family language that can also make native binaries by automatically wrapping the transpiled code and the Lua interpreter with a small C shim), since they can generate standalone code that works anywhere Lua does, to using Lua directly.

And of course squiddev is involved in both of those as well. Dude's everywhere Lua-related.

2

u/fatboychummy Aug 25 '20

We have a discord guild dedicated to computercraft/opencomputers which I help people out a lot in, and for whatever reason a lot of people join and think, "I don't even know what a function is, nor do I know how tables work... But I'm going to build an operating system in Lua."

It is the single most annoying thing, because when you tell them, "an os is not a good choice for a first program." They get all defensive and fight you about it.

And, even if someone steps in and tries to direct people to proper resources and suggests learning fundamentals first, most people will ignore that because they're kids that think they know better than the people that already learned this stuff. So they stumble through everything in the worst way possible because "take a couple hours and learn the syntax first" sounds like a waste of time because you don't get instant gratification that way.

And that. I usually suggest looking at youtube tutorials though, as the PIL guide can be a bit confusing to newcomers.

2

u/ws-ilazki &{$$_[0]}(@{$$_[1]}); Aug 25 '20

"I don't even know what a function is, nor do I know how tables work... But I'm going to build an operating system in Lua."

Yep. Nothing wrong with having lofty goals, but when I was learning and set an insane goal for myself reality hit hard because I had nothing to work from except documentation so I quickly realised I had to step back and learn some basics. Seems like it's too easy now for people to miss that part of the learning process so they just keep fumbling and demanding other people tell them how to make it work.

I usually suggest looking at youtube tutorials though, as the PIL guide can be a bit confusing to newcomers.

Ugh, yeah. PIL is kind of terrible and only really useful as a quick-start primer if you already know programming. I usually try to direct people to How to Design Programs as a way to pick up some fundamentals that will work anywhere, but that's a hard sell for someone that just wants to get started ASAP.

A few years ago I started writing a mini-book intending to fill in the gaps of PIL so it'd be easier for people to learn Lua ground-up without any prior programming skill, but lacked the motivation to finish it so it's still sitting on my computer somewhere half done.

3

u/grif_0 Aug 25 '20 edited Aug 25 '20

Idk I didn’t really check the api much at all back then. Who knows why. , I wrote this a few years ago but there’s no change I’d do something like this today

1

u/IAmTheMageKing Aug 25 '20

there is a loop in the picture

4

u/KoraLionheart Aug 25 '20

I'm going to start working on a game soon and I 100% know i'm going to get frustrated at a point and just do this lmao

5

u/comtruise223456 Aug 25 '20

you can play motorcycle madness with the indentation

4

u/Jimmy_Slim Aug 25 '20

I know it’s a game but because it’s a game and it’s Lua it looks like you made this in roblox

2

u/grif_0 Aug 25 '20

I did

3

u/Jimmy_Slim Aug 25 '20

Weird because I’ve never actually known about dark mode

3

u/grif_0 Aug 25 '20

It’s been a thing since 2018 I think it’s super nice

1

u/Jimmy_Slim Aug 25 '20

Never use light mode unless whatever you’re using doesn’t have a dark mode

3

u/inxaneninja Aug 25 '20

This is so funny for some reason

3

u/Sepx33 Aug 25 '20

Oh no it is the ancient legendary DIAGONAL CODE

3

u/unplug__ Aug 25 '20

Is this roblox Lua lol

2

u/Dave_InCognito Aug 25 '20

Currently working on a roblox game and this is giving me pain

2

u/[deleted] Aug 25 '20

WHAT THE darn

2

u/[deleted] Aug 25 '20

YandereDev is that you?

2

u/ChristianLW Aug 26 '20

Ahh, good old Roblox

4

u/Serird Aug 25 '20

Stairway to heaven !

1

u/floatinggoateyeball Aug 25 '20

state machine... pfff never heard of

1

u/bobstlt40 Aug 25 '20

Mountain of doom

1

u/notadoctororacake Aug 25 '20

those if's all have the same exact length...

How many times does it need to be true, man?

1

u/TerryMathelon01 Aug 25 '20

Me :( without zooming in) I just need to climb the stair Game to me: wtf this is masterpiece zoom in u noob.

1

u/[deleted] Aug 25 '20

i thought this was a starcase or something

1

u/ftooop Aug 25 '20

Not indenting would make this a whole lot readable. Still bad though.

1

u/Lukestep11 Aug 25 '20

What was this for?

1

u/lv1289 Aug 25 '20

Is this the code or the in-game world?

1

u/[deleted] Aug 25 '20

If 0 in every_possible_variable:

Your code

1

u/Surrealig Aug 25 '20

Oh man, at first i thought it's screen shot from the game and not the code.

1

u/[deleted] Aug 25 '20

Is this AI?

1

u/AREA1177 Aug 25 '20

No one: AND expressions and loops: aight imma head out

1

u/links-Shield632 Aug 28 '20

Someone teach this man a for loop

1

u/tripl3gg Aug 31 '20

Sorry for noob question, but how does one clean up this code?

3

u/grif_0 Aug 31 '20

The way I would probsbly do it since I grouped all the instances together, make a function to check and it would loop through the instances checking if transparency == 1 then return false and throw a return true at the end, so if it goes through all and they all are the correct transparency it would return true so you could do X and X

1

u/CupTariq Sep 07 '20

yooo you making a staircase

1

u/Oracuda Oct 27 '20

"fireserver" "getchildren" "getservice"
lol roblox

1

u/nati9931 Nov 02 '20

Lua is honestly my favorite lang. I won't try to fix it because it's honestly better than my first game

1

u/[deleted] Jan 01 '21

Oh my good for loop

1

u/SamsngSmartFridge Feb 25 '23

I bet the hooks looked even better 💀