Download new Custom Keys Plugin here

New releases and general discussions.

Post » Mon Jun 08, 2009 8:25 pm

hi all
I've created a Custom Controls plugin you can use for your games. To begin with, I will state that unfortunately, this does not work with built-in behaviors, but only for your own control and movement.
Now on to the good news...

[list:1ji99rbx]Features:

[*:1ji99rbx]Set up to 100 different controls for up to 10 players (total of 1000 controls)[/*:m:1ji99rbx]
[*:1ji99rbx]Allow players to change keys at runtime[/*:m:1ji99rbx]
[*:1ji99rbx]Save keys to a file and load them to individual players[/*:m:1ji99rbx]
[*:1ji99rbx]Saves key config files not easily readable in a text editor[/*:m:1ji99rbx][/list:u:1ji99rbx]


Now, before you try to use it, please read the tutorial below.
[color=#008000:1ji99rbx][size=150:1ji99rbx]download the plugin here[/size:1ji99rbx][/color:1ji99rbx]


[size=100:1ji99rbx][color=#008000:1ji99rbx]Download an example exe here[/color:1ji99rbx][/size:1ji99rbx]
[list:1ji99rbx][size=90:1ji99rbx][color=#008000:1ji99rbx][*:1ji99rbx]click the text of the control setting you want to modify (i.e. Left Mouse Button)

[/*:m:1ji99rbx][*:1ji99rbx]if you change the controls after clicking Save, clicking Load instantaneously loads your saved keys and sets them.[/color:1ji99rbx][/size:1ji99rbx][/*:m:1ji99rbx][/list:u:1ji99rbx]


[size=100:1ji99rbx][color=#008000:1ji99rbx]Download the example cap here[/size:1ji99rbx][/color:1ji99rbx][size=75:1ji99rbx] [color=#008000:1ji99rbx](saved in .99)[/color:1ji99rbx][/size:1ji99rbx]
[color=#008000:1ji99rbx][size=90:1ji99rbx](the tutorial below will help you to understand what you're looking at)[/size:1ji99rbx][/color:1ji99rbx]




first I will list the actions and expressions, and then explain how they are all used.


[list:1ji99rbx][color=#0000BF:1ji99rbx]Actions: [/color:1ji99rbx] [*:1ji99rbx][color=#0000FF:1ji99rbx]New Control[/color:1ji99rbx] (makes a new control for your game, such as "jump", or "move right". creates the control for all players)[/*:m:1ji99rbx]
[*:1ji99rbx][color=#0000FF:1ji99rbx]Set Key [/color:1ji99rbx](sets a key to your control)[/*:m:1ji99rbx]
[*:1ji99rbx][color=#0000FF:1ji99rbx]Save Key Config [/color:1ji99rbx](saves a key config to a file)[/*:m:1ji99rbx]
[*:1ji99rbx][color=#0000FF:1ji99rbx]Load Key Config[/color:1ji99rbx] (loads a key config from a file)[/*:m:1ji99rbx]
[*:1ji99rbx][color=#0000FF:1ji99rbx]Change Display String[/color:1ji99rbx] (allows you to change the default text to represent keys, like "F-12" instead of "F12", so you can decide what the player sees on your key config menu[/*:m:1ji99rbx][/list:u:1ji99rbx]

[list:1ji99rbx][color=#0000BF:1ji99rbx]Expressions:[/color:1ji99rbx]
[*:1ji99rbx][color=#0000FF:1ji99rbx]Get Control[/color:1ji99rbx] (Let's you check if the player is pressing one of their set controls)[/*:m:1ji99rbx]
[*:1ji99rbx][color=#0000FF:1ji99rbx]Get Control String[/color:1ji99rbx] (Returns a string with the name of the key set to a certain control, like "Tab", or "Left mouse button")[/*:m:1ji99rbx][/list:u:1ji99rbx]

on to the tutorial:

first unrar the plugins into construct's plugin directory. one will go directly into \plugins, the other will go into \plugins\runtime


1.when you open your construct project. add both the [color=#0000FF:1ji99rbx]Custom Keys[/color:1ji99rbx] Object and the [color=#0000FF:1ji99rbx]Mouse/Keyboard[/color:1ji99rbx] Object




2.At start of layout, add any controls you want in your game using the [color=#0000FF:1ji99rbx]AddControl[/color:1ji99rbx] action in [color=#0000FF:1ji99rbx]Custom Keys[/color:1ji99rbx]



3.In your game, you make your control editor menu. Decide when you want the player to press the key he is customizing.
Now this part might seem a little weird, but don't let it confuse you. you do the same exact thing every time, and after the next step, it all becomes very intuitive.

Add a [color=#0000FF:1ji99rbx]System Condition : For[/color:1ji99rbx], and set it up as displayed below; just set the "end" number to 89. I will explain the reasoning for this in the next step
[size=85:1ji99rbx][color=#804000:1ji99rbx](I know some screenshots show 1 to 89, but it should be 0 - 89, you leave the 0 alone. Will retake screenshots later)[/color:1ji99rbx][/size:1ji99rbx]








4.Next you add a subevent, [color=#0000FF:1ji99rbx]Mouse/Keyboard : On Key Pressed[/color:1ji99rbx],

instead of choosing a key from the list:
right click the word [color=#008000:1ji99rbx]key[/color:1ji99rbx] just above the list of choices and select [color=#008000:1ji99rbx]use expression[/color:1ji99rbx].
for the expression, simply type [color=#008000:1ji99rbx]loopindex[/color:1ji99rbx]

the reason you are doing this is because the [color=#0000FF:1ji99rbx]system:for[/color:1ji99rbx] loop is having the [color=#0000FF:1ji99rbx]mouse/keyboard[/color:1ji99rbx] function check whether the player pressed any of the 90 possible keys.
loopindex is the current key it's checking





5.Now you can set the keys by adding the [color=#0000FF:1ji99rbx]CustomControls : Set Key[/color:1ji99rbx] action:
[list:1ji99rbx][*:1ji99rbx]choose one of the controls you added in the start of layout,
[/*:m:1ji99rbx]
[*:1ji99rbx]choose a player to set it to,
[/*:m:1ji99rbx]
[*:1ji99rbx]and always type [color=#008000:1ji99rbx]loopindex[/color:1ji99rbx] for the key to set to.
remember, [color=#008000:1ji99rbx]loopindex[/color:1ji99rbx] is the key that you actually pressed.[/*:m:1ji99rbx][/list:u:1ji99rbx]


it will be easy to read in the event sheet which key was set and when:






6.Now for the fun part - where you're making the character move with your new controls.
You add a [color=#0000FF:1ji99rbx]mouse/keyboard : "On key pressed"[/color:1ji99rbx], or [color=#0000FF:1ji99rbx]"key is down" [/color:1ji99rbx]condition,
but instead of choosing a key from the drop down list.
Right click the word [color=#008000:1ji99rbx]key[/color:1ji99rbx] just above the list of choices and select [color=#008000:1ji99rbx]use expression[/color:1ji99rbx]. Now double click the custom keys icon to bring up the expression list:




7.The first parameter is the name of the control, the second parameter is the player number. So the condition in the screenshot above would trigger anytime [color=#008000:1ji99rbx]player 1[/color:1ji99rbx] pressed the [color=#008000:1ji99rbx]"jump"[/color:1ji99rbx] key




8.You may have noticed in step 6, there is another expression for [color=#0000FF:1ji99rbx]Custom Keys[/color:1ji99rbx] --- [color=#0000FF:1ji99rbx]Get Control String[/color:1ji99rbx]. This is to show the player what key they have set.
[code:1ji99rbx]ControlString(name of control, player number) [/code:1ji99rbx]
If player 1 would have set [color=#008000:1ji99rbx]jump[/color:1ji99rbx] to be the [color=#008000:1ji99rbx]Left mouse button[/color:1ji99rbx], then the action in the screenshot above would set [color=#0000FF:1ji99rbx]Text[/color:1ji99rbx] to [color=#008000:1ji99rbx]"Left mouse button"[/color:1ji99rbx].

But what if you wanted the text to say [color=#008000:1ji99rbx]"Mouse1"[/color:1ji99rbx], or [color=#008000:1ji99rbx]"LEFT MOUSE BUTTON"[/color:1ji99rbx], or [color=#008000:1ji99rbx]"lft ms btn"[/color:1ji99rbx]?
fortunately there is an action for that as well:


[color=#0000FF:1ji99rbx]change display string[/color:1ji99rbx]


9.[color=#0000FF:1ji99rbx]Change display string[/color:1ji99rbx] allows you to override the default string output for keys you get from the [color=#0000FF:1ji99rbx]Get Control String[/color:1ji99rbx] expression. First choose the key you want to override the string for, and then, input whatever string you wish.




10.And last, but certainly not least, there are the [color=#0000FF:1ji99rbx]SaveKeyConfig[/color:1ji99rbx], and [color=#0000FF:1ji99rbx]LoadKeyConfig[/color:1ji99rbx] actions.
Simply select a filename, and which player you want to save the keys from, or load the keys to. You can choose whatever file extension you wish, and the saved file is purposefully not easily readable in a text file. The start directory is the directory your game exe is in.

If you want to save a default key configuration, make your cap with your own key configuration menu. Make the cap save to [color=#008000:1ji99rbx]"default.keys"[/color:1ji99rbx] (for instance), then set the keys and save the cap, then change the cap so it no longer saves to [color=#008000:1ji99rbx]"default.keys"[/color:1ji99rbx], and make it load those keys whenever a user clicks a Set to Default button , and save new key configs to [color=#008000:1ji99rbx]"user.keys"[/color:1ji99rbx](or whatever). You can also setup several preset control schemes this way by saving several files [color=#008000:1ji99rbx]"Control Scheme A"[/color:1ji99rbx],[color=#008000:1ji99rbx] "WSAD walk"[/color:1ji99rbx], etc.


Have fun, please feel free to ask questions, and make suggestions. This plugin is free to use for whatever purposes you wish. I hope you find it useful
Spriter Dev
B
87
S
21
G
12
Posts: 3,240
Reputation: 16,461

Post » Mon Jun 08, 2009 9:30 pm

Wow thats a lot for your first plug.
Image Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767

Post » Tue Jun 09, 2009 12:06 am

uber useful
B
25
S
3
G
6
Posts: 1,197
Reputation: 5,620

Post » Tue Jun 09, 2009 3:14 pm

You are free to download and play with it
especially the exe, since it's no trouble to test out
but this plugin will soon be obselete,
I am making a version without as much awkwardness, that also let's you save and use xbox360 controls,

the xbox360 pad support is not the part I'm making, david just made a new xbox360 plugin, I'm just making it so you can save the controls
Spriter Dev
B
87
S
21
G
12
Posts: 3,240
Reputation: 16,461

Post » Tue Jun 09, 2009 3:39 pm

Congratulations on making your first plugin :)
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

Post » Tue Jun 09, 2009 4:12 pm

thanks!
this is not THE plugin btw, if you're wondering
that's still a whiles away
Spriter Dev
B
87
S
21
G
12
Posts: 3,240
Reputation: 16,461


Return to Construct Classic Discussion

Who is online

Users browsing this forum: No registered users and 3 guests