Stencyl 3.4.0 is now out. Get it now!

Custom Controls Extension

captaincomic

  • *
  • Posts: 6109
Custom Controls Extension
This extension should work on every platform. I have only tested it on Flash, if you any issues with it let me know.

This extension provides blocks to change the game controls at runtime.
For example, to switch between arrow keys and WASD for movement. 

Download this Extension. (For instructions see How to Install and Update an Extension.)

You can change the keys of existing controls:

Or you can add additional keys:


To keep the key configuration between sessions, you can store the current configuration within a game attribute before saving the game.

Then the configuration can be restored after loading the game.


To get/apply the control config, you need Stencyl 3.1 or build >= b7140.

Usage Notes

set control [  ] to key with name: [  ]
Sets the key for the selected control (no other keys will be assigned to that control afterwards). The names of the keys are the same as the fields in the Keyboard class (i.e. all upper case).

add to control [  ] key with name: [  ]
Adds a key to the selected control (any keys that have been assigned to that control will still work afterwards).
The parameters are the same as for the previous block.

set control [  ] to key code: [  ]
Sets the key for the selected control (no other keys will be assigned to that control afterwards). Expects the key code instead of the key name. Use for example with the "key code" block from the "Any Key".

add to control [  ] key code: [  ]
Adds a key to the selected control (any keys that have been assigned to that control will still work afterwards).
The parameters are the same as for the previous block.

