Page 2 of 2

Re: Some pointers wanted regarding user created content

Posted: Tue Dec 11, 2012 4:40 pm
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?

Re: Some pointers wanted regarding user created content

Posted: Wed Dec 12, 2012 11:02 am
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