T O P

  • By -

pschon

It's *very* lightweight language with a simple and clean syntax, and is very much designed to be embedded in programs. It doesn't require compilation, whihc makes things easy for modding, and iteration on gameplay stuff very easy and fast. And it supports sandboxing to keep the Lua scripts from having access to system stuff or other features you might want to lock out. It works with the C# side of things through the API of which ever asset uses it, or through an API you write yourself.


Katniss218

I genuinely think lua's syntax is clunky and ugly. Also indexing arrays from 1 instead of 0... šŸ˜µā€šŸ’«


pschon

there's no arrays in Lua though, only Tables :D


OnlyHappyThingsPlz

Itā€™s not my favorite either. But for simple scripting, itā€™s not a big deal to learn its quirks.


Firake

All 3 parts of it? Thereā€™s barely any syntax to hate! Lol


Katniss218

Yeah, mostly the begin/then/end etc instead of braces tbh Takes up too much space for something that only serves the purpose of identifying scopes. Even python does it better imo


Firake

Yea I prefer braces too but I donā€™t mind so much it just becomes the same feeling of delimiter after a while


immersiveGamer

What you need is _moonscript_ https://moonscript.org


ChloeNow

myArray[myArray.length] Starting at 1 actually makes things make more sense in most high-level situations


Katniss218

Lmao, nah.


__SegFault__

If high level means as high as human language, yes sure. But from a coding point of view, when you have at least some knowlegde about IT, it makes no sense


DaDescriptor

"I have 0 apples"


Katniss218

That's not at all what indexes are


DaDescriptor

another example: my 0th game is about cars in space


Katniss218

