How can I shorten this code

(prepare to bleach your eyes)

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)
2 Likes

how can i delete a post aaaaaaaaaaaa

1 Like
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)
1 Like

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)
1 Like

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)

Even shorter.

Saved 3 lines :>

1 Like

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)

I just saved 2 more lines :sunglasses:.

3 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.