-- [[ Admin Panel: Client Side ]] -- -- Variables -- Interface local adminPanel = script.Parent -- Frames local lightsFrame = adminPanel.Lights local doorsFrame = adminPanel.Doors local serverFrame = adminPanel.Server -- Buttons local lightButtons = lightsFrame.Buttons:GetChildren() local doorButtons = doorsFrame.Buttons:GetChildren() local serverButtons = serverFrame.Buttons:GetChildren() -- Remotes local actionRemote = game.ReplicatedStorage.actionRemote -- Properties local defaultProperties = { BackgroundTransparency = 1, } local selectionProperties = { BackgroundTransparency = 0.5, } -- Settings local originalLights = .8 local dimLights = .25 local offLights = 1 -- Functions -- Selection Highlighting local highlightButton(group, highlight) -- Grab all buttons for i = 1, #group, 1 do local selectBtn = group[i] -- Determine whether the button is suppose to be higlighted or not if selectBtn == highlight then -- If is, set highlight properties selectBtn = selectionProperties else -- If not, return to default properties selectBtn = defaultProperties end end end -- Events -- Doors for i = 1, #doorButtons, 1 do local selectButton = doorButtons[i] if selectButton:IsA("TextButton") then -- Ensure the button is a text button; avoid errors selectButton.MouseButton1Click:Connect(function() -- If clicked, begin event highlightButton(doorButtons, selectButton) -- Highlight button local doorsLocked = true -- Determine if the doors will be locked or unlocked if selectButton.Text == "Unlocked" then doorsLocked = false end -- Excute command actionRemote:FireServer("Doors", doorsLocked) end) end end -- Light Functions for i = 1, #lightButtons, 1 do local selectButton = lightButtons[i] -- Grab specific button if selectButton:IsA("TextButton") then -- Check to see if it is a button selectButton.MouseButton1Click:Connect(function() -- Click event listener highlightButton(lightButtons, selectButton) -- Highlight button local outcome -- Determine Outcome if selectButton.Text == "Dim" then outcome = dimLights elseif selectButton.Text == "Off" then outcome = offLights elseif selectButton.Text == "Original" outcome = originalLights elseif selectButton.Text == "Flicker" then outcome = "Flicker" end -- Execute command actionRemote:FireServer("Lights", outcome) end) end end -- Server Functions for i = 1, #serverButtons, 1 do local selectButton = serverButtons[i] -- Grab specific button if selectButton:IsA("TextLabel") then -- Ensure it is a TextButton selectButton.MouseButton1Click:Connect(function() -- Event listener: Clicker highlightButton(serverButtons, selectButton) -- Highlight button local serverLocked = true -- Determine outcome if selectButton.Text == "Unlocked" then serverLocked = false end -- Execute command actionRemote:FireServer("Server", serverLocked) end) end end
Write, Run & Share Lua code online using OneCompiler's Lua online compiler for free. It's one of the robust, feature-rich online compilers for Lua language, running the latest Lua version 5.4. Getting started with the OneCompiler's Lua editor is easy and fast. The editor shows sample boilerplate code when you choose language as Lua and start coding.
OneCompiler's Lua online editor supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample Lua program which takes name as input and prints hello message with your name.
name = io.read("*a")
print ("Hello ", name)
Lua is a light weight embeddable scripting language which is built on top of C. It is used in almost all kind of applications like games, web applications, mobile applications, image processing etc. It's a very powerful, fast, easy to learn, open-source scripting language.
-- global variables
a = 10
-- local variables
local x = 30
Value Type | Description |
---|---|
number | Represents numbers |
string | Represents text |
nil | Differentiates values whether it has data or not |
boolean | Value can be either true or false |
function | Represents a sub-routine |
userdata | Represents arbitary C data |
thread | Represents independent threads of execution. |
table | Can hold any value except nil |
While is also used to iterate a set of statements based on a condition. Usually while is preferred when number of iterations are not known in advance.
while(condition)
do
--code
end
Repeat-Until is also used to iterate a set of statements based on a condition. It is very similar to Do-While, it is mostly used when you need to execute the statements atleast once.
repeat
--code
until( condition )
For loop is used to iterate a set of statements based on a condition.
for init,max/min value, increment
do
--code
end
Function is a sub-routine which contains set of statements. Usually functions are written when multiple calls are required to same set of statements which increase re-usuability and modularity.
optional_function_scope function function_name( argument1, argument2, argument3........, argumentn)
--code
return params with comma seperated
end