I’m working on a strategy game where users must script their units, they do not have direct control like in a classic RTS. I’d like to at least prototype this on Roblox because a lot of the components I need, syntax highlighting, a good code editor, gui elements, are available.
Eventually it will have its own language, but for now I think it’d be very easy to give users access to Lua. That requires some kind of sandboxing to limit users to controlling intended gameplay. So far I have read this thread on how to do that:
There’s a major complication in that I need to prevent players from freezing a script by getting stuck in an infinite loop, or just doing too many expensive things. I don’t know of any way of doing preemptive multitasking in Roblox, which would allow me to control this. Additionally, I’m curious if there are other sandboxing methods besides the one in that thread. A lot of these issues are fixable by using a different platform where I can directly modify the interpreter, but I really need to keep the initial prototyping cost down.
Let me know your thoughts.
This definitely solves the sandboxing requirements. Any idea how to prevent a script from freezing the game? Right now I can just execute “while true do end” and it will freeze until the default 10 second timeout. It will do this even if I wrap it in a task.spawn, because tasks use cooperative multitasking.
The best way to ultimately do this is to create your own instruction language
Like for controlling units your language could look something like
var marchDistance = 10;
units.march(marchDistance);
As you can see they are specific instructions, with variables to ensure there’s no funny business. I DO NOT RECCOMMEND letting any users execute code in your game at any point. Just give them an instruction system, whether it’s physical or drag-drop scripting.
I’m planning to do this and will have to do it if I can’t obtain what I’ve described. If its a little exploitable that could be okay for now as I’m only going to have a select set of people testing it.
Right now its usable but I have no way of stopping the obvious while true do end DoS. I tried using an Actor with task.desynchronize but it still freezes even in the allegedly “parallel” section.