I am an experienced programmer but can’t find any way to shorten this piece of code, probably because I REALLY need to get to sleep right now
UIS.InputBegan:Connect(function(input,gameProcessed)
if gameProcessed then return end
if input.KeyCode == Enum.KeyCode.E or input.KeyCode == Enum.KeyCode.Q or input.KeyCode == Enum.KeyCode.R or input.KeyCode == Enum.KeyCode.C or input.KeyCode == Enum.KeyCode.X or input.KeyCode == Enum.KeyCode.F or input.KeyCode == Enum.KeyCode.G or input.KeyCode == Enum.KeyCode.V or input.KeyCode == Enum.KeyCode.B then
checkKey(input.KeyCode.Name)
end
end)
local keys = {
"E",
"Q",
"R",
"C",
"X",
"F",
"G",
"V",
"B"
}
UIS.InputBegan:Connect(function(input,gameProcessed)
if gameProcessed then return end
if table.find(keys,input.KeyCode.Name) then
checkKey(input.KeyCode.Name)
end
end)
To furtherly enrich this idea (at least visually):
local keys = {"E", "Q", "R", "C", "X", "F", "G", "V", "B"}
UIS.InputBegan:Connect(function(input, gameProcessed)
if gameProcessed then return end
local keyCodeName = input.KeyCode.Name -- optional variable; just for readability
if table.find(keys, keyCodeName) then checkKey(keyCodeName) end
end)
Eh Tomato (american) Tomato (british) same thing. But:
UIS.InputBegan:Connect(function(input, gameProcessed)
if not gameProcessed and table.find({"E", "Q", "R", "C", "X", "F", "G", "V", "B"},input.KeyCode.Name) then checkKey(input.KeyCode.Name) end
end)
Yes! I like it! If we throw the readability out of the window we may get even more creative:
UIS.InputBegan:Connect(function(input, gameProcessed)
if not gameProcessed and table.find({"E", "Q", "R", "C", "X", "F", "G", "V", "B"},input.KeyCode.Name) then checkKey(input.KeyCode.Name) end
end)
Or, in an extremely inhumane (even cruel) way:
UIS.InputBegan:Connect(function(input, gameProcessed) if not gameProcessed and table.find({"E", "Q", "R", "C", "X", "F", "G", "V", "B"},input.KeyCode.Name) then checkKey(input.KeyCode.Name) end end)