Why would you use Lua for your scripts?

I am wondering why every Script I come across is written in Lua instead of Javascript or C# when the advantages of those languages are obvious.

What is the reason you use Lua for your script?

People use it because it’s easy to learn, you don’t have to mess around with things like building c# or bundling typescript and because people are braindead and can’t understand the concept of runtime overhead so they see C# / V8 resources with seemingly higher usage on the resource monitor and go hurr durr bad script lua good

Why do you use C# or Javascript? exactly, my point.

People enjoy using LUA and as stated above it’s easy to learn, you may use C# or Javascript because you know how to ‘code’ in them languages where others don’t.

Simple really, why even ask?.

I am asking because I see huge drawbacks for Lua and I wanted to know if there is any other reason next to “easy to learn”.

me like lua
lua like me
why:
create thread(function() print (‘s’) end

2 Likes

This really reminds me of another done-to-death variation on this topic like, uh:

One answer is simple: Lua is meant to be embedded in other environments. The other languages supported, less so, so you will often encounter edge cases with the way they are integrated. Similarly, Lua has a lot less complexity involved, less boilerplate required, and the runtime is much easier to customize (e.g. the vector logic).

2 Likes

This is kinda the answer I was hoping for. I have never worked with lua and all I can see on first glance is that its painfully slow and absolutely horrifying if you want to use it in more than one file because you have no Compiler checking like in other languages. Can you give an example for the advantages with vector logic? I could not find anything clarifying on Google.

I mean…

LUA isn’t really ‘slow’ from what i’ve experienced just optimize your code i guess :person_shrugging:

image

Lua itself is absolutely not slow at all. It is actually really fast, especially if you know how to optimize it.
What makes it “slow” is when you start calling a lot of natives in a single frame. Calling natives always comes with a slight overhead since they need to call the actual functions from GTA/FiveM.
Reduce the amount of natives and you will continuously get scripts with 0.00ms usage even with while(true) loops.

There are a lot of resources out there about Lua and you can learn a lot about it. You can even go full “OOP” using metatables if that is your preferred way of programming. (I use it too in one of my resources)

And I think the main point is that everyone is using Lua. It is extremely easy to tell your customers / downloaders to edit something inside of your resources even if they have Zero prior knowledge of programming.
Try explaining them how to compile a C# resource.

As for the vector logic, I think d-bubble meant that they could just easily exchange the default x,y,z values in natives with a single vector3 without having to rewrite a whole lot of natives. In C# this is not the case and someone had to write a whole lot of wrapper functions manually. Those wrapper classes also need to be updated everytime a new patch hits with new functions (or don’t even include all possible functions yet).

Vectors automatically expand most of the time (there are some natives it wont work on because of compatibility issues)

--  would return a vector3
local playerCoords = GetEntityCoords(PlayerPedId())
-- this is useful because we can just use the vector for natives
-- we can also just pass it along (and add another vector too)
SetEntityCoords(PlayerPedId(), playerCoords + vector3(0, 250, 0))

While in TS/JS (same for C# but it has wrappers) you would have to do something like:

-- Returns an array instead
let [x, y, z] = GetEntityCoords(PlayerPedId());
y += 250;
SetEntityCoords(PlayerPedId(), x, y, z);

You can get around this with a wrapper, but that comes at the cost of an increased bundle size, and you still won’t be able to change how adding & shit works, you have to use methods instead

const ped = Game.PlayerPed;
const pos = ped.Position;
ped.Position = pos.add(new Vector3(0, 250, 0))