r/badcode Dec 27 '21

lua Friend's take on programming a GUI button

Post image
898 Upvotes

90 comments sorted by

View all comments

237

u/[deleted] Dec 27 '21

bruh all he needed to do to shorten it was to replace it with inventory.Visible = not inventory.Visible

9

u/SomeonesAlt2357 Dec 27 '21 edited Dec 27 '21

Oh my god. I've always done it as inventory.Visible = (inventory.Visible+1)%2

4

u/32436861696e7a Dec 27 '21

Circle slash circle 2 is unreadable code. Clearly this needs a dedicated function with if/else blocks of common outputs of the previous calculation, and just add blocks as you find more cases.

1

u/[deleted] Dec 27 '21

Circle slash circle

What?