Page 5 of 5

Re: Wiki Requests

Posted: Tue Aug 02, 2011 10:18 am
by T-Bone
Perhaps a tutorial on proper usage of multiple .lua files would be nice. All my knowledge comes from trial and error, and asking people on the forums here, and every once in a while I notice large gaps in my knowledge :neko:

Re: Wiki Requests

Posted: Tue Aug 02, 2011 10:45 am
by XQYZ
T-Bone wrote:Perhaps a tutorial on proper usage of multiple .lua files would be nice. All my knowledge comes from trial and error, and asking people on the forums here, and every once in a while I notice large gaps in my knowledge :neko:
It's basically do whatever you want, all there is is convention and personal preference. Lua itself doesn't care where you define your functions or your classes.

Re: Wiki Requests

Posted: Tue Aug 02, 2011 5:18 pm
by zohnny
I think a good system for both newbies and experienced users would be a sort of request system.

Users who think they are 100% proficient in a subject can put their name in one of the sections. When users hit a "request example" button, the experienced user will get an email or something saying that so-and-so has requested an example for this section. If nobody has applied for one section, if something is requested then all experienced users will get the email.

With this system, newbies can get the examples they need, and experienced members don't have to make an example for every section right off the bat.

Just an idea ;D

Re: Wiki Requests

Posted: Tue Aug 02, 2011 5:45 pm
by tentus
Request: joystick examples.

Here is the joystick class from my game Kurosuke:

Code: Select all

joystick = class:new() 

function joystick:init()
	self.pressed = {}
	self.password = 1
end

function joystick:update(dt)
	self.password = (self.password % 2) + 1		-- change the password each update, for use in cleaning
	for j=0, love.joystick.getNumJoysticks() do
		for h=0, love.joystick.getNumHats(j) do
			local direction = love.joystick.getHat(j, h)
			if direction ~= "" and direction ~= "c" then
				local key = "j"..j.."_h"..h.."_d"..direction
				self:check(key)
			end
		end
		for a=0, love.joystick.getNumAxes(j) do
			local direction = love.joystick.getAxis(j, a)
			if direction > .5 or direction < -.5 then
				direction = round(direction)	-- to keep it even between sticks and buttons
				local key = "j"..j.."_a"..a.."_d"..direction
				self:check(key)
			end
		end
	end
	for key, value in pairs(self.pressed) do		-- clean out hats that aren't being pressed any more
		if self.pressed[key] ~= self.password then
			self.pressed[key] = nil
		end
	end
end

function joystick:check(key)
	if self.pressed[key] == nil then
		scene:keypressed(key)
	end
	self.pressed[key] = self.password
end
It pains me to post such inelegant code. Does anyone have some good code that they could put up as examples on the wiki?

Re: Wiki Requests

Posted: Tue Aug 02, 2011 7:49 pm
by XQYZ
tentus wrote:It pains me to post such inelegant code. Does anyone have some good code that they could put up as examples on the wiki?
Imho if you want to handle Input correctly, then you should keep it more abstract, ie. handle keyboard, mouse and gamepad input in one separate class which can be accessed independently from you main loop/input function. Something like if InputManager:isActionButtonPressed() then and so on.

Re: Wiki Requests

Posted: Tue Aug 02, 2011 8:53 pm
by tentus
XQYZ wrote:
tentus wrote:It pains me to post such inelegant code. Does anyone have some good code that they could put up as examples on the wiki?
Imho if you want to handle Input correctly, then you should keep it more abstract, ie. handle keyboard, mouse and gamepad input in one separate class which can be accessed independently from you main loop/input function. Something like if InputManager:isActionButtonPressed() then and so on.
Input is handled based on which scene (gamestate) you're in. For example, the character select screen has a very different set of bindings than the main game, which is very different from the nogame screen. Within the scenes some of the input is passed on to specific objects based on relevance (for example, if a key or joystick is bound to a player control, the input is passed onto that player object).

Re: Wiki Requests

Posted: Fri Aug 05, 2011 8:57 pm
by tentus
Question: What is the proper way to note that a function is getting renamed? I'm thinking specifically about threads, since send will become set and receive will become get in 0.8.0.

Re: Wiki Requests

Posted: Fri Aug 05, 2011 9:00 pm
by bartbes
Using the oldin template in the old one and the newin in the new one.
Another option might be moving the page to the new one, leaving a link in place then list both (with oldin and newin).

Re: Wiki Requests

Posted: Tue Sep 27, 2011 2:10 pm
by tentus
Hello, thread necromancy, how have you been?

Since I noticed that love.update had no examples, I've been going through some of the more commonly used functions on the wiki and adding more practical examples (not just the function being called, but it being called in a quasi-useful way). I've also been adding more See Also links, such as love.mouse.isVisible‎ to love.mouse.setVisible‎.

My point is, if anyone wants to pitch in, please do. My example-writing skills are pretty poor, and there are plenty of functions I've never even used (love.thread, I'm not looking at you). Having some more experienced Lovers than me working on the wiki would be a good thing.