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
|
  |
| 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
|
  |
| 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 |
|
|