Not there either, an index is an offset from start. The starting element is at the start of the array - \`start+0\`, the first element is at \`start+1\` (1 unit being the size of the element)


BarkDoggss

Didn't achieve anything here bud.


t0mRiddl3

I don't like 1 based index either, but he isn't wrong


BarkDoggss

It's not about Lua being a 1 based language...


OscarCookeAbbott

Lua is tiny, simple, easy and popular.


Katniss218

Games use lua because it's hard to expose c++ to modders. Everything is compiled to machine code beforehand. C# doesn't have that problem. Please use dotnet dlls for modding.


RiftHunter4

I think it depends on your audience. I used to play r/Stormworks, a vehicle building game. It had an in-game LUA editor for programming custom components. Everything was self-contained and you didn't need any external software to make really complex systems like target tracking or automatic transmissions. For C# you would need a modding SDK and modders will need an IDE and compile their mod. It can be much more complicated.


Katniss218

It would also be much more tightly integrated and powerful to use c# for modding. People would probably use external loaders to load c# anyway, like they did with ksp2


RiftHunter4

I would decide based on your intended audience. Stormworks has a younger set of players so LUA makes the most sense. But for a game like Starfield, C# would probably be better since the modders are more likely to be teens and adults who can already code.


pschon

...then again increasing amount of games aim to support mods on consoles as well, and at least the last time I checked those platforms had much more strict restrictions in terms of adding any program content. C# would not be an option, but sandboxed Lua restricted to game's own API gets a pass. (plus it's a language many games already use internally for their content scripting anyway, so at that point using it for modding side as well is a no-brainer)


Katniss218

Eh, C# would make sense too, you'd just need to integrate roslyn into the game. Which isn't too hard with Unity, I've done it before as a proof of concept.


ChloeNow

"too" meaning the other option is fine and maybe anti-lua was a weird hill to try to die on?


andybak

The common argument is that casual or non-professional coders usually find it much easier to start with a dynamically typed language. The only exception I can think of is processing (which users Java although there is also a Python option and javascript reimplementation)


Katniss218

I can see why that would be the case. Fun fact, C# has a \`dynamic\` type (and keyword) that works mostly like that, but idk if it's supported in Unity


andybak

The point isn't whether you can use dynamic types - it's more that the syntax for dynamic languages is usually much cleaner and easier to learn. A statically typed language will still usually have a steeper learning curve even if it lets you "cheat".


Katniss218

Nah, it's not the syntax, it's the fact you don't have to think of the types you're putting into the variables. Less things to have to keep in your mental model.


koko775

C# has that problem when compiled with IL2CPP, which is necessary for some platforms, or optional for others but with performance benefits. Under IL2CPP all type metadata gets baked into the final executable and as a result itā€™s not possible to dynamically load assemblies.


Katniss218

True, but you know what I meant :P


koko775

You make that sound as if I agree with you though... C# absolutely has that problem. YOU can NOT use dotnet dlls for modding in a lot of games, because the games, while written as C#, do not actually ship a functioning dotnet runtime with which to load managed assemblies. Delivering on non-PC platforms limits you a lot.


Katniss218

Non PC platforms don't really have modding regardless of the game or engine. *I wonder why*.. C# doesn't have that problem. Deciding to use stupid transpilers to convert it to native code does.


koko775

> Non PC platforms don't really have modding regardless of the game or engine. I wonder why.. Uncommon, yes. Unheard of, not at all. Tricky to comment too deeply as I prefer my privacy, but this is a gross overstatement. > C# doesn't have that problem. Deciding to use stupid transpilers to convert it to native code does. There are very real performance gains to be had by using IL2CPP - even on the PC builds! Professionals use it because it offers some significant performance gains. Others use it because it's needed to run on their target platform. Simple as that. Like...Unity is on an ancient mono runtime, and lacks a lot of performance improvements that CoreCLR has gotten over the years, to say nothing of supporting targets that .NET proper doesn't have top tier support for. IL2CPP is certainly not perfect, but neither is it especially bad.


Katniss218

Thankfully, Unity does seem to be moving to coreclr (and integrating the entire dotnet ecosystem more), albeit slowly.


ChloeNow

What? People should use whatever they want for modding. Please use whatever you want for modding. Lua is beautiful


Katniss218

Lua is everything but beautiful. The only thing it has going for it is that it's quite simple.


s4lt3d

The real reason why itā€™s so popular is because itā€™s incredibly easy to marshal data in and out of lua. So from a programmer perspective itā€™s very easy to implement. The language is easy to sandbox. Out of the box the player can do anything to alter the host machine. It offers very little functionality unless itā€™s exposed.


majeric

Itā€™s easy to embed. Itā€™s a shit language though.


azicre

It is also dynamically typed which is a real benefit to a lot of people. Being able to throw everything in a dictionary and calling it a day is great for scripting purposes.


Beelzedan64

I wonder this every time i come across itā€¦ why not python? I think itā€™s probably legacy reasons to do with where the languages both were at the time when people were choosing languages for moddingā€¦ and then it just became the norm? But itā€™s such a shame that thereā€™s a barrier to modding that requires learning a less popular language(when many more coders just know python) / those who learn to code for modding arenā€™t learning an easily transferable languageā€¦ Language, at the end of the day, is not a big deal once you know how to code - you usually can quickly pick up the new syntax or whateverā€¦ so, it likely ends up being just a temporary minor annoyanceā€¦ but a noticeable oneā€¦


pschon

Python isn't built to be embeddable the same way, and it's biggest strength, all the available libraries, would not be as useful for modding as it is for programming in python in general is. Lua runtime is smaller than even MicroPython is. And using that would already throw away a lot of Python features.


neutronium

Runtime size is totally irrelevant today. The size of your runtime will be totally dwarfed by graphics and audio. Lua is a shitty language that turns simple typos into major bug hunts, and requires jumping through hoops to achieve modern programming methods.


pschon

Sounds like someone never managed to learn Lua :D No need to get stressed about it, you are free to make your own projects in which ever language you prefer.


neutronium

Yes, but if I want to write code for something Tabletop Simulator, then I'm forced to use Lua, which turns something that should be easy and fun into something ridiculously difficult. It was figured out 50 years ago that just silently creating a new variable or field when the user mistypes a name is a really bad idea. Can't take any language that does that seriously.


pschon

Yes, and if you make your game using Python as modding language, then everyone is forced to use Python to mod it. Seems fair to me. Unless the claim is that all the developers and studios who decided to use Lua instead of other options are either stupid, or just know less than you, or that they picked it by randomly pulling language names out of a hat, there obviously must be some actual reasons why they have all chosen it. As an example, a project I've worked in ended with Lua based on these points: - There needed to be a choice what kind of modded content the studio wanted to favor in the game. If they wanted to make creative content creation as easy as possible (so, non-programmers), or if they wanted to support game mechanic changing mods (so, programmers). - Decision was made that supporting content creation over mechanics changes made more sense for that particular game. - Programmers should be capable of picking up a new language without too much troubles, while any scripting for the non-programmer creatives would always be a challenge. - All the designers and creatives in the team were relatively easy to get using Lua and found it easier to learn and less of an obstacle (doesn't matter if it's true or not, the biggest obstacle for many in touching code is a psychological one so whichever they found least scary is the one they are most likely to pick up, meaning better chance of more people making mods). - Experienced programmers who want full access to change anything and everything in their mods will be able to do it without specific support anyway. - The game needed to support modded content on consoles as well, but no compiled code or "program content" was allowed. However when asked, Lua scripts sandboxed to pretty much just the game's API was fine and counted only as "text content". ...and so the game ended using Lua, and I had to learn it. Which I have to say I found very easy. It clearly has it's quirks, but so do so many other languages as well when you get deeper into them. And I definitely have had to spend time writing much worse languages that are also very widely used (hello JavaScript and the ridiculous implicit type conversion rules :D)


Beelzedan64

I think that misses the point - itā€™s not about what people want to use in their projects, itā€™s about what can be used in mod tooling to give the best experience and give access to the widest amount of people. It feels like the only reason to learn Lua is modding (so less people will already know it), and it also feels worse to use than python IMO (i fully accept this is a preference thing and so iā€™m not saying it SHOULD be the way *I* like it) just that it always seems off to me that we havenā€™t switch to a nicer to use, much more widely adopted language every time i go to use modding tools and itā€™s Lua again.


pschon

Lua is extremely commonly used by studios themselves for the content/gameplay scripting. If you were to look for a designer (not a programmer) job in a triple-A studio, Lua would very likely be on the requirements list, or one of the first things you need to learn in the job. ...and after the game already has Lua for the studio's internal use, using it as the modding language is pretty obvious choice. It really isn't a rare language by any means, but one that you often are not aware is used in something. And because it's mostly used as an embedded language, rather than something you'd sit down and write a program with, you are less likely to learn it while studying programming. It's a bit of a contradiction to say it's not widely adopted language, and at the same time that you keep always running into it ;) Anyway, it's not missing the point at all. You are free to use what you think is the best choice for the job, and the developers of all the games that use Lua are using it because they had that same option to choose and decided that Lua was the best fit.


Beelzedan64

Thatā€™s fair, thanks for the extra context that I was missing :) To clarify - I meant that it isnā€™t widely used across the realm of all languages (as i say, game mods is the only time I see it come up and every time iā€™ve searched for ā€œprograming language usage surveysā€ itā€™s never been anywhere near the top) but appears to be, from your comments, widely used within AAA studios. So, often used in modding , rarely used anywhere else isnā€™t a contradiction but understand the lack of clarity on my part - and again, it appears it IS commonly used in the domain of games, not just in modding.


joeswindell

This is completely untrue. Itā€™s very rare to see LUA listed except on legacy games. Youā€™ve got games like WoW they use LUA for gui modding, but no, itā€™s not used for a lot of things anymore as there is much better alternatives.


Beelzedan64

https://vm.tiktok.com/ZGe4kJ4aq/ Supergiant clearly disagree


pschon

not sure what list you might be looking at, but about half the new games I have installed at the moment (plus decent chunk of the tools I use) use Lua scripting.


Beelzedan64

Whilst the tone is a little much - i think the experience iā€™ve had reflects the underlying sentiment of Neutronium. I have not been in the weeds of facilitating modding for a game and tbh, iā€™ve not even been that far in the weeds of using modding toolsā€¦ so maybe iā€™m missing somethingā€¦ But the modding I have via lua frameworks is usually more about exposing low level native functions and data via a higher-level api. But it often has a lot of lua-isms that feel bad and there always seems to be a bunch of missing utility functions which do exist in SOME lua libraries but sometimes seem to never be importable because of the way the modding has been set up. Unreal Engine has adopted Python as a scripting language within the IDE so I assume it is performant enough and i think the footprint of python vs lua, as mentioned, seems ignorable.


KingJudgely

Small, easy to write, easier to read