It really doesn't matter tbh. If you're making small scale shit like undertale, you can even use if else if you want to. It won't have any effect with performance.
What matters more with shit like this is code readability when working with other people or for debugging and again, if you're working alone like toby fox, it's not really a problem if you at least understand your own code you're typing. Sometimes simple shit like 1000+ switch cases is a lot easier to debug compared to making logic hierarchies that ultimately won't matter with the output.
The switch is actually fine but having all the game's dialogue formatted like that is kind of psychotic, making any alteration to the script would be a huge pain in the ass and localization would be a nightmare. Life would be a lot easier if the dialogue lived in its own data structure, or better yet was further separated based on location or character or whatever is intuitive to you
if there was only one developer and no localization efforts were needed you'd probably do a jump table like what the other posters said. This is a nightmare to make changes or localize, so otherwise you'd store data in a json file, for instance, acting as a database for text. You'd then read the dialogue from the file as needed
But before you even consider that, ask Optimally for what?
Run speed?
Load speed?
Memory load?
Readability?
Error checking?
Robustness?
Easy to Debug?
Expansion?
Flexibility?
Flexibility in branching?
Flexibility in dynamic decisions?
Maintainablility?
Ability to be worked on by some dumbass?
Time to code?
Yeah, multiple languages is going to be a pain in the ass.
lmao how the frick do you localize this
Line by line. And some of the dumb shit with localization might make more sense now.
optimally it looks like you releasing a finished product instead of something you slave over for years because nig/g/ers would find something to complain about and nitpick anyway.
are Black folk going to come in this thread and ramble about what would be the optimal way of doing that switch statement? lmao dude made bank with that shit
Shitcode isn’t shit if it works
But it only works for so long before you frick up something that actually matters, like GTAV parsing a 10 MB string 60,000 times and adding like 15 minutes to their load times
Just werks and is O(1). Am senior dev, if it works it's good code, only amateurs obsess over arbitrary rules Uncle Bob invented in his book.
>O(1)
It depends. The compiler might turn this into a jumptable and it might not. Worst case it's O(n), which in this case would still be fine. The actual problem with this code is how fricking hard it would be for anyone else besides Toby to work on it. At a glance I have no idea what "case 737" actually means. Which character? Which encounter? I have no clue.
He should have made a "dialogue" class with instance variables that point to a json file or something. Then every character could have an instance of the class as a component. Would make it much easier to write/change dialogue.
I'm not Ganker but isn't switch statements fine? I think it's only nested if statements that are moronic. How else are you even supposed to implement something that responds to hundreds of different cases?
Ifs are perfectly fine when utilized correctly, namely short checks *if* one thing fulfills a certain condition and returns whatever you might branch off with. Switches are best used when you're expecting exactly one thing to happen. The problem here is that Toby shouldn't have used if/else or switches for handling all the dialog in the game.
Even if this is decompiled code, it's a dogshit solution.
Its not about performance morons, its about maintainability, of course a short shitty game can get away with it, but in any serious project it will take exponentially more hours trying to change/update/localize any line the more lines you have
>script is stored in plain text >game loads the text file into a string variable when a new game begins >strings are pulled based on ID from within the stringvar'd file based on the string ID when you go to talk to someone >certain things like text box size and other things are also handled on a per-string basis in the event you need to shrink/expand them individually
Not my game, but a game I translated. I liked this setup a lot since it made the translation process quicker and easier than other alternative arrangements.
Anon you can put that file into excel and mark as '/' delineated to put it into a spreadsheet format. That's literally a spreadsheet file, and that is normally how that kind of thing is done for localization/configuration of things like that.
Don't tell me you did this all in .txt format? holy shit why
the trick is to store all your text in json or yaml and then perform adhoc translations by sending the level's text file to an LLM with the requested language
Did any of you armchair programmers even consider the fact that this shit could be generated code? You're looking at a very small snippet of a decompilation.
first they came for the if statements
now they're coming for my switch statements
how the frick am I supposed to check for a condition now bros
1000 layers of abstraction and overloading that no mere mortal can parse
if you aren't writing branch statements in assembly you aren't a real programmer.
any "real" programmer wouldn't be rotting in his room trying to make fricking videogames
I took a 4 year computer science degree in college and I think I never met a real programmer
What do they look like?
Checking for conditions is patriarchal. You need to build in consensus building daemons that go and poll POC and leave the decisions to them.
You’re supposed to use OOP
It really doesn't matter tbh. If you're making small scale shit like undertale, you can even use if else if you want to. It won't have any effect with performance.
What matters more with shit like this is code readability when working with other people or for debugging and again, if you're working alone like toby fox, it's not really a problem if you at least understand your own code you're typing. Sometimes simple shit like 1000+ switch cases is a lot easier to debug compared to making logic hierarchies that ultimately won't matter with the output.
jump table
Don't check conditions just use dynamic dispatch with virtual calls.
Store your dialogues in another file
Make half-assed projects in unreal engine for 10 years and never publish a game
It depends on the game but this is actually pretty clean way to make it as it's dialogue heavy game.
Good morning sir
your arrogance is showing
What should this look like optimally? I have no idea.
hashtable
>bloating with no advantage
The switch is actually fine but having all the game's dialogue formatted like that is kind of psychotic, making any alteration to the script would be a huge pain in the ass and localization would be a nightmare. Life would be a lot easier if the dialogue lived in its own data structure, or better yet was further separated based on location or character or whatever is intuitive to you
if there was only one developer and no localization efforts were needed you'd probably do a jump table like what the other posters said. This is a nightmare to make changes or localize, so otherwise you'd store data in a json file, for instance, acting as a database for text. You'd then read the dialogue from the file as needed
quick reference that looks like what I'd expect
You should not give a FRICK about optimally.
But before you even consider that, ask Optimally for what?
Run speed?
Load speed?
Memory load?
Readability?
Error checking?
Robustness?
Easy to Debug?
Expansion?
Flexibility?
Flexibility in branching?
Flexibility in dynamic decisions?
Maintainablility?
Ability to be worked on by some dumbass?
Time to code?
Yeah, multiple languages is going to be a pain in the ass.
Line by line. And some of the dumb shit with localization might make more sense now.
So basically to translate you need to actually publish a completely different game because the text is just hardcoded in like that
optimally it looks like you releasing a finished product instead of something you slave over for years because nig/g/ers would find something to complain about and nitpick anyway.
>your arrogance is showing
are Black folk going to come in this thread and ramble about what would be the optimal way of doing that switch statement? lmao dude made bank with that shit
Shitcode isn’t shit if it works
But it only works for so long before you frick up something that actually matters, like GTAV parsing a 10 MB string 60,000 times and adding like 15 minutes to their load times
It's still O(1), so it's fine brews trust me
>O(1)
It depends. The compiler might turn this into a jumptable and it might not. Worst case it's O(n), which in this case would still be fine. The actual problem with this code is how fricking hard it would be for anyone else besides Toby to work on it. At a glance I have no idea what "case 737" actually means. Which character? Which encounter? I have no clue.
He should have made a "dialogue" class with instance variables that point to a json file or something. Then every character could have an instance of the class as a component. Would make it much easier to write/change dialogue.
>dialogue heavy linear short game with gay characters that nags you for not being a good dog
>goty
why are gaymers like this
I'm not Ganker but isn't switch statements fine? I think it's only nested if statements that are moronic. How else are you even supposed to implement something that responds to hundreds of different cases?
the compiler fixes everything and trying to be clever is more likely to frick it up than anything
Ifs are perfectly fine when utilized correctly, namely short checks *if* one thing fulfills a certain condition and returns whatever you might branch off with. Switches are best used when you're expecting exactly one thing to happen. The problem here is that Toby shouldn't have used if/else or switches for handling all the dialog in the game.
Even if this is decompiled code, it's a dogshit solution.
in this case the "compiler" Toby used back in the day doesn't optimize switch statements, so it is in fact not fine
>Undertale is GOTY to zoomers
Games have fallen
Just werks and is O(1). Am senior dev, if it works it's good code, only amateurs obsess over arbitrary rules Uncle Bob invented in his book.
>setting array values by explicit index number
gross
lmao how the frick do you localize this
It's cool that you have to generate an executable for each translation
There are also games that never finish because the codebase is such a mess that adding new features to it is like pulling teeth.
Its not about performance morons, its about maintainability, of course a short shitty game can get away with it, but in any serious project it will take exponentially more hours trying to change/update/localize any line the more lines you have
Is a spaghetti mess? Yes but it's works and nobody gonna give some maintenance.
at the end of the day if the code works nobody gives a shit
>undertale
>"game of the year"
>script is stored in plain text
>game loads the text file into a string variable when a new game begins
>strings are pulled based on ID from within the stringvar'd file based on the string ID when you go to talk to someone
>certain things like text box size and other things are also handled on a per-string basis in the event you need to shrink/expand them individually
Not my game, but a game I translated. I liked this setup a lot since it made the translation process quicker and easier than other alternative arrangements.
Anon you can put that file into excel and mark as '/' delineated to put it into a spreadsheet format. That's literally a spreadsheet file, and that is normally how that kind of thing is done for localization/configuration of things like that.
Don't tell me you did this all in .txt format? holy shit why
I did it all in .txt format straight in Notepad++, yes.
I don't work on coomer games.
>I did it all in .txt format straight in Notepad++, yes.
Bro... Next time just convert it to a spreadsheet it's in the right format
how many gangrape scenes did you translate
any monkey can write code, but not everyone has it in them to be an auteur and actually make a game.
anyone can make an earthbound ripoff
If it works it works, I guess. I wouldn't want to work on a project like that. I'd at least separate dialog by level.
the trick is to store all your text in json or yaml and then perform adhoc translations by sending the level's text file to an LLM with the requested language
Did any of you armchair programmers even consider the fact that this shit could be generated code? You're looking at a very small snippet of a decompilation.
Good code wouldn't have string literals loaded at compile time
he's 100% right
>t. IT graduate doing hobby gamedev