“Código Lua” Respostas de código

Código do jogo da Lua

local grid = {
  { 11, 12, 13 },
  { 21, 22, 23 },
  { 31, 32, 33 }
}

for y, row in ipairs(grid) do
  for x, value in ipairs(row) do
    print(x, y, grid[y][x])
  end
end
Naughty Newt

Código Lua

-- PUT THIS IN A LOCAL SCRIPT
local UIS = game:GetService("UserInputService")
local switch = false

UIS.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.Keyboard then
		if input.KeyCode == Enum.KeyCode.F then -- replace "F" with key of your choice
			
			if switch == true then
				
                -- put what ever you want to happen when OFF
				print("Its off!")
				switch = false -- must keep this for it to work
			else
            
				-- put what ever you want to happen when ON
				print("Its on!")
				switch = true -- this also has to be here for it to work
			end
		end
	end
end)
Mohammed Hedia

Código Lua

-- Lua Basics
-- I made this because I'm bored.
-- 1. Variables
-- (1.1) Local Variables
local newVariable = "Something"
local newVariable2 = 1
local newVariable3 = true

-- (1.2) Global Variables
newVariable4 = "Insert text here"

-- 2. Tables
local newTable = {"Apple", "Pencil", "Eraser"}

-- 3. If Statement
if 1 + 1 == 2 then
  print("Cool, you didn't fail math.")
end

-- 4. for loops
for i = 1, 3 do
  print("Successfully looped " .. i .. " times.")
end

-- 5. While loops, break
local i = 1
while true do
  i = i + 1

  if i == 10 then
    break -- Basically exits the loop
  end
end

-- 6. Functions
local function newFunction()
	print("yes")
end
 
newFunction()

-- "n" and "n2" are parameters
local function addNumbers(n, n2)
  print(n + n2)
end

addNumbers(3, 4) -- prints 7

-- 7. varargs
function Plus(...)
    local result = 0
    for _, value in ipairs({...}) do
        result = result + value
    end
    return result
end
print(Plus(7, 5, 2, 5)) -- prints 19
print(Plus(1, 2, 3, 4, 5, 6, 7, 8, 9)) -- prints 45
Akari

Código Lua

-- While the code below IS lua, I think it's a bit hard to understand..-
-- Another way to do it, without confusing yourself, is just doing it like this:

local firstTable = {}

firstTable.Apples = "Apple"
firstTable.Bananas = "Banana" -- I'm adding new variables inside the table by using a dot,
-- Seperating themselves from the table, and the variable!
-- (A variable is something that can be used as a faster way to use values..
-- For instance, printing a string.)

print(firstTable.Apples, firstTable.Bananas)




-- IF YOU WANT TO DO IT FASTER vv


local secondTable = {}

secondTable.Apples = "Apples"
secondTable.Bananas = "Bananas"

local Apples, Bananas = secondTable.Apples, secondTable.Bananas
print(Apples, Bananas)
Opal

Respostas semelhantes a “Código Lua”

Perguntas semelhantes a “Código Lua”

Procure respostas de código populares por idioma

Procurar outros idiomas de código