Lua - Reddit – Telegram
Lua - Reddit
31 subscribers
281 photos
31 videos
4.27K links
News and discussion for the Lua programming language.

Subreddit: https://www.reddit.com/r/lua

Powered by : @r_channels & @reddit2telegram
Download Telegram
need help with 2d to 3d transitioning

-- Game state
local gameMode = "2D"  -- Can be "2D" or "3D"
local player = {
    x = 100,
    y = 100,
    angle = 0,
    fov = math.pi / 3,
    speed = 100,
    turnSpeed = 2,
    radius = 10
}

-- Map and objects
local map = {
    {1, 1, 1, 1, 1},
    {1, 0, 0, 0, 1},
    {1, 0, 0, 0, 1},
    {1, 0, 0, 0, 1},
    {1, 1, 1, 1, 1}
}
local tileSize = 64
local objects = {
    {x = 200, y = 200, type = "glitch"}  -- Example glitchy object
}

-- Raycasting parameters
local numRays = 800  -- Number of rays to cast (higher = smoother)
local rayLength = 300  -- Maximum ray length

-- Load function
function love.load()
    -- Initialize resources
    love.window.setMode(800, 600, {resizable=false, vsync=true})
    love.mouse.setVisible(false)
end

-- Update function
function love.update(dt)
    if gameMode == "2D" then
        update2D(dt)
    elseif gameMode == "3D" then
        update3D(dt)
    end
end

-- Draw function
function love.draw()
    if gameMode == "2D" then
        draw2D()
    elseif gameMode == "3D" then
        draw3D()
    end
end

-- 2D Mode
function update2D(dt)
    -- Handle player movement
    if love.keyboard.isDown("w") then
        player.y = player.y - player.speed * dt
    end
    if love.keyboard.isDown("s") then
        player.y = player.y + player.speed * dt
    end
    if love.keyboard.isDown("a") then
        player.x = player.x - player.speed * dt
    end
    if love.keyboard.isDown("d") then
        player.x = player.x + player.speed * dt
    end

    -- Check for interactions with objects
    for _, obj in ipairs(objects) do
        if checkCollision(player.x, player.y, obj.x, obj.y, 16) then
            if obj.type == "glitch" then
                -- Trigger 3D mode
                gameMode = "3D"
                player.angle = 0  -- Reset angle for 3D mode
            end
        end
    end
end

function draw2D()
    -- Draw the 2D world
    love.graphics.setColor(0.2, 0.8, 0.2)  -- Grass
    love.graphics.rectangle("fill", 0, 0, love.graphics.getWidth(), love.graphics.getHeight())

    -- Draw objects
    for _, obj in ipairs(objects) do
        if obj.type == "glitch" then
            love.graphics.setColor(1, 0, 0)  -- Red for glitchy object
            love.graphics.circle("fill", obj.x, obj.y, 16)
        end
    end

    -- Draw the player
    love.graphics.setColor(0, 0, 1)  -- Blue for player
    love.graphics.circle("fill", player.x, player.y, 10)
end

-- 3D Mode
function update3D(dt)
    -- Handle player movement and rotation
    if love.keyboard.isDown("w") then
        player.x = player.x + math.cos(player.angle) * player.speed * dt
        player.y = player.y + math.sin(player.angle) * player.speed * dt
    end
    if love.keyboard.isDown("s") then
        player.x = player.x - math.cos(player.angle) * player.speed * dt
        player.y = player.y - math.sin(player.angle) * player.speed * dt
    end
    if love.keyboard.isDown("a") then
        player.angle = player.angle - player.turnSpeed * dt
    end
    if love.keyboard.isDown("d") then
        player.angle = player.angle + player.turnSpeed * dt
    end

    -- Keep player angle within 0 to 2*pi
    player.angle = player.angle % (2 * math.pi)
end

