User Define keys in a game

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
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: User Define keys in a game

Post by Robin »

Why even use strings anyway? You could have replaced all those occurrences of "P1Left" etc. with P1Left etc., as you use those strings only as some sort of "references" to functions, for which you can use the function's name as well.
Help us help you: attach a .love.
User avatar
tido170
Prole
Posts: 13
Joined: Sat Dec 12, 2009 1:42 am

Re: User Define keys in a game

Post by tido170 »

it's because the user starts by selecting a player (P1 to P4) and an action (Right, Left, etc). The info is stored in the string and then the key he presses is binded to this.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: User Define keys in a game

Post by Robin »

tido170 wrote:it's because the user starts by selecting a player (P1 to P4) and an action (Right, Left, etc). The info is stored in the string and then the key he presses is binded to this.
I think it would then make sense to have a keyfuncs table with this layout:

Code: Select all

keyfuncs = {
    P1 = {
        Right = P1Right,
        Left = P1Left,
        (...)
        },
    P2 = {
        (...)
        },
    (...)
    }
This might be useful if you decide to change some function names.

... but on the other hand, this might not make any sense. Feel free to ignore me if that's the case. ;)
Help us help you: attach a .love.
Post Reply

Who is online

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