generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Here's some experimental double-tap code. [UIS]

Previous Thread :: Next Thread 
amanda is not online. 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 is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
23 Apr 2015 10:03 PM
good job
Report Abuse
DeviousDeviation is not online. DeviousDeviation
Joined: 28 Dec 2010
Total Posts: 9306
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
ShinyKillerSkiller is not online. ShinyKillerSkiller
Joined: 08 Feb 2015
Total Posts: 10
23 Apr 2015 10:04 PM
RE:A meteorite will hit September/24/15
Report Abuse
amanda is not online. 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 is not online. 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 is not online. 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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image