|
Tunicate posted:IIRC Lua doesnt' have a match statement or switch statement built in, right? Lua doesn’t even know what a constant is, so, yeah basically. But, you can very easily abuse its key/value table system to do more or less the same thing, if you’re trying to be more efficient.
|
# ? Apr 24, 2024 03:14 |
|
|
# ? Apr 27, 2024 03:44 |
yeah was gonna say, in lua your options are basically do the ten thousand line if-else, or do some really bonkers table magic poo poo.
|
|
# ? Apr 24, 2024 03:17 |
|
hailthefish posted:yeah was gonna say, in lua your options are basically do the ten thousand line if-else, or do some really bonkers table magic poo poo. “Table magic poo poo” is Lua’s major strength so I mean why the hell not.
|
# ? Apr 24, 2024 03:18 |
|
You can indeed do table magic poo poo, something likepre:match_table = { plus = function(x, y) return x + y end product = function(x, y) return x * y end } function fake_match(x, y, action) return match_table[action](x, y) end print(fake_match(2, 5, "plus")) print(fake_match(2, 5, "product"))
|
# ? Apr 24, 2024 04:40 |
|
All the data in Grimrock games was Lua table magic poo poo too and it was great. Being able to spice up data with the occasional function or defining objects in bulk with for loops for example is a nice luxury to have.
|
# ? Apr 24, 2024 06:03 |
|
If it works who cares how you did it? (Please never look at my code)
|
# ? Apr 24, 2024 08:54 |
|
Jabor posted:But it feels like a ton of boilerplate to write it that way when you're starting out with only a half-dozen cases, it's often easier to just start with something that works well at that small scale and then keep growing it. and once you have a pattern for how you add new content, it's way easier to stick to that pattern than it is to rearchitect everything. And, again, this is fine, it's a simple process, you know where to go to look up how something works. About the worst I can say about it is that it's hard to do comparisons of cards without a lot of scrolling around. The performance penalty of doing thousands of string comparisons every time a card needs to be scored is, honestly, negligible these days.
|
# ? Apr 24, 2024 12:28 |
|
Lua caches strings anyway, so the penalty for string comparison is already reduced as a language feature. LuaJIT is such a nice language.
|
# ? Apr 24, 2024 14:07 |
|
TooMuchAbstraction posted:About the worst I can say about it is that it's hard to do comparisons of cards without a lot of scrolling around. And if you end up needing that often enough, the pattern is simple enough that you move your data over to some other tool (like an Excel/Google Sheets spreadsheet), then write a really basic CSV importer that generates a string of that chain of ifs based on the data in the sheet, and you literally run it and copy paste the code in when you're done balancing the numbers. You can even automate it into your build pipeline.
|
# ? Apr 24, 2024 14:46 |
|
megane posted:You can indeed do table magic poo poo, something like It's weird to call this "magic table poo poo," since that implies to me that it's hacky/messy. It's the same as using a dictionary/hashmap of anonymous/lambda functions, which is extremely common in many languages. I do it all the time and it's a very normal alternative to giant if/else blocks. They don't need to be replaced if they aren't a problem, but this is pretty much the standard for how you would do it. Edit: My giant conditional blocks are implemented in shaders inside a critical loop that gets run hundreds of millions of times per frame and needs to be as optimized as possible. I use case statements Double edit: I'm not exaggerating. That case statement is evaluated up to 100 times per function per pixel and there can be up to 32 functions, so that's a worst case of ~26.5 billion evaluations per frame in 4k. Worst case can't really ever happen, but 100s of millions is common. It still runs at several hundred FPS on my 3090 (for now, until I bog it down with more poo poo). KillHour fucked around with this message at 15:30 on Apr 24, 2024 |
# ? Apr 24, 2024 15:01 |
|
Yep. One of the reasons Lua appeals to me it that it gives you one simple-yet-powerful tool, the table, and then you solve pretty much every problem by applying that one tool in clever ways. You can implement Sets by using tables "backwards," with the elements as keys and true/false as the values, for example. That's definitely a downside for many applications, but I enjoy it as a mental exercise.
|
# ? Apr 24, 2024 20:53 |
|
but it's 1-indexed! how am i supposed to use a language that's 1-indexed!!!
|
# ? Apr 24, 2024 21:04 |
|
In one of the legacy applications at work the previous dev suffixed every 0-indexed thing with _indexStartsAt0. As it's written in C#, it makes the source quite a thing to behold.
|
# ? Apr 24, 2024 21:39 |
|
Congrats on your employer coming up with a code standard that actually self documents!
|
# ? Apr 24, 2024 21:41 |
|
I appreciate how lean and elegant Lua is, but I haaaaate having to bring my own tools (and/or find and install others') to the party. I want a robust standard library that ships with the language.
|
# ? Apr 24, 2024 21:51 |
|
I always have handy this list of curated Love2D libraries for literally everything you can think of for Love2D/Lua gamedev. For objects, 'hump.class' or 'middleclass' are both good picks, and for asset management 'cargo' is pretty much the easiest way to pull in any file data for quick use.
|
# ? Apr 24, 2024 21:59 |
|
KRILLIN IN THE NAME posted:paging TWD to the thread the trombone champ background animations are built kinda like this for the same boneheaded reasons: each track having unique effects that couldn't easily be defined in a shared class, plus me being ignorant about a handful of coding fundamentals due to being self-taught edit: whoa! They deleted the tweet lol
|
# ? Apr 26, 2024 20:17 |
|
|
# ? Apr 27, 2024 03:44 |
|
This game I made just won ScoreSpace Choice on ScoreSpace Jam 29. Play on Itch: https://chrsgr.itch.io/gravoor-infinity Play on Newgrounds, with online leaderboard: https://www.newgrounds.com/portal/view/927101 So thats obviously very exciting for me lol. Check it out if you guys have a moment free.
|
# ? Apr 26, 2024 21:43 |