Page 3 of 3
Re: crowd sourced game - organizing files and objects
Posted: Sun Aug 19, 2012 5:25 am
by Roland_Yonaba
Code: Select all
function player.move(form,dt)
if form=='A' then formA.move(dt)
else formB.move(dt)
end
end
function love.update(dt)
...
player.move(player.form,dt)
...
end
Or am I missing something ?
Re: crowd sourced game - organizing files and objects
Posted: Sun Aug 19, 2012 5:36 am
by sanjiv
That works fine. I just wondered if there was a more elegant way to update the draw, update, and keypressed/keyreleased functions all at once. But this works fine. Potentially writing out each call-function for each form isn't that bad at all (5 or 6 of them?). I suppose this way is more transparent, and would be easier to read too.
Thanks.
-------------
EDIT: Just for the record, here's the other thing I was experimenting with
Code: Select all
function test.changeOption()
local o=menu.option
if o==1 then function test.draw() testA.draw() end
elseif o==2 then function test.draw() testB.draw() end
end
end
Basically, this went in the love.keypressed function, right after the menu.option changed. Essentially, I'm looking for a way in which members of "the crowd" can add in folders with new forms, and then easily hook those forms up into the core game. I wanted that to be doable in as few steps as possible.
Re: crowd sourced game - organizing files and objects
Posted: Sun Aug 19, 2012 6:08 am
by Roland_Yonaba
Well, if you have multiple similar functions, that have the same args, I suggest make something like:
Code: Select all
local var = ... -- a numeric value in this specific case
local tests = {}
tests[1] = function (...) -- blah --blah end
tests[2] = function (...) -- blah --blah end
...
tests[n] = function (...) -- blah --blah end
callback body {
if tests[var] then tests[var](...) end
}
So that you will no longer need to make multiple if-checks.
You can rewrite your
player.move and your
changeOptions functions a similar way.