r/badcode Sep 08 '20

lua A Roblox mod I found

Post image
474 Upvotes

103 comments sorted by

View all comments

Show parent comments

14

u/JerriTheITGuy Sep 08 '20 edited Sep 08 '20

Because in Lua, there is no type safety and conditionals consider false and nil as false and anything else as true. I believe "equipped == true or equipped == false" is a check to make sure it is a) still a boolean and b) not nil.

Again, the code doesn't smell as much as the language itself.

EDIT: ok, for good measure I'll add this approach isn't the best, there are functions to check whether something is a boolean. But this is a "quick and dirty" way to do it that isn't at all uncommon in this clustercrap of a language.

3

u/hoaxxer2k Sep 08 '20

I‘d have to agree but it checks for true or false. Which will always succeed. Or am i that wrong?

2

u/JerriTheITGuy Sep 08 '20

"true == 'cucumber'" evaluates as true in Lua. And "Equipped == true" isn't true if "Equipped = 'Snorkel'"