function draw3D()
    -- Draw the 3D-ish world using raycasting
    for i = 1, numRays do
        local rayAngle = (player.angle - player.fov / 2) + (i / numRays) * player.fov
        local rayDirX = math.cos(rayAngle)
        local rayDirY = math.sin(rayAngle)

        local rayX = player.x
        local rayY = player.y
   
    local distance = 0
        local hitWall = false

        while not hitWall and distance < rayLength do
            rayX = rayX + rayDirX
            rayY = rayY + rayDirY
            distance = distance + 1

            -- Check if the ray hits a wall
            local mapX = math.floor(rayX / tileSize) + 1
            local mapY = math.floor(rayY / tileSize) + 1

            if mapX >= 1 and mapX <= #map[1] and mapY >= 1 and mapY <= #map then
                if map[mapY][mapX] == 1 then
                    hitWall = true
                end
            else
                break
            end
        end

        -- Draw the first-person view (walls)
        if hitWall then
            local wallHeight = (tileSize * love.graphics.getHeight()) / (distance * math.cos(rayAngle - player.angle))
            local wallX = (i / numRays) * love.graphics.getWidth()
            local wallY = (love.graphics.getHeight() - wallHeight) / 2

            love.graphics.setColor(0.4, 0.4, 0.4)  -- Gray for walls
            love.graphics.rectangle("fill", wallX, wallY, love.graphics.getWidth() / numRays, wallHeight)
        end
    end
end

-- Helper function to check collision
function checkCollision(x1, y1, x2, y2, radius)
    return math.sqrt((x1 - x2)^2 + (y1 - y2)^2) < radius
end
-- Game state
local gameMode = "2D"  -- Can be "2D" or "3D"
local player = {
    x = 100,
    y = 100,
    angle = 0,
    fov = math.pi / 3,
    speed = 100,
    turnSpeed = 2,
    radius = 10
}


-- Map and objects
local map = {
    {1, 1, 1, 1, 1},
    {1, 0, 0, 0, 1},
    {1, 0, 0, 0, 1},
    {1, 0, 0, 0, 1},
    {1, 1, 1, 1, 1}
}
local tileSize = 64
local objects = {
    {x = 200, y = 200, type = "glitch"}  -- Example glitchy object
}


-- Raycasting parameters
local numRays = 800  -- Number of rays to cast (higher = smoother)
local rayLength = 300  -- Maximum ray length


-- Load function
function love.load()
    -- Initialize resources
    love.window.setMode(800, 600, {resizable=false, vsync=true})
    love.mouse.setVisible(false)
end


-- Update function
function love.update(dt)
    if gameMode == "2D" then
        update2D(dt)
    elseif gameMode == "3D" then
        update3D(dt)
    end
end


-- Draw function
function love.draw()
    if gameMode == "2D" then
        draw2D()
    elseif gameMode == "3D" then
        draw3D()
    end
end


-- 2D Mode
function update2D(dt)
    -- Handle player movement
    if love.keyboard.isDown("w") then
        player.y = player.y - player.speed * dt
    end
    if love.keyboard.isDown("s") then
        player.y = player.y + player.speed * dt
    end
    if love.keyboard.isDown("a") then
        player.x = player.x - player.speed * dt
    end
    if love.keyboard.isDown("d") then
        player.x = player.x + player.speed * dt
    end


    -- Check for interactions with objects
    for _, obj in ipairs(objects) do
        if checkCollision(player.x, player.y, obj.x, obj.y, 16) then
            if obj.type == "glitch" then
                -- Trigger 3D mode
                gameMode = "3D"
                player.angle = 0  -- Reset angle for 3D mode
            end
        end
    end
end


function draw2D()
    -- Draw the 2D world
    love.graphics.setColor(0.2, 0.8, 0.2)  -- Grass
    love.graphics.rectangle("fill", 0, 0, love.graphics.getWidth(), love.graphics.getHeight())


    -- Draw objects
    for _, obj in ipairs(objects) do
        if obj.type == "glitch" then
            love.graphics.setColor(1, 0, 0)  -- Red for glitchy object
           
love.graphics.circle("fill", obj.x, obj.y, 16)
        end
    end


    -- Draw the player
    love.graphics.setColor(0, 0, 1)  -- Blue for player
    love.graphics.circle("fill", player.x, player.y, 10)
end


