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: Efficiency Help

Previous Thread :: Next Thread 
pwnion is not online. pwnion
Joined: 03 Jan 2017
Total Posts: 117
11 Feb 2017 04:55 PM
This bit of code is just a test for the new game I'm working on and it works beautifully, however it just seems a bit repetitive when I was typing it. Is there any way I could make this more efficient?

local uis = game:GetService("UserInputService")
local one = true
local two = false
local three = false
local four = false

uis.InputBegan:connect(function(Key)
if Key.KeyCode == Enum.KeyCode.One and not one then
one = true
two = false
three = false
four = false
print("1 selected")
elseif Key.KeyCode == Enum.KeyCode.Two and not two then
two = true
one = false
three = false
four = false
print("2 selected")
elseif Key.KeyCode == Enum.KeyCode.Three and not three then
three = true
one = false
two = false
four = false
print("3 selected")
elseif Key.KeyCode == Enum.KeyCode.Four and not four then
four = true
one = false
two = false
three = false
print("4 selected")
end
end)
Report Abuse
pwnion is not online. pwnion
Joined: 03 Jan 2017
Total Posts: 117
11 Feb 2017 05:01 PM
Any help here? I just wanna keep my code clean.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
11 Feb 2017 05:02 PM
local uis = blah
local keycode = Enum.KeyCode
local keys = { [keycode.One] = true, [keycode.Two] = true, [keycode.Three], true, [keycode.Four] = true} -- keys that can be "selected"
local selected = keycode.One

uis.InputBegan:connect(function(inp)
if keys[inp.KeyCode] and selected ~= inp.KeyCode then
selected = inp.KeyCode
end
end)
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