Forum > Coding >

[RELEASE] Lua Switch Case

Posts: 673

Threads: 30

Joined: Aug, 2020

Reputation: 6

Posted

Credits: https://stackoverflow.com/questions/37447704/what-is-the-alternative-for-switch-statement-in-lua-language 

I was testing some stuff on Lua, It's not fun but it's kind of entertaining lmao. Don't ask me why I'm still alive. I'm just sharing what I learned from Lua.

 

-- # Begin Switch Case # --

function switch(E)
	return function (L)
		for _, V in pairs(L) do
			if V[1] == E then
				V[2]()
			elseif V[1] == "default" then
				V[2]()
			end
		end
	end
end

function case(E)
	return function(V)
		return { E, V[1] }
	end
end

function default(V)
	return { "default", V[1] }
end

-- # End Switch Case # --

script.Parent.MouseButton1Click:Connect(function()
	switch(3) {
		case(1) {
			function() print(1) end
		},
		case(2) {
			function() print(2) end
		},
		default {
			function() print(3) end
		}
	}
end)
  • 0

eb_

Formally known as Shade

vip

Posts: 920

Threads: 4

Joined: Jun, 2020

Reputation: 44

Replied

https://cdn.discordapp.com/attachments/835886949683298317/857149648677240872/SwitchCases.jpg

switch cases poooooooooooo but ok 

  • 0

https://media.discordapp.net/attachments/1010636204225601659/1012865624797610044/sKQybOLT.gif

ecstacy_lxnny

fka as delta

contentCreator

Posts: 764

Threads: 69

Joined: May, 2021

Reputation: 95

Replied

Wait I thought u wrote ur last thread :Thinks:

  • 0

fka as delta

Posts: 114

Threads: 26

Joined: Dec, 2019

Reputation: 3

Replied

You said farewell and now your posting threads again :think:

  • 0

Know c# and trying to expand my knowledge in it.

Rep Goal [1,2,3,4,5,6,7,8,9,10]Rickrolled Talan2016 : https://cdn.discordapp.com/attachments/852018376368979974/852033650593497128/unknown.png

MINISHXP

minishxp

Posts: 813

Threads: 5

Joined: Jan, 2021

Reputation: 9

Replied

please don't

  • 0

hi123

Posts: 26

Threads: 1

Joined: Jul, 2020

Reputation: 4

Replied

oh my god yes this is EPIC.

  • 0

Just your casual femboy, I know a bit of C++ and Lua.
Thank you ImmuneLion318, Peyton_ and Helios for the rep! <3

"clearly you don't like being raped cause you always consent" - DeepPain

Posts: 797

Threads: 70

Joined: May, 2020

Reputation: 9

Replied

is it faster then an if statement or is just for concept

  • 0

Don't buy exploits its not worth it your gonna quit anyway

Taking accountability will help you excel in life

Posts: 673

Threads: 30

Joined: Aug, 2020

Reputation: 6

Replied

@ZaphireHacks its just a concept of having a "cleaner?" codes lol

  • 0

Users viewing this thread:

( Members: 0, Guests: 1, Total: 1 )