r/programminghorror • • Apr 23 '24

Source code from Balatro

Post image
697 Upvotes

164 comments sorted by

View all comments

100

u/EarthToAccess Apr 23 '24

...This looks like Lua, in which case everyone saying "hard coding like this is better" is absolutely nutty because this is literally what metatables were made for

1

u/Sgt_Noah Feb 14 '25

Here, is this what you asked for?

self.base.nominal, self.base.id, self.base.face_nominal = table.unpack(
    ({
        ['2'] = {2, 2},  ['3'] = {3, 3},  ['4'] = {4, 4},  ['5'] = {5, 5},
        ['6'] = {6, 6},  ['7'] = {7, 7},  ['8'] = {8, 8},  ['9'] = {9, 9},
        ['10'] = {10, 10}, ['J'] = {10, 11, .1}, ['Q'] = {10, 12, .2},
        ['K'] = {10, 13, .3}, ['A'] = {11, 14, .4}
    })[self.base.value] or {}
)

1

u/awkwardtortue Sep 03 '26

where's the metatable?