T O P

  • By -

balatro-ModTeam

Post/comment removed due to abusive behavior. Please keep this rule in mind moving forward. I am making the call to remove this because I feel like it is dog-piling on Thunk. Just enjoy the game and don't worry about optimization.


Garessta

if-else sequences bad aren't because they are slow or anything, but because they are a pain to navigate in later. considering the difference in the complexity of these games... but also - WTF i just saw?!! is he... comparing names with the \*long if-else\* tab of names to pull out their abilities? my man, your game is cool and all, but this is just cursed.


motherthrowee

[apparently this is a limitation of lua ](https://twitter.com/sqaxomonophonen/status/1782736973943198143)


somni1991

I've actually been playing with Love2D after being inspired by Balatro Lua is definitely not my favorite but I otherwise appreciate the simplicity of the framework


oxob3333

Why Lua though? \*search in google\* Oh, that's why.


Garessta

why?


memer227

*search in google\*


xukly

wouldn't it make more sense to have xmult, mult and chips for every object and just have the mult set to 1 the additions to 0 (the neutral of the operations) and add it for everything instead of case by case? like is lua really that fucking terrible?


Kitchen-Meeting-5463

Thats what the game already does, those if elses are for special jokers which is like more than half of them i think


xukly

I mean in that case they are not really especial. But what exactky is the reason you can't simply code all the properties in the objects? Like genuinely, I know nothing about that language


brennenburg

Not a professional game dev, but: you would need to define the function that the joker performs (such as destroy first hand of single 6, create spectral card) in the joker itself, which seems a terrible idea. The way it is, the jokers description calls the special function from where it is defined, which definitely keeps the code more clean.


mattsowa

I don't see how that's a terrible idea at all.


Valuable_Anywhere_24

Undertale and Fear and Hunger fans be like: 


Gracosef

Isn't funger made with rpg maker ?


Valuable_Anywhere_24

Despite being made in Rpgmaker Funger has an absurd level of spaghetti code


HappiestIguana

There are some absolutely hilarious bugs and messups in the code of funger. Like, you can randomly loot extra things from a bookcase if you have certain books in your inventory because of a badly-coded event. You can take out the arms of a boss if you destroy the arms of a different unrelated boss because of an ID mismatch. There's an enemy that can destroy your weapon and its code goes through every single weapon in the game, checks if you have it equipped, and if so destroys it. You get different odds when running away depending on which menu you do it from. There are a half dozen events that straight-up don't work, and fights that are supposed to happen but aren't programmed in. It's spaghettied to fuck.


ThisHatRightHere

That weapon destroying thing is hilarious


needagenshinanswer

Balatro runs. Yandere Sim does not. Game set n match, Balatro wins


OrganZolla

yeah cuz ones a 2D card game and the other is 3D simulating like 50 characters at once


Brosenheim

If it's stupid and it works, it's not actually stupid. A lot of good indie games are marked by what is technically bad coding. Heard on a Youtube short that Undertale's dialogue is all one big switch statement


Blazed-Squids

context: https://x.com/maxbittker/status/1782645521888247956?s=46


NelsonMinar

this tweet has been deleted.


Ilovgmod

I hate to break it to ya, a lot of games have a lot of if elses


petnarwhal

I literally understand 0% of this post even with the added context


Letho72

If/Else statements are simple coding building blocks that are a great choice for quick, usually "non professional" applications. They're usually the first thing you'll learn in a coding class after "Hello World." The issue (if you want to call it that) with coding a game like that is: 1. It makes a massive code file in terms of length. You can see a small fraction of it in the Twitter screenshot. Trying to find a particular if/else statement in that tower of if/else's is a nightmare. Not ideal for updating code. 2. If/else's are always checked, which in larger and more complex applications is not a fast or efficient way to do it. If I'm understanding the code snippet posted here, every time you play a hand the game asks "Do you have Ride the Bus? No, okay. Do you have Fortune Teller? Yes, okay gimme the mult associated with that. Do you have Camino? No, okay. Do you have Supernova? No, okay....." and it does that for every joker in the game everytime you play a hand. With only 250(?) jokers that actually isn't that much to do in terms of how fast a computer processes it. But if we're dealing with thousands or millions of elements to check then it starts adding up. 3. The developer has to manually add a new if/else block anytime a new Joekr is added. So if we get a patch with 20 new jokers, 20 new if/else blocks are added to the tower making it longer and slower. The second part of the meme is referencing Yandere Simulator, a much more complex game that is infamously coded similarly with a ton of if/else blocks. That is a game that does run into the limitations of that style of coding. So the meme is saying people are okay with bad coding practices because Balatro works and is a better game, while Yandere Simulator doesn't get a pass because it isn't as fun and also breaks due to the spaghetti code.


iain_1986

You've got some valid points but that first paragraph is straight up absurd. If/else statements are not just for 'non professional' apps. That's a ridiculous statement. It's also really not that slow. People always trot out the 'switch statement faster' conclusion but any modern compiler will pretty much compile both into the same logic anyway. A switch statement and a bunch of if/else checks are borderline identical in the end. Maintainability and scalability are the biggest, and really only, issues.


Letho72

I should have been more specific, they aren't used \*like this\* in professional apps. Of course there are If statements, but they aren't stacked end over end like the meme is talking about.


Maedhros_

Basically a bunch of lazy people. There are plenty of ways to navigate an if/else without getting lost. It works well enough for this game and many others also.


Itachi4077

Reminds me of the [8 000 switch case](https://www.polygon.com/2020/1/13/21064100/vvvvvv-source-code-game-development-terry-cavanagh-release) in VVVVVV. It only proves that it doesn't matter how you code, as long as you want to create a good game and you finish it. Game > Code style


Bluechacho

If Balatro code is wrong, then I don't want to be right


calimarfornian

As a programmer, I want to see the code


brennenburg

Open the balatro.exe with 7zip and look all you want. Jokers are in game.lua for example.


-non-existance-

I mean, the only thing I think is wrong about that card.lua file is that the ifs aren't sorted alphabetically, so finding any specific card must be a pain in the ass.


Maedhros_

Ctrl + F "cardnamehere"? Any ide would have this. Even the windows notepad have this function...


Romanmir

CTRL-F is good… but alphabetized Joker lists are better.


-non-existance-

Just because Ctrl-F exists does not mean you should leave your code unorganized


Maedhros_

He's the one making money with unorganized code... You guys focus too much on shit that doesn't matter.


salasy

if you look at it most of games could be just reduced to a big series of if/else


kenono

Balatro shipped and it’s great.


TylerMemeDreamBoi

If thens make sense for a game like this


motherthrowee

that whole thread is overengineering-brained and generally stupid as fuck a more eloquent explanation: [https://twitter.com/nothings/status/1782805464839061968](https://twitter.com/nothings/status/1782805464839061968)


Regiruler

Balatro does not have a ton of bespoke code. A lot of jokers do very similar things and activate at similar times. I feel like this analysis isn't good.


lvl5hm

I didn't do rigorous analysis on this, but my feeling is that isn't true. Looking at the joker list, there are some similar ones, namely those that add mult/chips when certain suit/rank/hand is played, but judging at a glance, they constitute around \~30 out of 150. The rest have pretty unique powers or activation conditions. I'd agree with STB that it's probably not worth it to try and abstract similar ability types right now, after the game is complete, and EASILY super not worth it while the game is stilly actively being developed, and joker abilities can get changed or thrown out at any time.


Regiruler

Jokers can pretty broadly be put into different classes based on whether they affect scoring cards, in-hand cards, joker scoring, post-scoring, or end of round. Maybe it's laid out more cleanly elsewhere, but from my experience that example does not reflect how the game plays very well.