Hello, forum!
I just wanted to know the viability of letting the user write their own Lua scripts to control a character in-game.
What this means is their scripts would have to be able to talk to an entity in the game, and for challenge's sake I'd need to be able to limit what they can do with their scripts.
Anything to point me in the right direction would be greatly appreciated!
Some pointers wanted regarding user created content
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Some pointers wanted regarding user created content
It would probably be pretty hard to do this right, most importantly the fact that it is really hard to make a decent text editor in LÖVE. Other than that, it's a bit of setfenv, not very hard or complicated.
Help us help you: attach a .love.
Re: Some pointers wanted regarding user created content
Like robin said, a decent text editor is going to be rough to simulate inside LÖVE. You can make a simple one easily enough though. The popular minecraft mod ComputerCraft gets by with an extremely basic one. It's very similar to what it seems you're trying to accomplish.
Also, there is a sandbox page on the lua wiki if you're wondering exactly what modules/functions you might want to protect.
Also, there is a sandbox page on the lua wiki if you're wondering exactly what modules/functions you might want to protect.
Re: Some pointers wanted regarding user created content
I guess it's a good thing then that I don't plan to be providing an in-game editor for the scripts; I'm envisioning just reading scripts from files using basic file io (and it suits my goal perfectly).
Thanks a lot, I'll check out 'setfenv' as well as that sandbox page!
Thanks a lot, I'll check out 'setfenv' as well as that sandbox page!
Re: Some pointers wanted regarding user created content
One alternative is to scan the script files periodically and re-load them while running the game.
This way you can edit the script files from outside using Notepad++ or whatever and see the changes in-game.
This way you can edit the script files from outside using Notepad++ or whatever and see the changes in-game.
Re: Some pointers wanted regarding user created content
You could also use luasocket to provide simple webserver to upload your files right into the game.Frohman wrote:I guess it's a good thing then that I don't plan to be providing an in-game editor for the scripts; I'm envisioning just reading scripts from files using basic file io (and it suits my goal perfectly).
Thanks a lot, I'll check out 'setfenv' as well as that sandbox page!
My lovely code lives at GitHub: http://github.com/miko/Love2d-samples
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Some pointers wanted regarding user created content
That would be a rather ill-advised idea (unless everyone playing the game uses SELÖVE rather than vanilla LÖVE).miko wrote:You could also use luasocket to provide simple webserver to upload your files right into the game.
Help us help you: attach a .love.
Re: Some pointers wanted regarding user created content
Well I was less concerned with how to go about obtaining the scripts, more about how to run them and how to allow them to interact with the game (obtain certain values from the game and also pass back instructions).
Re: Some pointers wanted regarding user created content
Why? Assuming those would be run in sandboxed env anyway.Robin wrote:That would be a rather ill-advised idea (unless everyone playing the game uses SELÖVE rather than vanilla LÖVE).miko wrote:You could also use luasocket to provide simple webserver to upload your files right into the game.
My lovely code lives at GitHub: http://github.com/miko/Love2d-samples
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Some pointers wanted regarding user created content
I'd use a combination of callback functions and a few API functions for that (similar to the interface LÖVE exposes). For example:Frohman wrote:Well I was less concerned with how to go about obtaining the scripts, more about how to run them and how to allow them to interact with the game (obtain certain values from the game and also pass back instructions).
Code: Select all
function character.update(dt)
-- do stuff
if API.getMyCharacterX() > 10 * dt then API.goLeft(10 * dt) end
end
SELÖVE does more than a single sandbox. LÖVE provides more opportunities to break sandbox than you might think of, and it's probably better to rely on SELÖVE, since it's been around for a while and designed to work with LÖVE's internals. A simple sandbox is enough to prevent users from accidentally their own computer, but not enough to defend against malicious parties with access to a public distribution ground.miko wrote:Why? Assuming those would be run in sandboxed env anyway.Robin wrote:That would be a rather ill-advised idea (unless everyone playing the game uses SELÖVE rather than vanilla LÖVE).miko wrote:You could also use luasocket to provide simple webserver to upload your files right into the game.
Help us help you: attach a .love.
Who is online
Users browsing this forum: Google [Bot] and 4 guests