crowd sourced game - organizing files and objects

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.
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: crowd sourced game - organizing files and objects

Post 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 ?
User avatar
sanjiv
Citizen
Posts: 88
Joined: Mon Feb 27, 2012 5:11 am

Re: crowd sourced game - organizing files and objects

Post 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.
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: crowd sourced game - organizing files and objects

Post 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.
Post Reply

Who is online

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