get control config
Returns a list containing all assignments of keys to controls. (It is an array of strings, where each string is in the form "control;key1,[key2,]...", but you don't need to care about that. ) Store this in a game attribute before saving the game if you want to keep the current controls.

apply control config [  ]
Use this to restore the controls to what they have been at the last save. Pass the list that you stored in a game attribute as the only parameter. (Don't pass anything else to this block, unless it has the same format.)

Version History
1.0 Initial version
1.1 Make the blocks green again (extension block now honor the color attribute :) )
1.2 Fix: some keys where not accepted; Add key code blocks.

« Last Edit: May 14, 2017, 11:30:56 am by captaincomic »

captaincomic

  • *
  • Posts: 6109
I updated the extension. It should work with all characters defined in the Keyboard class now.
And I added blocks to use the key code (for example from the any key event) directly.

MadManAdam

  • Posts: 371
Why hasn't anybody commented on this yet?!  This seems awesome!  Thanks Captaincomic.

deepshock

  • *
  • Posts: 18
This is really nice. In my opinion, all it's missing is the ability to get individual control items or key codes. Everything else is there. Well done!

Edit:

I've tested it with a control scheme for my game (on Windows) and it's been acting odd. Even with 'replace controls', it's adding controls to the list. It's also adding to list items other than the ones requested and adding dupe controls. Finally, it's adding Ctrl and Shift as distinct controls even when they aren't being asked for, and it has a peculiar order of displaying them.  These logs are the result of me mapping the same control repeatedly for each control, using the "set control" option, which is supposed to set and keep only one button for the control. It's a solid concept, but outside of Flash it has some major bugs. I'm confident in your ability to sort it out though. Best of luck!

Edit 2: "Add key (x) to control (y)" crashes consistently on windows, presumably at 'Keys.remove(keyCode);' Could a conditional is-not-null check be missing?

« Last Edit: November 18, 2014, 09:07:35 am by deepshock »

Minimo

  • Posts: 201
I can't get this installed on the Mac.

Did just what the docs say (and I've installed other extensions).
Went to Settings, Extensions, and 'Install Extension'.

Nothing happens when I try to install this file.  Closing and re-opening the game... no new extension is shown...

captaincomic

  • *
  • Posts: 6109
Minimo, the extension wasn't packaged right. It should now be possible to install it with that button.

deepshock, sorry, I didn't see your post before. If you still have troubles with this extension, let me know.

Minimo

  • Posts: 201
Captain,

thank you !  Installation = success.
In the process of integrating the extension into this game right now.
Everything is working perfectly so far.

Bombini

  • *
  • Posts: 752
Thanks for this awesome extension!
One question:
I want to let the player choose which key he/she wants to set for a control (lets say chooce any key for moving left).
How do i measure which key is pressed?

Something like "set control to key PRESSED KEY "
Is that possible?

Cheers!

Justin

  • *
  • Posts: 3699
The Input > Any Key event.

Quote from: captaincomic
set control [  ] to key code: [  ]
Sets the key for the selected control (no other keys will be assigned to that control afterwards). Expects the key code instead of the key name. Use for example with the "key code" block from the "Any Key".

add to control [  ] key code: [  ]
Adds a key to the selected control (any keys that have been assigned to that control will still work afterwards).
The parameters are the same as for the previous block.

For Live Support: Join our discord channel and ping me @justin.

Bombini

  • *
  • Posts: 752
Sorry, not my brightes day;)
Thanks a lot for the help.
Will implement!

Bombini

  • *
  • Posts: 752
Hi,
one more question which could also be relevant for others:
I am trying to build a "define your own controls" option:
  • The player can changes the controls to any key he/she presses
  • The keyname should be displayed when changing
This is what i have:


I did not find a way yet to get the name right away thats why i am using the "38 = UP" according to this list:
http://static.stencyl.com/api/31/types/flash/ui/Keyboard.html

Is there an easier way to get the name (to get UP right away instead of 38)?
Cheers!



Justin

  • *
  • Posts: 3699
com.stencyl.Key.nameOfKey(??)

Where I put ??, just put whatever code the key code block generates.

For Live Support: Join our discord channel and ping me @justin.

Donni11

  • *
  • Posts: 2118
Custom Controls Extension
This extension should work on every platform. I have only tested it on Flash, if you any issues with it let me know.

This extension provides blocks to change the game controls at runtime.
For example, to switch between arrow keys and WASD for movement. 

Download this Extension. (For instructions see How to Install and Update an Extension.)

You can change the keys of existing controls:

Or you can add additional keys:


To keep the key configuration between sessions, you can store the current configuration within a game attribute before saving the game.

Then the configuration can be restored after loading the game.


To get/apply the control config, you need Stencyl 3.1 or build >= b7140.

Usage Notes

set control [  ] to key with name: [  ]
Sets the key for the selected control (no other keys will be assigned to that control afterwards). The names of the keys are the same as the fields in the Keyboard class (i.e. all upper case).

add to control [  ] key with name: [  ]
Adds a key to the selected control (any keys that have been assigned to that control will still work afterwards).
The parameters are the same as for the previous block.

set control [  ] to key code: [  ]
Sets the key for the selected control (no other keys will be assigned to that control afterwards). Expects the key code instead of the key name. Use for example with the "key code" block from the "Any Key".

add to control [  ] key code: [  ]
Adds a key to the selected control (any keys that have been assigned to that control will still work afterwards).
The parameters are the same as for the previous block.

get control config
Returns a list containing all assignments of keys to controls. (It is an array of strings, where each string is in the form "control;key1,[key2,]...", but you don't need to care about that. ) Store this in a game attribute before saving the game if you want to keep the current controls.

apply control config [  ]
Use this to restore the controls to what they have been at the last save. Pass the list that you stored in a game attribute as the only parameter. (Don't pass anything else to this block, unless it has the same format.)

Version History
1.0 Initial version
1.1 Make the blocks green again (extension block now honor the color attribute :) )
1.2 Fix: some keys where not accepted; Add key code blocks.
Wow! Cool extension! I never noticed this extension. I really needed a extension like this , thanks for creating it :) !!!!
The Stencyl Discord Channel , Where the real Stencyl work happens ;).

Bombini

  • *
  • Posts: 752
com.stencyl.Key.nameOfKey(??)

Where I put ??, just put whatever code the key code block generates.

Thanks a lot for the help Justin, but i dont get it.
Do i put your line into a code block? And with what exactly do replace the ??
The "key code"?
How would that look like?

Justin

  • *
  • Posts: 3699
Sorry, I wrote that on my tablet right after waking up. I'll be more thorough. lol

Yeah, you put that line into a code block. Where I put the ??, it's the code equivalent of the [key code] block, which I wasn't sure of, so I used the "preview code" feature to find that out (see below).

Code: [Select]
com.stencyl.Key.nameOfKey(event.keyCode)

For Live Support: Join our discord channel and ping me @justin.