how would I make a custom programming language in game for users to use?
sorry for no info
how would I make a custom programming language in game for users to use?
sorry for no info
Create your own language with keywords then make a compilator or something that check the script words by words and characters by characters and do actions that the script order to do
It’s actually very advanced, because you have to put : variables, functons and more
This is an advanced and difficult thing to do, but you will have to sort through strings (what they type) and figure out what they are wanting to do based on that.
Here is some documentation that should help you:
Creating a programming language is one of the most advanced things you can do, and it involves several steps (if you dont want to involve luau at all):
First, create a parser. It takes the text and transforms it into tokens. This allows you to ignore comments, and also makes writing the next step easier. For example, words like “for” and “while” get turned into a token, numbers like “2341” and “-24.5” get turned into constant tokens. Don’t forget expressions either. Stuff like “23+4/2”.
Now for the abstract syntax tree. You could skip this step, but it makes compilation much easier. The original Lua for example skips this. Construct a syntax tree with nodes, which establishes the structure of the code. It makes code generation in specific easier, since you can just go down the list.
If you want expressions to take into account order of operations, you need to use an algorithm for that.
Now for the final step of compilation: Code generation. You can either compile it into luau (at that point you might as well just use luau, please). Or make your own custom VM. Compile the code into its own bytecode, which can be executed by the VM.
I recommend you just don’t do this and sandbox luau code. Whatever code you make will always be slower than luau
if i were to use luau how could i run the scripts the players write?
Several loadstring modules exist. You can also use normal loadstring, if its on the server.
ok, how would i make custom default functions for my players such as, “MoveForward(10)”?
When loading the script, you can just attach those custom functions on top. Like this.
local myCode = "function moveForward(x) print(x) end "
loadstring(myCode+"moveForward(10)")()
How simple is your programming language? You might be able to use a much simpler custom language, so you don’t have to worry about sandboxing.
Excuse me if I sound a bit rude, Isn’t making a player run code on server dangerous? A bad actor may abuse and exploit this in any inappropriate way!
That’s what sandboxing is for. So they can’t access game or any service at all.
i think im just going to use luau
There is currently no way of sandboxing when using loadstring function.
EDIT: loadstring returns a function which we are calling, Therefore this function can access variables in parent scope, thus cant be sandboxed. May be they can replace another function in parent scope?
At that point they would have to use a module. Running it on a module on the client is better anyway.
I would suggest running it on client and also to obfuscate game’s client code a little bit so they cant overflow server with already present remote events. Maybe reviewing code through AI API like CHatGPT Api help sanitization of code?
Blocking game, workspace, Workspace, and any other global that somehow leads to accessing game should be possible on a module, so they don’t access the remotes at all.
I’m not a professional on loadstring modules so it might actually involve a bit more than most people would expect.
Uhm, How can we actually block using any global stuff, You know I told they can also replace other inner function inside script and call them from there, potentially bypassing that.
just overwrite all the global variables
You can, loadstring returns a function in which you set a new fenv of, and re-run the loadstring (setfenv)
Even the script
global?. I don’t think so, correct me if I am wrong.
script is a global. Anything you reference a value that is not referenced as a variable is a global; within global scope.