-- 3D Mode
function update3D(dt)
    -- Handle player movement and rotation
    if love.keyboard.isDown("w") then
        player.x = player.x + math.cos(player.angle) * player.speed * dt
        player.y = player.y + math.sin(player.angle) * player.speed * dt
    end
    if love.keyboard.isDown("s") then
        player.x = player.x - math.cos(player.angle) * player.speed * dt
        player.y = player.y - math.sin(player.angle) * player.speed * dt
    end
    if love.keyboard.isDown("a") then
        player.angle = player.angle - player.turnSpeed * dt
    end
    if love.keyboard.isDown("d") then
        player.angle = player.angle + player.turnSpeed * dt
    end


    -- Keep player angle within 0 to 2*pi
    player.angle = player.angle % (2 * math.pi)
end


function draw3D()
    -- Draw the 3D-ish world using raycasting
    for i = 1, numRays do
        local rayAngle = (player.angle - player.fov / 2) + (i / numRays) * player.fov
        local rayDirX = math.cos(rayAngle)
        local rayDirY = math.sin(rayAngle)


        local rayX = player.x
        local rayY = player.y
        local distance = 0
        local hitWall = false


        while not hitWall and distance < rayLength do
            rayX = rayX + rayDirX
            rayY = rayY + rayDirY
            distance = distance + 1


            -- Check if the ray hits a wall
            local mapX = math.floor(rayX / tileSize) + 1
            local mapY = math.floor(rayY / tileSize) + 1


            if mapX >= 1 and mapX <= #map[1] and mapY >= 1 and mapY <= #map then
                if map[mapY][mapX] == 1 then
                    hitWall = true
                end
            else
                break
            end
        end


        -- Draw the first-person view (walls)
        if hitWall then
            local wallHeight = (tileSize * love.graphics.getHeight()) / (distance * math.cos(rayAngle - player.angle))
            local wallX = (i / numRays) * love.graphics.getWidth()
            local wallY = (love.graphics.getHeight() - wallHeight) / 2


            love.graphics.setColor(0.4, 0.4, 0.4)  -- Gray for walls
            love.graphics.rectangle("fill", wallX, wallY, love.graphics.getWidth() / numRays, wallHeight)
        end
    end
end


-- Helper function to check collision
function checkCollision(x1, y1, x2, y2, radius)
    return math.sqrt((x1 - x2)^2 + (y1 - y2)^2) < radius
end

okay so i am trying to make a 2d topdown game for and working on a object collision to transition to a doom like 3d zone but it isn't working as intended

https://redd.it/1ij7o0d
@r_lua
how do event loops work in terminal and how to implement them? (please help im bashing my head in)

I come from a JS background and I am pretty new to lua and terminals, i have a basic terminal application. I wanted to understand how you would go about implementing let's say a progress bar that runs in a nonblocking way, right now the progress bar runs but you cannot do any tasks or add an input while the progress bar runs, I have been trying to implement it but i am honestly just confused, I wanted a functionality like this:

==============40%
press 'q' to go back

You can switch between the menu while the progress bar runs.

Here's the code for the main application and the progress bar ui file :

main.lua

local sys = require("system")
local UI = require("ui")
local copas = require("copas")

function displayMenu()
print("=============")
print("1. Check Time")
print("2. Get Mono Time")
print("3. Give Feedback")
print("4. Progress Bar Demo")
print("6. Exit")
print("=============")
end

function sleep()
local input = io.read()
local gotInput = sys.readkey(input)
print(gotInput)
end

function getTime()
local time = sys.gettime()
local date = os.date("Current Time: %Y-%m-%d %H:%M:%S", time)
print(date)
end


function monoTime()
local response = sys.monotime()
print(response)
end

function UI.prompt(message)
print(message .. " (yes/no):")
local response = io.read()
if response == "yes" then
return true
else return false end
end

function uiPrompt()
local response = UI.prompt("Do you like lua?")
if response == true then
print("Thats great!")
else
print("So sad to hear :(")
end
end

while true do
displayMenu()
io.write("Select an Option: ")
local choice = tonumber(io.read())

if choice == 1 then
getTime()
elseif choice == 2 then
monoTime()
elseif choice == 3 then
uiPrompt()
elseif choice == 4 then
copas.addthread(
function ()
local total = 100
for i=1, total do
UI.progressBar(i, total)
copas.pause(0.1)
end
print()
end)
elseif choice==6 then
break
end
end

copas.loop()

ui.lua

UI={}

