Page 1 of 2

Some pointers wanted regarding user created content

Posted: Mon Dec 10, 2012 11:21 am
by Frohman
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!

Re: Some pointers wanted regarding user created content

Posted: Mon Dec 10, 2012 6:25 pm
by Robin
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.

Re: Some pointers wanted regarding user created content

Posted: Mon Dec 10, 2012 10:08 pm
by Kadoba
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.

Re: Some pointers wanted regarding user created content

Posted: Tue Dec 11, 2012 9:12 am
by Frohman
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!

Re: Some pointers wanted regarding user created content

Posted: Tue Dec 11, 2012 9:23 am
by ivan
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.

Re: Some pointers wanted regarding user created content

Posted: Tue Dec 11, 2012 9:37 am
by miko
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!
You could also use luasocket to provide simple webserver to upload your files right into the game.

Re: Some pointers wanted regarding user created content

Posted: Tue Dec 11, 2012 9:40 am
by Robin
miko wrote:You could also use luasocket to provide simple webserver to upload your files right into the game.
That would be a rather ill-advised idea (unless everyone playing the game uses SELÖVE rather than vanilla LÖVE).

Re: Some pointers wanted regarding user created content

Posted: Tue Dec 11, 2012 10:41 am
by Frohman
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

Posted: Tue Dec 11, 2012 11:12 am
by miko
Robin wrote:
miko wrote:You could also use luasocket to provide simple webserver to upload your files right into the game.
That would be a rather ill-advised idea (unless everyone playing the game uses SELÖVE rather than vanilla LÖVE).
Why? Assuming those would be run in sandboxed env anyway.

Re: Some pointers wanted regarding user created content

Posted: Tue Dec 11, 2012 4:21 pm
by Robin
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).
I'd use a combination of callback functions and a few API functions for that (similar to the interface LÖVE exposes). For example:

Code: Select all

function character.update(dt)
 -- do stuff
 if API.getMyCharacterX() > 10 * dt then API.goLeft(10 * dt) end
end
For instructions, you could run them directly or use a queue to execute the instructions the user code gives back later.
miko wrote:
Robin wrote:
miko wrote:You could also use luasocket to provide simple webserver to upload your files right into the game.
That would be a rather ill-advised idea (unless everyone playing the game uses SELÖVE rather than vanilla LÖVE).
Why? Assuming those would be run in sandboxed env anyway.
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.