Professional controls/binding scheme

General discussion about LÖVE, Lua, game development, puns, and unicorns.
User avatar
Taehl
Dreaming in associative arrays
Posts: 1025
Joined: Mon Jan 11, 2010 5:07 am
Location: CA, USA
Contact:

Professional controls/binding scheme

Post by Taehl »

I've noticed that nearly all professional computer games offer the same scheme for binding controls: 2 sets of keys and an optional joystick, all configurable. Since I needed to overhaul Underlife's controls anyway, I thought I'd figure out how to recreate that scheme in Love. It ended up just being 33 lines of simple code (and allows both digital and analogue movement). Here's the resulting article: Professional controls
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Professional controls/binding scheme

Post by Robin »

Ehm, I have some problems with that. It is nice in principle, but things like:

Code: Select all

        for k,v in pairs(control.keys) do control[k] = control[k] or love.keyboard.isDown(v) end
        for k,v in pairs(control.keys2) do control[k] = control[k] or love.keyboard.isDown(v) end
are problematic. You see, once you press "jump" or whatever, it will stick. control["jump"] will become true, and if you release the key, you get control["jump"] = control["jump"] or false. And since control["jump"] was true, it remains true (true or false is true).

It also has some namespace pollution, which is a shame.

Lastly, the examples don't work: you forgot the function keyword as well as leaving out control.update().
Help us help you: attach a .love.
User avatar
Taehl
Dreaming in associative arrays
Posts: 1025
Joined: Mon Jan 11, 2010 5:07 am
Location: CA, USA
Contact:

Re: Professional controls/binding scheme

Post by Taehl »

It doesn't stick since the controls are reset to false at the beginning of each control.update(). It has potential namespace pollution since this is just an example which is meant to be tailored to a given game, not a standalone library. As for the examples: You're right, I forgot that. I'll fix it now.
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Professional controls/binding scheme

Post by Robin »

Taehl wrote:It doesn't stick since the controls are reset to false at the beginning of each control.update().
Oh, you're right, I didn't see that. Still ugly, since you'd need to change that in two places when you add controls.
Taehl wrote:It has potential namespace pollution since this is just an example which is meant to be tailored to a given game, not a standalone library.
I mean, you can't call a control keys, keys, joyaxes, joybtns or update. That's pretty arbitrary. And so easy and quick to fix.
Help us help you: attach a .love.
User avatar
kraftman
Party member
Posts: 277
Joined: Sat May 14, 2011 10:18 am

Re: Professional controls/binding scheme

Post by kraftman »

Taehl wrote:It doesn't stick since the controls are reset to false at the beginning of each control.update(). It has potential namespace pollution since this is just an example which is meant to be tailored to a given game, not a standalone library. As for the examples: You're right, I forgot that. I'll fix it now.
It would be nice to have something like

SetBinding("KEY_PRESSED", "w", JumpOrFly)
User avatar
Taehl
Dreaming in associative arrays
Posts: 1025
Joined: Mon Jan 11, 2010 5:07 am
Location: CA, USA
Contact:

Re: Professional controls/binding scheme

Post by Taehl »

Robin wrote:I mean, you can't call a control keys, keys, joyaxes, joybtns or update. That's pretty arbitrary. And so easy and quick to fix.
Sure I can. In my mind, a control is a thing a game system looks for ("jump", "run", "left"). An input is a hardware signal ("shift", "joybutton 0", "mouse coordinate"). Bindings links input(s) to control(s).
kraftman wrote:SetBinding("KEY_PRESSED", "w", JumpOrFly)
You could add such a function to my scheme with just a few lines of code. But I would much rather use control.key.JumpOrFly = "w".
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Professional controls/binding scheme

Post by Robin »

Taehl wrote:Sure I can. In my mind, a control is a thing a game system looks for ("jump", "run", "left"). An input is a hardware signal ("shift", "joybutton 0", "mouse coordinate"). Bindings links input(s) to control(s).
No, you don't understand. What I mean is, that you can't call a control "keys" or "update" or those other things. Because control["keys"] and control["update"] are already taken.

Modifying it to what it says below this line causes it to crash and burn.

Code: Select all

keys = { up="w", left="a", down="s", right="d", jump=" ", attack="lctrl", menu="escape", update="u" },
Help us help you: attach a .love.
User avatar
Taehl
Dreaming in associative arrays
Posts: 1025
Joined: Mon Jan 11, 2010 5:07 am
Location: CA, USA
Contact:

Re: Professional controls/binding scheme

Post by Taehl »

You can break /anything/ by changing a line the wrong way. Just don't do that.
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Professional controls/binding scheme

Post by Robin »

Taehl wrote:You can break /anything/ by changing a line the wrong way. Just don't do that.
The wrong way, yes. There was nothing wrong about my example.
Help us help you: attach a .love.
User avatar
T-Bone
Inner party member
Posts: 1492
Joined: Thu Jun 09, 2011 9:03 am

Re: Professional controls/binding scheme

Post by T-Bone »

There isn't really a big problem in what our TC is doing, but calling this "professional" seems like a bit too much when it has such relatively simple issues.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 9 guests