amanda
|
  |
| Joined: 21 Nov 2006 |
| Total Posts: 5925 |
|
|
| 23 Apr 2015 10:02 PM |
Not overly-complicated. For those unfamiliar with UserInputService, here's a quick example of how it works:
The variable currentKey is set to nil.
You press 'B' on your keyboard. currentKey is set to Enum.KeyCode.B. 0.3 seconds later, currentKey is set to nil.
However, if you pressed 'B' again within that .3 second duration, it would detect that the key you are pressing is equivalent to the last key you pressed, and run my lovely print function.
Put it in a LocalScript in StarterGui, and test it out in Studio, try double-tapping. --
local UIS = game:GetService('UserInputService')
local players = game:GetService('Players') local player = players.LocalPlayer local character = player.Character or player.CharacterAdded:wait()
local currentKey = nil
UIS.InputBegan:connect(function(input, gameProcessedEvent) if input.KeyCode ~= Enum.KeyCode.Unknown then if input.KeyCode == currentKey then print('You double-tapped: '..currentKey.Name) else currentKey = input.KeyCode wait(.3) currentKey = nil end end end) |
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
| |
|
|
| 23 Apr 2015 10:04 PM |
local currentKey = nil
UIS.InputBegan:connect(function(input, gameProcessedEvent) if not gameProcessedEvent then if input.KeyCode == currentKey then print('You double-tapped: '..currentKey.Name) else currentKey = input.KeyCode wait(.3) currentKey = nil end end end)
bettr
I appreciate your attempt at humor |
|
|
| Report Abuse |
|
|
|
| 23 Apr 2015 10:04 PM |
RE:A meteorite will hit September/24/15
|
|
|
| Report Abuse |
|
|
amanda
|
  |
| Joined: 21 Nov 2006 |
| Total Posts: 5925 |
|
|
| 23 Apr 2015 10:08 PM |
@Devious
I intentionally didn't add that line because it is unnecessary in my testing.
Here's a pro-tip: Enum.KeyCode.I and Enum.KeyCode.O are gameProcessedEvents, and cannot be used to trigger stuff in UIS if you have that check. :)
All of my core GUIs are auto-disabled. |
|
|
| Report Abuse |
|
|
amanda
|
  |
| Joined: 21 Nov 2006 |
| Total Posts: 5925 |
|
|
| 23 Apr 2015 10:12 PM |
Note: The original code is purely experimental and should not be used in game development.
There are a few essential variables unaccounted for which make this unreliable for usage in active games.
This was simply a preliminary test to give myself an idea of how to check for it, however in future tests, it will be using an entirely different system. |
|
|
| Report Abuse |
|
|
iHin
|
  |
| Joined: 06 Apr 2014 |
| Total Posts: 407 |
|
|
| 23 Apr 2015 10:19 PM |
Nicely done. I have a few improvement ideas.
-𝒩 | iHin, Scripter |
|
|
| Report Abuse |
|
|