function UI.progressBar(current, total)
local widthOfBar = 50
local progress = math.floor((current / total) widthOfBar)
local remaining = widthOfBar - progress
local bar = "[" .. string.rep("=", progress) .. string.rep(" ", remaining) .. "]"
io.write("\r" .. bar .. math.floor((current / total)
100) .. "%") -- carriage return for progress bar to stay on the same line
io.flush()
end

copas.loop()

return UI

If anyone could explain and point out what i am doing wrong that would be great. Thanks!

https://redd.it/1ij6w4y
@r_lua
How possible is to make programs with Lua?

I'm learning to code to make games, and Lua is one of the languages that interest me, as some say Lua is easier than Pythom to learn. What I see often, however, is that Lua is designed to be enbedded into other languages, as oppose to be used on it's on.

Is it possible to make complete programins purely on Lua?

https://redd.it/1ijk4un
@r_lua
cool little 3d terminal ascii renderer i made for fun

```

local width = 50
local height = 50
local cameraZ = 100
local FPS = 1/60
local origin = {x = 25, y = 25}

local grid = {}

local properties = {
    size = 13,
    position = {x = 0, y = 0, z = 0},
    rotation = {x = 0, y = 0, z = 0},
}

local vertices = {
    {x = -1, y = -1, z = -1},  -- Vertex 1: Bottom-left-front
    {x = 1, y = -1, z = -1},   -- Vertex 2: Bottom-right-front
    {x = 1, y = 1, z = -1},    -- Vertex 3: Top-right-front
    {x = -1, y = 1, z = -1},   -- Vertex 4: Top-left-front
    {x = -1, y = -1, z = 1},   -- Vertex 5: Bottom-left-back
    {x = 1, y = -1, z = 1},    -- Vertex 6: Bottom-right-back
    {x = 1, y = 1, z = 1},     -- Vertex 7: Top-right-back
    {x = -1, y = 1, z = 1}     -- Vertex 8: Top-left-back
}

local edges = {
    {1, 2},  -- Bottom-left-front to Bottom-right-front
    {2, 3},  -- Bottom-right-front to Top-right-front
    {3, 4},  -- Top-right-front to Top-left-front
    {4, 1},  -- Top-left-front to Bottom-left-front
    {5, 6},  -- Bottom-left-back to Bottom-right-back
    {6, 7},  -- Bottom-right-back to Top-right-back
    {7, 8},  -- Top-right-back to Top-left-back
    {8, 5},  -- Top-left-back to Bottom-left-back
    {1, 5},  -- Bottom-left-front to Bottom-left-back
    {2, 6},  -- Bottom-right-front to Bottom-right-back
    {3, 7},  -- Top-right-front to Top-right-back
    {4, 8}   -- Top-left-front to Top-left-back
}

local function sleep(t)
    local n = os.clock()
    while os.clock() - n < t do end
end

local function plot(x, y)
    if x >= 1 and x <= width and y >= 1 and y <= height then
        gridxy = "##"
    end
end

-- Bresenham's line algorithm
local function DrawLine(x0, y0, x1, y1)
    local dx = math.abs(x1 - x0)
    local dy = math.abs(y1 - y0)
    local sx = x0 < x1 and 1 or -1
    local sy = y0 < y1 and 1 or -1
    local err = dx - dy
   
    while true do
        plot(x0, y0)
        if x0 == x1 and y0 == y1 then break end
        local e2 = 2 err
        if e2 > -dy then
            err = err - dy
            x0 = x0 + sx
        end
        if e2 < dx then
            err = err + dx
            y0 = y0 + sy
        end
    end
end

local function project(x3d, y3d, z3d)    
    local depth = cameraZ - z3d
    if depth <= 0 then return nil, nil end  -- Clip behind camera
   
    local projX = (x3d - origin.x)
cameraZ / depth + origin.x
    local projY = (y3d - origin.y) cameraZ / depth + origin.y
    local screenX = math.floor(projX + 0.5)
    local screenY = height - math.floor(projY + 0.5) + 1

    if screenX < 1 or screenX > width or screenY < 1 or screenY > height then
        return nil, nil
    end
   
    return screenX, screenY
end

local function SetupGrid()
    for x = 1, width do
        grid[x] = {}
        for y = 1, height do
            grid[x][y] = "  "
        end
    end
end

local function TransformVertices()
    local transformed = {}
    local cosX, sinX = math.cos(properties.rotation.x), math.sin(properties.rotation.x)
    local cosY, sinY = math.cos(properties.rotation.y), math.sin(properties.rotation.y)
    local cosZ, sinZ = math.cos(properties.rotation.z), math.sin(properties.rotation.z)

    for _, v in ipairs(vertices) do
        -- Scale
        local x = v.x
properties.size / 2
        local y = v.y properties.size / 2
        local z = v.z
properties.size / 2

        -- Rotate around X axis
        local y1 = y cosX - z sinX
        local z1 = y sinX + z cosX
        y, z = y1, z1

        -- Rotate around Y axis
        local x1 = x cosY + z sinY
        local z2 =
cool little 3d terminal ascii renderer i made for fun

\`\`\`

local width = 50
local height = 50
local cameraZ = 100
local FPS = 1/60
local origin = {x = 25, y = 25}

local grid = {}

local properties = {
    size = 13,
    position = {x = 0, y = 0, z = 0},
    rotation = {x = 0, y = 0, z = 0},
}

local vertices = {
    {x = -1, y = -1, z = -1},  -- Vertex 1: Bottom-left-front
    {x = 1, y = -1, z = -1},   -- Vertex 2: Bottom-right-front
    {x = 1, y = 1, z = -1},    -- Vertex 3: Top-right-front
    {x = -1, y = 1, z = -1},   -- Vertex 4: Top-left-front
    {x = -1, y = -1, z = 1},   -- Vertex 5: Bottom-left-back
    {x = 1, y = -1, z = 1},    -- Vertex 6: Bottom-right-back
    {x = 1, y = 1, z = 1},     -- Vertex 7: Top-right-back
    {x = -1, y = 1, z = 1}     -- Vertex 8: Top-left-back
}

local edges = {
    {1, 2},  -- Bottom-left-front to Bottom-right-front
    {2, 3},  -- Bottom-right-front to Top-right-front
    {3, 4},  -- Top-right-front to Top-left-front
    {4, 1},  -- Top-left-front to Bottom-left-front
    {5, 6},  -- Bottom-left-back to Bottom-right-back
    {6, 7},  -- Bottom-right-back to Top-right-back
    {7, 8},  -- Top-right-back to Top-left-back
    {8, 5},  -- Top-left-back to Bottom-left-back
    {1, 5},  -- Bottom-left-front to Bottom-left-back
    {2, 6},  -- Bottom-right-front to Bottom-right-back
    {3, 7},  -- Top-right-front to Top-right-back
    {4, 8}   -- Top-left-front to Top-left-back
}

local function sleep(t)
    local n = os.clock()
    while os.clock() - n < t do end
end

local function plot(x, y)
    if x >= 1 and x <= width and y >= 1 and y <= height then
        grid[x][y] = "##"
    end
end

-- Bresenham's line algorithm
local function DrawLine(x0, y0, x1, y1)
    local dx = math.abs(x1 - x0)
    local dy = math.abs(y1 - y0)
    local sx = x0 < x1 and 1 or -1
    local sy = y0 < y1 and 1 or -1
    local err = dx - dy
   
    while true do
        plot(x0, y0)
        if x0 == x1 and y0 == y1 then break end
        local e2 = 2 * err
        if e2 > -dy then
            err = err - dy
            x0 = x0 + sx
        end
        if e2 < dx then
            err = err + dx
            y0 = y0 + sy
        end
    end
end

local function project(x3d, y3d, z3d)    
    local depth = cameraZ - z3d
    if depth <= 0 then return nil, nil end  -- Clip behind camera
   
    local projX = (x3d - origin.x) * cameraZ / depth + origin.x
    local projY = (y3d - origin.y) * cameraZ / depth + origin.y
    local screenX = math.floor(projX + 0.5)
    local screenY = height - math.floor(projY + 0.5) + 1

    if screenX < 1 or screenX > width or screenY < 1 or screenY > height then
        return nil, nil
    end
   
    return screenX, screenY
end

local function SetupGrid()
    for x = 1, width do
        grid[x] = {}
        for y = 1, height do
            grid[x][y] = "  "
        end
    end
end

local function TransformVertices()
    local transformed = {}
    local cosX, sinX = math.cos(properties.rotation.x), math.sin(properties.rotation.x)
    local cosY, sinY = math.cos(properties.rotation.y), math.sin(properties.rotation.y)
    local cosZ, sinZ = math.cos(properties.rotation.z), math.sin(properties.rotation.z)

    for _, v in ipairs(vertices) do
        -- Scale
        local x = v.x * properties.size / 2
        local y = v.y * properties.size / 2
        local z = v.z * properties.size / 2

        -- Rotate around X axis
        local y1 = y * cosX - z * sinX
        local z1 = y * sinX + z * cosX
        y, z = y1, z1

        -- Rotate around Y axis
        local x1 = x * cosY + z * sinY
        local z2 =
-x * sinY + z * cosY
        x, z = x1, z2

        -- Rotate around Z axis
        local x2 = x * cosZ - y * sinZ
        local y2 = x * sinZ + y * cosZ
        x, y = x2, y2

        -- Translate
        x = x + properties.position.x + origin.x
        y = y + properties.position.y + origin.y
        z = z + properties.position.z

        table.insert(transformed, {x = x, y = y, z = z, close = v.close})
    end

    return transformed
end

local function DrawLines()
    local transformed = TransformVertices()
    for _, edge in ipairs(edges) do
        local v1 = transformed[edge[1]]
        local v2 = transformed[edge[2]]
        local x0, y0 = project(v1.x, v1.y, v1.z)
        local x1, y1 = project(v2.x, v2.y, v2.z)
        if x0 and y0 and x1 and y1 then
            DrawLine(x0, y0, x1, y1)
        end
    end
end

local function DrawGrid()
    for y = 1, height do
        for x = 1, width do
            io.write(grid[x][y])
        end
        io.write("\n")
    end
end

-- Main loop
while true do
    os.execute("cls") -- Clear output on Windows (if you're on mac you shouldn't be here, it is the inferior os)

    properties.rotation.x = properties.rotation.x + 0.05
    properties.rotation.y = properties.rotation.y + 0.03
    properties.position.x = math.sin(os.clock()) * 3 -- Oscillate position

    SetupGrid()
    DrawLines()
    DrawGrid()

    sleep(FPS)
end



\`\`\`


that renders a cube, but i have some other shapes too


pyramid:



\`\`\`

local properties = {

size = 7,

position = {x = 0, y = 0, z = 0},

rotation = {x = 0, y = 0, z = 0},

}



local vertices = {

{x = -2, y = -2, z = 0}, -- Vertex 1: Bottom-left

{x = 2, y = -2, z = 0}, -- Vertex 2: Bottom-right

{x = 2, y = 2, z = 0}, -- Vertex 3: Top-right

{x = -2, y = 2, z = 0}, -- Vertex 4: Top-left

{x = 0, y = 0, z = 6} -- Vertex 5: Apex

}



local edges = {

{1, 2}, -- Bottom-left to Bottom-right

{2, 3}, -- Bottom-right to Top-right

{3, 4}, -- Top-right to Top-left

{4, 1}, -- Top-left to Bottom-left

{1, 5}, -- Bottom-left to Apex

{2, 5}, -- Bottom-right to Apex

{3, 5}, -- Top-right to Apex

{4, 5} -- Top-left to Apex

}
\`\`\`


and a dodecahedron


\`\`\`

local properties = {

size = 20,

position = {x = 0, y = 0, z = 0},

rotation = {x = 0, y = 0, z = 0},

}



local vertices = {

{x = 1, y = 1, z = 1}, -- Vertex 1

{x = 1, y = 1, z = -1}, -- Vertex 2

{x = 1, y = -1, z = 1}, -- Vertex 3

{x = 1, y = -1, z = -1}, -- Vertex 4

{x = -1, y = 1, z = 1}, -- Vertex 5

{x = -1, y = 1, z = -1}, -- Vertex 6

{x = -1, y = -1, z = 1}, -- Vertex 7

{x = -1, y = -1, z = -1}, -- Vertex 8

{x = 0, y = 1/1.618, z = 1.618}, -- Vertex 9

{x = 0, y = 1/1.618, z = -1.618},-- Vertex 10

{x = 0, y = -1/1.618, z = 1.618},-- Vertex 11

{x = 0, y = -1/1.618, z = -1.618},-- Vertex 12

{x = 1/1.618, y = 1.618, z = 0}, -- Vertex 13

{x = 1/1.618, y = -1.618, z = 0},-- Vertex 14

{x = -1/1.618, y = 1.618, z = 0},-- Vertex 15

{x = -1/1.618, y = -1.618, z = 0},-- Vertex 16

{x = 1.618, y = 0, z = 1/1.618}, -- Vertex 17

{x = 1.618, y = 0, z = -1/1.618},-- Vertex 18

{x = -1.618, y = 0, z = 1/1.618},-- Vertex 19

{x = -1.618, y = 0, z = -1/1.618},-- Vertex 20

}



local edges = {

{1, 2}, {2, 4}, {4, 3}, {3, 1}, -- Top face

{5, 6}, {6, 8}, {8, 7}, {7, 5}, -- Bottom face

{1, 9}, {9, 5}, -- Connect top to middle

{2, 10}, {10, 6},

{3, 11}, {11, 7},

{4, 12}, {12, 8},

{9, 13}, {13, 15}, {15, 10}, {10, 14}, {14, 9}, -- Top-middle pentagon

{11, 16}, {16, 14}, {14, 12}, {12, 17}, {17, 11},-- Bottom-middle pentagon

{13, 17}, {17, 18}, {18, 15},

{16, 19}, {19, 20}, {20, 14},

{19, 5}, {20, 6}

}
\`\`\`

https://redd.it/1ijnx6n
@r_lua
Lua modding

Does anyone know or have experience modding Sims 4 in lua? I have been learning lua for a bit and wonder if its possible to mod sims 4 with this programming language.

https://redd.it/1ijxjl2
@r_lua
I've only been learning for a short time, but I love physics so I tried this

Is it good for a beginner?



--define the root function
function root(x)
return math.sqrt(x)
end


--- light constant
c = 310^8

--get the values
print("how many percent of the speed of light")
v = (tonumber(
io.read())/100)c
print("what is the mass of the object(kg)")
M = tonumber(io.read())


--calculate lorentz value
LorentzFactor = (1/root(1-(v^2)/(c^2)))


--simplify the variable
F= Lorentz
Factor


--see if the value is less than the speed of light
if v >= c+1 then
print("               $ERROR.0".. math.random(1,10).. "$;enter a valid value (<= c)")
-- here checks if the value is equal
elseif v == c then
print(" $ERROR.0"..math.random(11,15)..";value approaches infinity")
--aki checks if the value is negative
elseif v <= -1 then
print("ERROR.016;identified negative value")

else
--energy calculation
E = (F - 1)Mc^2
--print the energy
print("the energy of the object is "..E)
end





https://redd.it/1ik0pz6
@r_lua
Thoughts on roblox as a free way to learn?

What are your thought son roblox studio and the platform itself, from a developer's perspective?


I'm leaning towards roblox but ive also considered love2d or some fantasy console.

I like lua and i want to learn the basic of it. ive messed with roblox but im not sure if i should stick with it. ive also never finished anything in studio.

https://redd.it/1ike280
@r_lua
Why did you guys decide to learn Lua?

Basically noscript.
I’m just curious to learn why other people decided to learn Lua. For me it’s for my work (I work as a robot programmer and I need to learn how to write some noscripts). I’m just starting out and I think it’s kinda fun.
Do you have any tips and or insights for a newb?

https://redd.it/1ilpbvz
@r_lua
fivem noscript support

ayone here with fivem noscripting that can help me out please?

https://redd.it/1ilssyh
@r_lua
How do you learn programming in general when you have mathematical struggles?

Hello, I have a learning disability and it affects my ability to comprehend math.

https://redd.it/1imcqo1
@r_lua
Learning Lua

Hello all!

I am very interested in Lua language because the game Final Fantasy XI has some add-ons that use it. Is there an online course I could take?? I've heard about Love2d

https://redd.it/1in7awd
@r_lua
It's lua a good choice to Desktop Apps?

My first language was lua, like 10 years ago, but then i start use JavaScript, and i forgot how to use lua btw, i want to know if i can use lua to make Desktop apps, not games, i want to build apps such as a POS or a Dashboard.

https://redd.it/1ini0e3
@r_lua