Some pointers wanted regarding user created content

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Frohman
Prole
Posts: 21
Joined: Sat Dec 08, 2012 12:32 pm

Some pointers wanted regarding user created content

Post 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!
User avatar
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

Post 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.
Help us help you: attach a .love.
User avatar
Kadoba
Party member
Posts: 399
Joined: Mon Jan 10, 2011 8:25 am
Location: Oklahoma

Re: Some pointers wanted regarding user created content

Post 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.
Frohman
Prole
Posts: 21
Joined: Sat Dec 08, 2012 12:32 pm

Re: Some pointers wanted regarding user created content

Post 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!
User avatar
ivan
Party member
Posts: 1911
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: Some pointers wanted regarding user created content

Post 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.
User avatar
miko
Party member
Posts: 410
Joined: Fri Nov 26, 2010 2:25 pm
Location: PL

Re: Some pointers wanted regarding user created content

Post 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.
My lovely code lives at GitHub: http://github.com/miko/Love2d-samples
User avatar
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

Post 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).
Help us help you: attach a .love.
Frohman
Prole
Posts: 21
Joined: Sat Dec 08, 2012 12:32 pm

Re: Some pointers wanted regarding user created content

Post 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).
User avatar
miko
Party member
Posts: 410
Joined: Fri Nov 26, 2010 2:25 pm
Location: PL

Re: Some pointers wanted regarding user created content

Post 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.
My lovely code lives at GitHub: http://github.com/miko/Love2d-samples
User avatar
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

Post 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.
Help us help you: attach a .love.
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 129 guests