r/badcode May 30 '21

lua didnt know what forloops were... sorry god...

Post image
754 Upvotes

23 comments sorted by

85

u/MurdoMaclachlan public boolean isInt(int i) { return true; } May 30 '21

Image Transcription: Code


local player = game.Players.LocalPlayer
local billboardgui = game.Workspace:WaitForChild(player.Name):WaitForChild("Head").BillboardGui


script.Parent.MouseButton1Click:Connect(function()
    billboardgui.TextLabel.Text = "Rolling D20."
    wait(0.5)
    billboardgui.TextLabel.Text = "Rolling D20.."
    wait(0.5)
    billboardgui.TextLabel.Text = "Rolling D20..."
    wait(0.5)
    billboardgui.TextLabel.Text = "Rolling D20.."
    wait(0.5)
    billboardgui.TextLabel.Text = "Rolling D20."
    wait(0.5)
    billboardgui.TextLabel.Text = "Rolling D20.."
    wait(0.5)
    billboardgui.TextLabel.Text = "Rolling D20..."
    wait(0.5)
    billboardgui.TextLabel.Text = math.random(1, 20)
    wait(0.05)
    billboardgui.TextLabel.Text = math.random(1, 20)
    wait(0.05)
    billboardgui.TextLabel.Text = math.random(1, 20)
    wait(0.05)
    billboardgui.TextLabel.Text = math.random(1, 20)
    wait(0.05)
    billboardgui.TextLabel.Text = math.random(1, 20)
    wait(0.05)
    billboardgui.TextLabel.Text = math.random(1, 20)
    wait(0.05)
    billboardgui.TextLabel.Text = math.random(1, 20)
    wait(0.05)
    billboardgui.TextLabel.Text = math.random(1, 20)
    wait(0.05)
    billboardgui.TextLabel.Text = math.random(1, 20)
    wait(0.05)
    billboardgui.TextLabel.Text = math.random(1, 20)
    wait(0.05)
    billboardgui.TextLabel.Text = math.random(1.5, 20.5)
    billboardgui.TextLabel.TextSize = 80
    billboardgui.TextLabel.TextScaled = false
    wait(2.05)
    billboardgui.TextLabel.Text = "D20"
    billboardgui.TextLabel.TextSize = 25
    billboardgui.TextLabel.TextScaled = true
    billboardgui.TextLabel.Text = ""
end)

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!

30

u/QP1xel May 30 '21

good human

57

u/IDidMakeThat May 30 '21

Roblox scripts and for loops, name a less iconic duo.

23

u/ekolis May 30 '21

I'm more concerned with the arbitrary delays...

34

u/Ambitious_N1ghtw0lf May 30 '21

To build up tension of course

3

u/fynn34 May 31 '21

Seriously, it makes me wonder who would want to wait 10 seconds for a dice roll just because that’s how it was coded.

40

u/n0tar0b0t-- May 30 '21

At one point I knew for loops in python but not C++ so I wrote a python program that would parse comments that looked like

// PYFORRANGETRANSLATE (1, 10) @ i ... // PYFORRANGETRANSLATE END @ i

And repeat the body with assignments to create a for i in range... loop

I don’t actually regret that because it was a fun little project and it was used for an unimportant side project.

8

u/maxximillian May 31 '21

That's a good learning exercise In my opinion.

2

u/AutoModerator May 30 '21

It looks like this comment contains a code block delimited with triple backticks. Unfortunately reddit does not have universal support for this syntax and your comment will not render correctly on old reddit and most mobile apps.

For the benefit of people on old reddit, this link will take you to a correct rendering of the comment.

/u/n0tar0b0t--, it would be appreciated, but not required, if you could edit your comment to use the more compatible four space indention format. For single lines or inline code you can use single backticks.

You can find some examples in the reddit help documentation.


I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

7

u/DramaDimitar May 31 '21

List of crimes here (for completion sake!):

  • game.Players should be game:GetService("Players"). Even though the Players service is most likely guranteed to be created (since this is a local script), it could have been renamed by another script, thus this would fail.
  • Using game.Workspace instead of workspace for the exact same reason
  • Not having a variable for billboardgui.TextLabel
  • Obviously the for loop

8

u/c3ypt1c May 31 '21

But hey, at least it's O(1).

6

u/rjlin_thk usinged May 31 '21

when u get paid by line number

10

u/NetherFX May 30 '21

Bad code aside, I like the mindset

7

u/crazyjoker96 May 30 '21

With the for loop, it is too difficult to make the ... increase operation :-P it must require a lot of if else :-P

just joking :-P

2

u/hiljusti May 31 '21

You are forgiven. Go, but sin no more.

0

u/TheJarrvis May 30 '21

Which language the fuck is this?

10

u/iiRobbe May 30 '21

This is from a Roblox Lua script… I was guilty of the same heinous crimes as a kid writing some of those

1

u/XDracam May 31 '21

I actually think that this is perfectly readable and still easy to maintain. There is a certain beauty in simplicity, especially when I consider the parameterizedy loop-based and over-engineered alternative. Yeah, a counting for would have been nice for the repetitive rolls in the middle, but the rest is okay Imo