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

Re: Some pointers wanted regarding user created content

Post by Frohman »

Robin wrote:
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.
This seems like a perfect solution for the user side of things for me, how would I implement the workings for an API like that on the other side?
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:This seems like a perfect solution for the user side of things for me, how would I implement the workings for an API like that on the other side?
Ehm, how you would normally do it? If you want a queue rather than direct execution (maybe to prevent users from making all-powerful characters?), you would have things like:

Code: Select all

queue = {}
function API.goLeft(n)
    queue[#queue+1] = {"goleft", n}
end

actions = {}
function actions.goleft(n)
    player.x = player.x - n
end
function doaction()
   a = table.remove(queue)
   actions[a[1]](a[2])
end
Help us help you: attach a .love.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot], zingo and 0 guests