flashTimer = flashTimer + dt
-- Clear clickEffects when game is won
clickEffects = {}
elseif gameState == "lost" then
-- Handle game over state
end
end
function love.draw()
if gameState == "playing" then
drawGame()
drawSightRange() -- Draw the sight range cone
-- Debug information
love.graphics.setColor(1, 1, 1) -- Set color to white
love.graphics.setFont(love.graphics.newFont(18)) -- Set font size to 18
love.graphics.print("Your position: (" .. player.x .. ", " .. player.y .. ")", 10, 30)
elseif gameState == "won" then
drawWinningScreen()
if not soundPlayed then
love.audio.play(CongratsSound)
soundPlayed = true
end
elseif gameState == "lost" then
drawGameOverScreen()
if not soundPlayed then
love.audio.play(GameOver)
soundPlayed = true
end
end
-- Draw click effects list
love.graphics.setColor(1, 1, 1) -- Set color to white
love.graphics.setFont(love.graphics.newFont(18)) -- Set font size to 18
local xOffset = love.graphics.getWidth() - 400 -- Offset from the right side of the window
local yOffset = 50 -- Initial offset for y-coordinate (lowered slightly)
local lineHeight = 20 -- Height of each line in the list
for i, effect in ipairs(clickEffects) do
-- Calculate the alpha value for the text based on the alpha value of the ripple
local alpha = 1 - (effect.radius / 500)
if alpha > 0 then
local text = string.format("Effect %d: x = %d, y = %d, radius = %d", i, effect.x, effect.y, effect.radius)
love.graphics.setColor(1, 1, 1, alpha) -- Set color to white with fading alpha
love.graphics.print(text, xOffset, yOffset) -- Draw text
yOffset = yOffset + lineHeight -- Increase yOffset for next text
else
-- Remove the corresponding text entry when alpha drops below 0
table.remove(clickEffects, i)
end
end
-- Draw click effects
for _, effect in ipairs(clickEffects) do
local alpha = 1 - (effect.radius / 500) -- Calculate alpha based on radius
love.graphics.setColor(0.2, 0.6, 1, alpha) -- Set color to blue with fading alpha
love.graphics.circle("line", effect.x, effect.y, effect.radius)
end
-- Draw projectiles
drawProjectiles()
end
function love.touchpressed(id, x, y, dx, dy, pressure)
if gameState == "lost" then
-- Check if the touch is within the exit button bounds
if x >= exitButtonX and x <= exitButtonX + buttonWidth and y >= exitButtonY and y <= exitButtonY + buttonHeight then
love.event.quit()
end
-- Check if the touch is within the try again button bounds
if x >= tryAgainButtonX and x <= tryAgainButtonX + buttonWidth and y >= tryAgainButtonY and y <= tryAgainButtonY + buttonHeight then
resetGame()
end
else
-- Handle touch for other game states
player.targetX = x - player.width / 2
player.targetY = y - player.height / 2
-- Create a new click effect
local newEffect = {
x = x,
y = y,
radius = 0
}
table.insert(clickEffects, newEffect)
end
end
function checkCollision(a, b)
return a.x < b.x + b.width and
b.x < a.x + a.width and
a.y < b.y + b.height and
b.y < a.y + a.height
end
function updatePlayerPosition(dt)
local dx = player.targetX - player.x
local dy = player.targetY - player.y
local distance = math.sqrt(dx * dx + dy * dy)
if distance > player.speed * dt then
player.x = player.x + (dx / distance) * player.speed * dt
player.y = player.y + (dy / distance) * player.speed * dt
else
player.x = player.targetX
player.y = player.targetY
end
end
-- Modify updateEnemyPosition function
function updateEnemyPosition(dt)
if gameState ~= "playing" then
return -- Do not update enemy
-- Clear clickEffects when game is won
clickEffects = {}
elseif gameState == "lost" then
-- Handle game over state
end
end
function love.draw()
if gameState == "playing" then
drawGame()
drawSightRange() -- Draw the sight range cone
-- Debug information
love.graphics.setColor(1, 1, 1) -- Set color to white
love.graphics.setFont(love.graphics.newFont(18)) -- Set font size to 18
love.graphics.print("Your position: (" .. player.x .. ", " .. player.y .. ")", 10, 30)
elseif gameState == "won" then
drawWinningScreen()
if not soundPlayed then
love.audio.play(CongratsSound)
soundPlayed = true
end
elseif gameState == "lost" then
drawGameOverScreen()
if not soundPlayed then
love.audio.play(GameOver)
soundPlayed = true
end
end
-- Draw click effects list
love.graphics.setColor(1, 1, 1) -- Set color to white
love.graphics.setFont(love.graphics.newFont(18)) -- Set font size to 18
local xOffset = love.graphics.getWidth() - 400 -- Offset from the right side of the window
local yOffset = 50 -- Initial offset for y-coordinate (lowered slightly)
local lineHeight = 20 -- Height of each line in the list
for i, effect in ipairs(clickEffects) do
-- Calculate the alpha value for the text based on the alpha value of the ripple
local alpha = 1 - (effect.radius / 500)
if alpha > 0 then
local text = string.format("Effect %d: x = %d, y = %d, radius = %d", i, effect.x, effect.y, effect.radius)
love.graphics.setColor(1, 1, 1, alpha) -- Set color to white with fading alpha
love.graphics.print(text, xOffset, yOffset) -- Draw text
yOffset = yOffset + lineHeight -- Increase yOffset for next text
else
-- Remove the corresponding text entry when alpha drops below 0
table.remove(clickEffects, i)
end
end
-- Draw click effects
for _, effect in ipairs(clickEffects) do
local alpha = 1 - (effect.radius / 500) -- Calculate alpha based on radius
love.graphics.setColor(0.2, 0.6, 1, alpha) -- Set color to blue with fading alpha
love.graphics.circle("line", effect.x, effect.y, effect.radius)
end
-- Draw projectiles
drawProjectiles()
end
function love.touchpressed(id, x, y, dx, dy, pressure)
if gameState == "lost" then
-- Check if the touch is within the exit button bounds
if x >= exitButtonX and x <= exitButtonX + buttonWidth and y >= exitButtonY and y <= exitButtonY + buttonHeight then
love.event.quit()
end
-- Check if the touch is within the try again button bounds
if x >= tryAgainButtonX and x <= tryAgainButtonX + buttonWidth and y >= tryAgainButtonY and y <= tryAgainButtonY + buttonHeight then
resetGame()
end
else
-- Handle touch for other game states
player.targetX = x - player.width / 2
player.targetY = y - player.height / 2
-- Create a new click effect
local newEffect = {
x = x,
y = y,
radius = 0
}
table.insert(clickEffects, newEffect)
end
end
function checkCollision(a, b)
return a.x < b.x + b.width and
b.x < a.x + a.width and
a.y < b.y + b.height and
b.y < a.y + a.height
end
function updatePlayerPosition(dt)
local dx = player.targetX - player.x
local dy = player.targetY - player.y
local distance = math.sqrt(dx * dx + dy * dy)
if distance > player.speed * dt then
player.x = player.x + (dx / distance) * player.speed * dt
player.y = player.y + (dy / distance) * player.speed * dt
else
player.x = player.targetX
player.y = player.targetY
end
end
-- Modify updateEnemyPosition function
function updateEnemyPosition(dt)
if gameState ~= "playing" then
return -- Do not update enemy
position if game state is not playing
end
if isPlayerInSightRange() then
-- Player is in sight range, engage behavior (e.g., attack or pursue)
enemy.shootTimer = enemy.shootTimer + dt
if enemy.shootTimer >= enemy.shootCooldown then
-- Shoot or perform action towards the player
local dx = player.x - enemy.x
local dy = player.y - enemy.y
local distance = math.sqrt(dx * dx + dy * dy)
if distance > 0 then
local directionX = dx / distance
local directionY = dy / distance
spawnProjectile(enemy.x + enemy.width / 2, enemy.y + enemy.height / 2, {x = directionX, y = directionY})
end
enemy.shootTimer = 0
end
-- Move towards player
local dx = player.x - enemy.x
local dy = player.y - enemy.y
local distance = math.sqrt(dx * dx + dy * dy)
if distance > 0 then
local directionX = dx / distance
local directionY = dy / distance
enemy.x = enemy.x + directionX * enemy.speed * dt
enemy.y = enemy.y + directionY * enemy.speed * dt
end
-- Update enemy's sight cone direction based on movement
enemy.directionX = dx
enemy.directionY = dy
else
-- Player is not in sight range, idle behavior (patrol)
local targetPoint = patrolPoints[currentPatrolIndex]
local dx = targetPoint.x - enemy.x
local dy = targetPoint.y - enemy.y
local distance = math.sqrt(dx * dx + dy * dy)
if distance > 0 then
local directionX = dx / distance
local directionY = dy / distance
enemy.x = enemy.x + directionX * enemy.speed * dt
enemy.y = enemy.y + directionY * enemy.speed * dt
end
-- Update enemy's sight cone direction based on movement
enemy.directionX = dx
enemy.directionY = dy
-- Check if reached the current patrol point
if distance < 5 then
currentPatrolIndex = currentPatrolIndex % #patrolPoints + 1
end
end
end
function checkKeyCollision()
if not key.collected and checkCollision(player, key) then
key.collected = true
player.hasKey = true
love.audio.play(KeyCollected)
keyCollectedMessage.alpha = 1 -- Reset alpha to 1 when key is collected
end
end
function checkDoorCollision()
if player.hasKey and checkCollision(player, door) then
gameState = "won"
end
end
function checkEnemyCollision()
if checkCollision(player, enemy) then
gameState = "lost"
end
end
function updateClickEffects(dt)
-- Update click effects
for i = #clickEffects, 1, -1 do
clickEffects[i].radius = clickEffects[i].radius + 600 * dt -- Adjust the speed of expansion
local maxRadius = 500 -- Adjust the maximum radius as needed
if clickEffects[i].radius > maxRadius then
clickEffects[i].radius = maxRadius -- Cap the radius to the maximum value
end
end
end
function updateKeyCollectedMessage(dt)
-- Update key collected message alpha
if key.collected then
keyCollectedMessage.alpha = keyCollectedMessage.alpha - dt * keyCollectedMessage.fadeSpeed
if keyCollectedMessage.alpha <= 0 then
keyCollectedMessage.alpha = 0
end
else
keyCollectedMessage.alpha = 0 -- Set alpha to 0 if the key is not collected
end
end
function drawGame()
-- Draw player
love.graphics.setColor(0.2, 0.6, 1)
love.graphics.rectangle("fill", player.x, player.y, player.width, player.height)
-- Draw enemy
love.graphics.setColor(1, 0, 0)
love.graphics.rectangle("fill", enemy.x, enemy.y, enemy.width, enemy.height)
-- Draw key if not collected
if not key.collected then
love.graphics.setColor(1, 1, 0)
end
if isPlayerInSightRange() then
-- Player is in sight range, engage behavior (e.g., attack or pursue)
enemy.shootTimer = enemy.shootTimer + dt
if enemy.shootTimer >= enemy.shootCooldown then
-- Shoot or perform action towards the player
local dx = player.x - enemy.x
local dy = player.y - enemy.y
local distance = math.sqrt(dx * dx + dy * dy)
if distance > 0 then
local directionX = dx / distance
local directionY = dy / distance
spawnProjectile(enemy.x + enemy.width / 2, enemy.y + enemy.height / 2, {x = directionX, y = directionY})
end
enemy.shootTimer = 0
end
-- Move towards player
local dx = player.x - enemy.x
local dy = player.y - enemy.y
local distance = math.sqrt(dx * dx + dy * dy)
if distance > 0 then
local directionX = dx / distance
local directionY = dy / distance
enemy.x = enemy.x + directionX * enemy.speed * dt
enemy.y = enemy.y + directionY * enemy.speed * dt
end
-- Update enemy's sight cone direction based on movement
enemy.directionX = dx
enemy.directionY = dy
else
-- Player is not in sight range, idle behavior (patrol)
local targetPoint = patrolPoints[currentPatrolIndex]
local dx = targetPoint.x - enemy.x
local dy = targetPoint.y - enemy.y
local distance = math.sqrt(dx * dx + dy * dy)
if distance > 0 then
local directionX = dx / distance
local directionY = dy / distance
enemy.x = enemy.x + directionX * enemy.speed * dt
enemy.y = enemy.y + directionY * enemy.speed * dt
end
-- Update enemy's sight cone direction based on movement
enemy.directionX = dx
enemy.directionY = dy
-- Check if reached the current patrol point
if distance < 5 then
currentPatrolIndex = currentPatrolIndex % #patrolPoints + 1
end
end
end
function checkKeyCollision()
if not key.collected and checkCollision(player, key) then
key.collected = true
player.hasKey = true
love.audio.play(KeyCollected)
keyCollectedMessage.alpha = 1 -- Reset alpha to 1 when key is collected
end
end
function checkDoorCollision()
if player.hasKey and checkCollision(player, door) then
gameState = "won"
end
end
function checkEnemyCollision()
if checkCollision(player, enemy) then
gameState = "lost"
end
end
function updateClickEffects(dt)
-- Update click effects
for i = #clickEffects, 1, -1 do
clickEffects[i].radius = clickEffects[i].radius + 600 * dt -- Adjust the speed of expansion
local maxRadius = 500 -- Adjust the maximum radius as needed
if clickEffects[i].radius > maxRadius then
clickEffects[i].radius = maxRadius -- Cap the radius to the maximum value
end
end
end
function updateKeyCollectedMessage(dt)
-- Update key collected message alpha
if key.collected then
keyCollectedMessage.alpha = keyCollectedMessage.alpha - dt * keyCollectedMessage.fadeSpeed
if keyCollectedMessage.alpha <= 0 then
keyCollectedMessage.alpha = 0
end
else
keyCollectedMessage.alpha = 0 -- Set alpha to 0 if the key is not collected
end
end
function drawGame()
-- Draw player
love.graphics.setColor(0.2, 0.6, 1)
love.graphics.rectangle("fill", player.x, player.y, player.width, player.height)
-- Draw enemy
love.graphics.setColor(1, 0, 0)
love.graphics.rectangle("fill", enemy.x, enemy.y, enemy.width, enemy.height)
-- Draw key if not collected
if not key.collected then
love.graphics.setColor(1, 1, 0)
love.graphics.rectangle("fill", key.x, key.y, key.width, key.height)
end
-- Draw door
love.graphics.setColor(0.6, 0.3, 0.1)
love.graphics.rectangle("fill", door.x, door.y, door.width, door.height)
-- Draw key collected indicator
if key.collected then
love.graphics.setColor(1, 1, 0, keyCollectedMessage.alpha)
love.graphics.setFont(love.graphics.newFont(24)) -- Set font size to 24
love.graphics.printf(keyCollectedMessage.text, 0, love.graphics.getHeight() - 50, love.graphics.getWidth(), "center")
end
end
function drawWinningScreen()
local r = math.abs(math.sin(flashTimer * 2))
local g = math.abs(math.sin(flashTimer * 2 + math.pi / 2))
local b = math.abs(math.sin(flashTimer * 2 + math.pi))
love.graphics.setColor(r, g, b)
love.graphics.setFont(love.graphics.newFont(72))
love.graphics.printf("Congratulations!", 0, love.graphics.getHeight() / 2 - 36, love.graphics.getWidth(), "center")
projectiles = {}
clickEffects = {}
end
function drawGameOverScreen()
-- Draw game over text
love.graphics.setColor(1, 0, 0)
love.graphics.setFont(love.graphics.newFont(36))
love.graphics.printf("Game Over", 0, love.graphics.getHeight() / 3, love.graphics.getWidth(), "center")
-- Clear Effects
clickEffects = {}
-- Projectiles
projectiles = {}
-- Draw buttons
love.graphics.setColor(0.5, 0.5, 0.5)
love.graphics.rectangle("fill", exitButtonX, exitButtonY, buttonWidth, buttonHeight)
love.graphics.rectangle("fill", tryAgainButtonX, tryAgainButtonY, buttonWidth, buttonHeight)
-- Draw button text
love.graphics.setColor(1, 1, 1)
love.graphics.setFont(love.graphics.newFont(24))
love.graphics.printf("Exit", exitButtonX, exitButtonY + (buttonHeight - love.graphics.getFont():getHeight()) / 2, buttonWidth, "center")
love.graphics.printf("Try Again", tryAgainButtonX, tryAgainButtonY + (buttonHeight - love.graphics.getFont():getHeight()) / 2, buttonWidth, "center")
end
function resetGame()
-- Reset player position
player.x = 50
player.y = 50
player.hasKey = false
player.targetX = 50
player.targetY = 50
-- Reset key position and state
key.x = 300
key.y = 200
key.collected = false
-- Reset enemy position
enemy.x = 600
enemy.y = 400
-- Reset game state
gameState = "playing"
-- Reset sound played flag
soundPlayed = false
end
-- Projectile functions
function spawnProjectile(x, y, direction)
local newProjectile = {
x = x,
y = y,
direction = direction,
speed = 350, -- Adjust as needed
size = 5,
active = true
}
table.insert(projectiles, newProjectile)
end
function updateProjectiles(dt)
for i = #projectiles, 1, -1 do
local proj = projectiles[i]
proj.x = proj.x + proj.direction.x * proj.speed * dt
proj.y = proj.y + proj.direction.y * proj.speed * dt
-- Check collision with player
if checkCollision(player, proj) then
gameState = "lost"
table.remove(projectiles, i) -- Remove projectile upon collision
end
-- Check if projectile is out of bounds
if proj.x < 0 or proj.x > love.graphics.getWidth() or
proj.y < 0 or proj.y > love.graphics.getHeight() then
table.remove(projectiles, i) -- Remove projectile if out of bounds
end
end
end
function drawProjectiles()
love.graphics.setColor(1, 0, 0) -- Red ;)
for _, proj in ipairs(projectiles) do
love.graphics.circle("fill", proj.x, proj.y, proj.size)
end
end
function checkCollision(a, b)
if b.size then
-- If b is a projectile
return a.x < b.x + b.size and
b.x < a.x + a.width and
a.y < b.y + b.size and
b.y < a.y + a.height
else
-- For other objects like player, enemy, key, door
return a.x < b.x + b.width and
b.x < a.x + a.width and
a.y < b.y + b.height and
end
-- Draw door
love.graphics.setColor(0.6, 0.3, 0.1)
love.graphics.rectangle("fill", door.x, door.y, door.width, door.height)
-- Draw key collected indicator
if key.collected then
love.graphics.setColor(1, 1, 0, keyCollectedMessage.alpha)
love.graphics.setFont(love.graphics.newFont(24)) -- Set font size to 24
love.graphics.printf(keyCollectedMessage.text, 0, love.graphics.getHeight() - 50, love.graphics.getWidth(), "center")
end
end
function drawWinningScreen()
local r = math.abs(math.sin(flashTimer * 2))
local g = math.abs(math.sin(flashTimer * 2 + math.pi / 2))
local b = math.abs(math.sin(flashTimer * 2 + math.pi))
love.graphics.setColor(r, g, b)
love.graphics.setFont(love.graphics.newFont(72))
love.graphics.printf("Congratulations!", 0, love.graphics.getHeight() / 2 - 36, love.graphics.getWidth(), "center")
projectiles = {}
clickEffects = {}
end
function drawGameOverScreen()
-- Draw game over text
love.graphics.setColor(1, 0, 0)
love.graphics.setFont(love.graphics.newFont(36))
love.graphics.printf("Game Over", 0, love.graphics.getHeight() / 3, love.graphics.getWidth(), "center")
-- Clear Effects
clickEffects = {}
-- Projectiles
projectiles = {}
-- Draw buttons
love.graphics.setColor(0.5, 0.5, 0.5)
love.graphics.rectangle("fill", exitButtonX, exitButtonY, buttonWidth, buttonHeight)
love.graphics.rectangle("fill", tryAgainButtonX, tryAgainButtonY, buttonWidth, buttonHeight)
-- Draw button text
love.graphics.setColor(1, 1, 1)
love.graphics.setFont(love.graphics.newFont(24))
love.graphics.printf("Exit", exitButtonX, exitButtonY + (buttonHeight - love.graphics.getFont():getHeight()) / 2, buttonWidth, "center")
love.graphics.printf("Try Again", tryAgainButtonX, tryAgainButtonY + (buttonHeight - love.graphics.getFont():getHeight()) / 2, buttonWidth, "center")
end
function resetGame()
-- Reset player position
player.x = 50
player.y = 50
player.hasKey = false
player.targetX = 50
player.targetY = 50
-- Reset key position and state
key.x = 300
key.y = 200
key.collected = false
-- Reset enemy position
enemy.x = 600
enemy.y = 400
-- Reset game state
gameState = "playing"
-- Reset sound played flag
soundPlayed = false
end
-- Projectile functions
function spawnProjectile(x, y, direction)
local newProjectile = {
x = x,
y = y,
direction = direction,
speed = 350, -- Adjust as needed
size = 5,
active = true
}
table.insert(projectiles, newProjectile)
end
function updateProjectiles(dt)
for i = #projectiles, 1, -1 do
local proj = projectiles[i]
proj.x = proj.x + proj.direction.x * proj.speed * dt
proj.y = proj.y + proj.direction.y * proj.speed * dt
-- Check collision with player
if checkCollision(player, proj) then
gameState = "lost"
table.remove(projectiles, i) -- Remove projectile upon collision
end
-- Check if projectile is out of bounds
if proj.x < 0 or proj.x > love.graphics.getWidth() or
proj.y < 0 or proj.y > love.graphics.getHeight() then
table.remove(projectiles, i) -- Remove projectile if out of bounds
end
end
end
function drawProjectiles()
love.graphics.setColor(1, 0, 0) -- Red ;)
for _, proj in ipairs(projectiles) do
love.graphics.circle("fill", proj.x, proj.y, proj.size)
end
end
function checkCollision(a, b)
if b.size then
-- If b is a projectile
return a.x < b.x + b.size and
b.x < a.x + a.width and
a.y < b.y + b.size and
b.y < a.y + a.height
else
-- For other objects like player, enemy, key, door
return a.x < b.x + b.width and
b.x < a.x + a.width and
a.y < b.y + b.height and
b.y < a.y + a.height
end
end
It's so hard to implement a shooting feature for the player, probably 'cause it will share a touch with the movement and move and shoot where you clicked. It's really hard to explain LOL, but I just want to be able to implement a move and shoot independently feature. Any suggestions? Thanks in advance.
Edit: I just realised how butchered the code looks on reddit, I don't know how to properly write code snippets though :(
https://redd.it/1delu9f
@r_lua
end
end
It's so hard to implement a shooting feature for the player, probably 'cause it will share a touch with the movement and move and shoot where you clicked. It's really hard to explain LOL, but I just want to be able to implement a move and shoot independently feature. Any suggestions? Thanks in advance.
Edit: I just realised how butchered the code looks on reddit, I don't know how to properly write code snippets though :(
https://redd.it/1delu9f
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
Which .dll file do i choose>
I'm trying to get LazyVim/NeoVim setup and I need to build with luajit, but I wasn't able to do the instructions:
>Copy `luajit.exe` and `lua51.dll` (built in the `src` directory) to a newly created directory (any location is ok). Add `lua` and `lua\\jit` directories below it and copy all Lua files from the `src\\jit` directory of the distribution to the latter directory.
>There are no hardcoded absolute path names — all modules are loaded relative to the directory where `luajit.exe` is installed (see `src/luaconf.h`).
What i did was first install luajit from the git link and pasted into powershell, then installed cygwin and installed gcc-core and make, then made cygwin\\bin go into my path for make to then work.
I tried to look online for this issue but I didn't seem to find any solution.
then i just looked up .dll, and found `cyglua51.dll` & `libluajit-5.1.dll.a` within the luajit folder
https://preview.redd.it/71ya8pq0796d1.png?width=1920&format=png&auto=webp&s=38ab102a39bf2e0a7979453d8c1330c5621282c0
Which one do i use? or do i need something that is exactly as `lua51.dll` instead without "cyg"?
I am not a coder/computer expert at all, I'm only really able to find quick fixes on google and can find some problems with a bit of patient, but complex problems are out of my reach.
https://redd.it/1deorps
@r_lua
I'm trying to get LazyVim/NeoVim setup and I need to build with luajit, but I wasn't able to do the instructions:
>Copy `luajit.exe` and `lua51.dll` (built in the `src` directory) to a newly created directory (any location is ok). Add `lua` and `lua\\jit` directories below it and copy all Lua files from the `src\\jit` directory of the distribution to the latter directory.
>There are no hardcoded absolute path names — all modules are loaded relative to the directory where `luajit.exe` is installed (see `src/luaconf.h`).
What i did was first install luajit from the git link and pasted into powershell, then installed cygwin and installed gcc-core and make, then made cygwin\\bin go into my path for make to then work.
I tried to look online for this issue but I didn't seem to find any solution.
then i just looked up .dll, and found `cyglua51.dll` & `libluajit-5.1.dll.a` within the luajit folder
https://preview.redd.it/71ya8pq0796d1.png?width=1920&format=png&auto=webp&s=38ab102a39bf2e0a7979453d8c1330c5621282c0
Which one do i use? or do i need something that is exactly as `lua51.dll` instead without "cyg"?
I am not a coder/computer expert at all, I'm only really able to find quick fixes on google and can find some problems with a bit of patient, but complex problems are out of my reach.
https://redd.it/1deorps
@r_lua
Getting up to speed with Lua...and the ecosystem
Hi All!
Aside from Programming in Lua, what are your go-to resources (or collections) for recommend libs, mailing lists, etc. for use and OSS contributions?
I'm trying to get a handle on the current state of the ecosystem and I feel like I keep finding
1/ maintained libs without "traction"
2/ libs that aren't maintained _with_ traction
3/ projects/libs from large companies (i.e. Kong) that aren't referenced anywhere else
4/ and many more...
I'm sold on getting more into Lua and using it for an upcoming project but I'm trying to get a handle on where to focus energy getting up to speed, etc.
thanks in advance!
https://redd.it/1dfewdp
@r_lua
Hi All!
Aside from Programming in Lua, what are your go-to resources (or collections) for recommend libs, mailing lists, etc. for use and OSS contributions?
I'm trying to get a handle on the current state of the ecosystem and I feel like I keep finding
1/ maintained libs without "traction"
2/ libs that aren't maintained _with_ traction
3/ projects/libs from large companies (i.e. Kong) that aren't referenced anywhere else
4/ and many more...
I'm sold on getting more into Lua and using it for an upcoming project but I'm trying to get a handle on where to focus energy getting up to speed, etc.
thanks in advance!
https://redd.it/1dfewdp
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
Modern GUI for lua?
I have successfuly installed 2. the others i had problems with C, though i don't know jack about C,
the two i successfully installed, dont look that good, the widgets arent customizable, i can't make them rounded, change the color, put animations, custom the noscriptbar. i mean make a fully modern GUI.
any suggestions?
https://redd.it/1dffk6z
@r_lua
I have successfuly installed 2. the others i had problems with C, though i don't know jack about C,
the two i successfully installed, dont look that good, the widgets arent customizable, i can't make them rounded, change the color, put animations, custom the noscriptbar. i mean make a fully modern GUI.
any suggestions?
https://redd.it/1dffk6z
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
Do you have any tips on reading Lua's source code?
Hi! I've seen many C developers say good things about the Lua interpreter codebase, so I went to give a look at it.
I was baffled.
The codebase is made of typedefs, in a way that you need to keep track of a million things in your mind in order to even start understanding a single line of code. It's typedefs all the way down:
So, in order to better understand this code, I'd like and am glad to be able to hear tips from developers in the Lua community. Other advice is also welcome: should I just "git gud" at C? what other codebases do you recommend to someone looking to learn and perhaps contribute? Thanks!
https://redd.it/1dfyqaa
@r_lua
Hi! I've seen many C developers say good things about the Lua interpreter codebase, so I went to give a look at it.
I was baffled.
The codebase is made of typedefs, in a way that you need to keep track of a million things in your mind in order to even start understanding a single line of code. It's typedefs all the way down:
lua_State contains a pointer to a StkSomething which is a typedeffed union with one of the elements being a (typedeffed) SomethingValue which... I could keep going on!So, in order to better understand this code, I'd like and am glad to be able to hear tips from developers in the Lua community. Other advice is also welcome: should I just "git gud" at C? what other codebases do you recommend to someone looking to learn and perhaps contribute? Thanks!
https://redd.it/1dfyqaa
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
Why does adding requires to a table cause an extra element to appear?
I have the following code
local helpers = {
require 'helper/helper1',
require 'helper/helper2',
require 'helper/helper3'
}
for i,v in pairs(helpers) do
print(i, v)
-- v.do()
end
I have noticed something strange, which is that there's always a fourth item added to my table. If I print
The output of the above is:
1 table: 0x6031448e1360
2 table: 0x6031448e0e10
3 table: 0x6031448e1ad0
4 ./helpers/helper3.lua
Finished in 8ms
When I remove
I can work around this by just removing the last element with
https://redd.it/1dgspd1
@r_lua
I have the following code
local helpers = {
require 'helper/helper1',
require 'helper/helper2',
require 'helper/helper3'
}
for i,v in pairs(helpers) do
print(i, v)
-- v.do()
end
I have noticed something strange, which is that there's always a fourth item added to my table. If I print
#helpers I get 4 (though other searches have cautioned against using # to count items in a table, table.getn(helpers) is giving me a nil error for getn...).The output of the above is:
1 table: 0x6031448e1360
2 table: 0x6031448e0e10
3 table: 0x6031448e1ad0
4 ./helpers/helper3.lua
Finished in 8ms
When I remove
require 'helper/helper3' from the table declaration, the same thing happens with helper2. Even with just one item, I get a extra element which is just the filename.I can work around this by just removing the last element with
table.remove() or ending the loop when it gets to the last value, but I am extremely confused by this as it's the first time I'm using Lua for anythinghttps://redd.it/1dgspd1
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
Framework for lua
A DLL made in C for Lua aimed at creating APIs and desktop web applications (such as VSCode, Postman, etc.). It was designed to be as intuitive as possible, with various features and configurations. It is open-source.
The name of the framework is serjaoBerranteiroServer: https://github.com/SamuelHenriqueDeMoraisVitrio/SerjaoBerranteiroServer
Currently, it only supports Linux, but it can be tested on WSL.
https://redd.it/1dgxb5b
@r_lua
A DLL made in C for Lua aimed at creating APIs and desktop web applications (such as VSCode, Postman, etc.). It was designed to be as intuitive as possible, with various features and configurations. It is open-source.
The name of the framework is serjaoBerranteiroServer: https://github.com/SamuelHenriqueDeMoraisVitrio/SerjaoBerranteiroServer
Currently, it only supports Linux, but it can be tested on WSL.
https://redd.it/1dgxb5b
@r_lua
GitHub
GitHub - SamuelHenriqueDeMoraisVitrio/SerjaoBerranteiroServer: Web server c for lua
Web server c for lua. Contribute to SamuelHenriqueDeMoraisVitrio/SerjaoBerranteiroServer development by creating an account on GitHub.
What a neat language!
I've been bored with programming for a while now. Nothing really seemed "fun" for the longest time. I've used Swift (great language), Kotlin (for work), Python/Django (for work), C#, Java, and JavaScript. I've been trying to think of projects I can build in those languages...I've been pretty uninspired lately.
That said, just this past week I was looking at languages I haven't used before and I stumbled upon the framework Love2D & noticed it uses Lua...
What a great language!
I've only been using it for a few days now and it feels so refreshing. I love that there's only 1 data structure (tables)! I also love how customizable the language is! If I want to use "classes", I can create my own. Metamethods & metatables also feel very powerful.
The language feels pretty straightforward (so far) and I can totally get behind the syntax.
That's all. Thanks for reading!
Happy coding! :)
https://redd.it/1dgxsl5
@r_lua
I've been bored with programming for a while now. Nothing really seemed "fun" for the longest time. I've used Swift (great language), Kotlin (for work), Python/Django (for work), C#, Java, and JavaScript. I've been trying to think of projects I can build in those languages...I've been pretty uninspired lately.
That said, just this past week I was looking at languages I haven't used before and I stumbled upon the framework Love2D & noticed it uses Lua...
What a great language!
I've only been using it for a few days now and it feels so refreshing. I love that there's only 1 data structure (tables)! I also love how customizable the language is! If I want to use "classes", I can create my own. Metamethods & metatables also feel very powerful.
The language feels pretty straightforward (so far) and I can totally get behind the syntax.
That's all. Thanks for reading!
Happy coding! :)
https://redd.it/1dgxsl5
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
How do i access functions from one file to another?
Let's say i have a function named "score" in "MainG.lua". But i also need this function in "Char.lua" since i want my character to have power-ups once he reaches high-enough score. How do i do this? Well, obviously just copying the code from MainG.lua to Char.lua is inefficient, so there's gotta be the other way.
https://redd.it/1dgy53m
@r_lua
Let's say i have a function named "score" in "MainG.lua". But i also need this function in "Char.lua" since i want my character to have power-ups once he reaches high-enough score. How do i do this? Well, obviously just copying the code from MainG.lua to Char.lua is inefficient, so there's gotta be the other way.
https://redd.it/1dgy53m
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
should i learn javanoscript or lua first?
im a beginner in coding, i only know html and css. i want to learn javanoscript and lua soon, i dont know which one to choose. so which is easier to learn for a beginner? thank you! :D
https://redd.it/1dh9xua
@r_lua
im a beginner in coding, i only know html and css. i want to learn javanoscript and lua soon, i dont know which one to choose. so which is easier to learn for a beginner? thank you! :D
https://redd.it/1dh9xua
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
My keys that I have assigned aren't working
So I watched an old LTT video about lua and I used the code that they provided and just made some adjustment to the keys (I removed the ones I didn't need and added my own to what i want them to do).
I was trying to setup a numpad for my truck sim, but for some reason the keys i assigned aren't getting detected when the code is running through LuaMacaros, the key strokes are getting read and are getting assigned in the console but not on the game or at all on my pc.
https://redd.it/1dhkt8s
@r_lua
So I watched an old LTT video about lua and I used the code that they provided and just made some adjustment to the keys (I removed the ones I didn't need and added my own to what i want them to do).
I was trying to setup a numpad for my truck sim, but for some reason the keys i assigned aren't getting detected when the code is running through LuaMacaros, the key strokes are getting read and are getting assigned in the console but not on the game or at all on my pc.
https://redd.it/1dhkt8s
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
Help with Fivem noscript
does anyone know how i would change okokShops to use qb-target, would i have to add a target ped for each individual store through qb-target? or is there an option somewhere in okokshops that im missing? (im new lmao)
https://redd.it/1dhoedr
@r_lua
does anyone know how i would change okokShops to use qb-target, would i have to add a target ped for each individual store through qb-target? or is there an option somewhere in okokshops that im missing? (im new lmao)
https://redd.it/1dhoedr
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
I am new to lua - What should I make?
I got bored, and wanted to learn a new coding language- so I chose lua. I've got all the basics down, and I can make simple text games, but there's a tiny problem...
What do I even make?
I am so stuck on deciding what to create, because nothing sounds useful or appealing to me! If anyone has any suggestions, it would help a lot.
https://redd.it/1dhpffi
@r_lua
I got bored, and wanted to learn a new coding language- so I chose lua. I've got all the basics down, and I can make simple text games, but there's a tiny problem...
What do I even make?
I am so stuck on deciding what to create, because nothing sounds useful or appealing to me! If anyone has any suggestions, it would help a lot.
https://redd.it/1dhpffi
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
Recommend courses
As a beginner , what are some good video resources (paid or free) to learn from? I learn better from videos than reading I do read after a better understanding through video tutorials.
https://redd.it/1dhqxr4
@r_lua
As a beginner , what are some good video resources (paid or free) to learn from? I learn better from videos than reading I do read after a better understanding through video tutorials.
https://redd.it/1dhqxr4
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
My keys that I have assigned aren't working
So I watched an old LTT video about lua and I used the code that they provided and just made some adjustment to the keys (I removed the ones I didn't need and added my own to what i want them to do).
I was trying to setup a numpad for my truck sim, but for some reason the keys i assigned aren't getting detected when the code is running through LuaMacaros, the key strokes are getting read and are getting assigned in the console but not on the game or at all on my pc.
Also just to note that i am also running AHK so maybe there's a problem with that too. I have no clue.
So if anyone could help.
My AHK Code:
#NoEnv
SendMode Input
#InstallKeybdHook
#UseHook On
Menu, Tray, Icon, shell32.dll, 283 ; this changes the tray icon to a little keyboard!
#SingleInstance force ;only one instance of this noscript may run at a time!
#MaxHotkeysPerInterval 2000
#WinActivateForce
#IfWinActive
\~F24::
If (key = "c")
Send {c}
else if(key = "e")
Send {e}
else if(key = "space")
Send {Space}
else if(key = "t")
Send {t}
else if(key = "f")
Send {f}
else if(key = "v")
Send {v}
else if(key = "p")
Send {p}
else if(key = "n")
Send {n}
else if(key = "k")
Send {k}
else if(key = "l")
Send {l}
else if(key = "F6")
Send {F6}
else if(key = "b")
Send {b}
else if(key = "num4")
Send {Numpad4}
else if(key = "num5")
Send {Numpad5}
else if(key = "num6")
Send {Numpad6}
else if(key = "num7")
Send {Numpad7}
else if(key = "num8")
Send {Numpad8}
Return
My Lua Code:
local keyboardIdentifier = '0000AAA'
if keyboardIdentifier == '0000AAA' then
lmc_assign_keyboard('MACROS');
else lmc_device_set_name('MACROS', keyboardIdentifier);
end
dev = lmc_get_devices()
for key,value in pairs(dev) do
print(key..':')
for key2,value2 in pairs(value) do print(' '..key2..' = '..value2) end
end
print('You need to get the identifier code for the keyboard with name "MACROS"')
print('Then replace the first 0000AAA value in the code with it. This will prevent having to manually identify keyboard every time.')
lmc.minimizeToTray = true
sendToAHK = function (key)
local file = io.open("C:\\\\AHK\\\\2nd-keyboard\\\\LUAMACROS\\\\keypressed.txt", "w") -- writing this string to a text file on disk is probably NOT the best method. Feel free to program something better!
--print("we are inside the text file")
file:write(key)
file:flush() --"flush" means "save." Lol.
file:close()
lmc_send_keys('{F24}')
end
local config = {
[13\] = "e",
[8\] = "space",
[107\] = "t",
[109\] = "f",
[96\] = "v",
[99\] = "p",
[102\] = "NumPad6",
[105\] = "c",
[106\] = "n",
[97\] = "k",
[98\] = "l",
[101\] = "NumPad5",
[104\] = "NumPad8",
[111\] = "F6",
[100\] = "NumPad4",
[103\] = "NumPad7",
[144\] = "b",
}
lmc_set_handler('MACROS', function(button, direction)
if (direction == 0) then return end
if type(config[button\]) == "string" then
print(' ')
print('Your key ID number is: ' .. button)
print('It was assigned string: ' .. config[button\])
sendToAHK(config[button\])
else
print(' ')
print('Not yet assigned: ' .. button)
end
end)
https://redd.it/1dhuydy
@r_lua
So I watched an old LTT video about lua and I used the code that they provided and just made some adjustment to the keys (I removed the ones I didn't need and added my own to what i want them to do).
I was trying to setup a numpad for my truck sim, but for some reason the keys i assigned aren't getting detected when the code is running through LuaMacaros, the key strokes are getting read and are getting assigned in the console but not on the game or at all on my pc.
Also just to note that i am also running AHK so maybe there's a problem with that too. I have no clue.
So if anyone could help.
My AHK Code:
#NoEnv
SendMode Input
#InstallKeybdHook
#UseHook On
Menu, Tray, Icon, shell32.dll, 283 ; this changes the tray icon to a little keyboard!
#SingleInstance force ;only one instance of this noscript may run at a time!
#MaxHotkeysPerInterval 2000
#WinActivateForce
#IfWinActive
\~F24::
If (key = "c")
Send {c}
else if(key = "e")
Send {e}
else if(key = "space")
Send {Space}
else if(key = "t")
Send {t}
else if(key = "f")
Send {f}
else if(key = "v")
Send {v}
else if(key = "p")
Send {p}
else if(key = "n")
Send {n}
else if(key = "k")
Send {k}
else if(key = "l")
Send {l}
else if(key = "F6")
Send {F6}
else if(key = "b")
Send {b}
else if(key = "num4")
Send {Numpad4}
else if(key = "num5")
Send {Numpad5}
else if(key = "num6")
Send {Numpad6}
else if(key = "num7")
Send {Numpad7}
else if(key = "num8")
Send {Numpad8}
Return
My Lua Code:
local keyboardIdentifier = '0000AAA'
if keyboardIdentifier == '0000AAA' then
lmc_assign_keyboard('MACROS');
else lmc_device_set_name('MACROS', keyboardIdentifier);
end
dev = lmc_get_devices()
for key,value in pairs(dev) do
print(key..':')
for key2,value2 in pairs(value) do print(' '..key2..' = '..value2) end
end
print('You need to get the identifier code for the keyboard with name "MACROS"')
print('Then replace the first 0000AAA value in the code with it. This will prevent having to manually identify keyboard every time.')
lmc.minimizeToTray = true
sendToAHK = function (key)
local file = io.open("C:\\\\AHK\\\\2nd-keyboard\\\\LUAMACROS\\\\keypressed.txt", "w") -- writing this string to a text file on disk is probably NOT the best method. Feel free to program something better!
--print("we are inside the text file")
file:write(key)
file:flush() --"flush" means "save." Lol.
file:close()
lmc_send_keys('{F24}')
end
local config = {
[13\] = "e",
[8\] = "space",
[107\] = "t",
[109\] = "f",
[96\] = "v",
[99\] = "p",
[102\] = "NumPad6",
[105\] = "c",
[106\] = "n",
[97\] = "k",
[98\] = "l",
[101\] = "NumPad5",
[104\] = "NumPad8",
[111\] = "F6",
[100\] = "NumPad4",
[103\] = "NumPad7",
[144\] = "b",
}
lmc_set_handler('MACROS', function(button, direction)
if (direction == 0) then return end
if type(config[button\]) == "string" then
print(' ')
print('Your key ID number is: ' .. button)
print('It was assigned string: ' .. config[button\])
sendToAHK(config[button\])
else
print(' ')
print('Not yet assigned: ' .. button)
end
end)
https://redd.it/1dhuydy
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
How to handle IEEE 754 single precision floats in Lua
I'm currently trying to read the following C struct from a file:
https://preview.redd.it/evjhau2yf67d1.png?width=222&format=png&auto=webp&s=92b66dc9c6e2205d6eb1e17451298cea517f3b26
I used the following code to create the structs and save them to a file:
That's the resulting binary file:
hexdump
But when i try to unpack the file, with the following Lua code, I get all the correct values, except for the float.
Output of the code above:
https://preview.redd.it/ks1ti094o67d1.png?width=448&format=png&auto=webp&s=97d223ee75d06a3950054a22a1586a0a59be5d35
Can somebody explain me why is this occurring?
https://redd.it/1di6ngr
@r_lua
I'm currently trying to read the following C struct from a file:
https://preview.redd.it/evjhau2yf67d1.png?width=222&format=png&auto=webp&s=92b66dc9c6e2205d6eb1e17451298cea517f3b26
I used the following code to create the structs and save them to a file:
#include <stdlib.h>#include <stdio.h>#define FILE_SAVE "./records"#define VECTOR_SIZE 128typedef struct Record {int x;char code[3];float value;} Record;int serializeRec(Record *rec_vector){FILE *fp = fopen(FILE_SAVE, "wb+");int rc = fwrite((void *)rec_vector, VECTOR_SIZE * sizeof(Record), 1, fp); fclose(fp);return 0;}int main(int argc, char *argv[]){Record r[VECTOR_SIZE];for(int i = 0; i < VECTOR_SIZE; i++){r[i].x = i;r[i].code[0] = 'a' + i; r[i].code[1] = 'b' + i; r[i].code[2] = '\0';r[i].value = i*3;}if(serializeRec(r) == -1) return -1;return 0;}That's the resulting binary file:
hexdump
But when i try to unpack the file, with the following Lua code, I get all the correct values, except for the float.
function getSumReg(file)local str = file:read("a")cursor = 1while(cursor < #str) dox, code, value, cursor = string.unpack("i4zfx", str, cursor)print(string.format("%d %s %f", x,code,value))endendfp = io.open("./records", "r")getSumReg(fp)Output of the code above:
https://preview.redd.it/ks1ti094o67d1.png?width=448&format=png&auto=webp&s=97d223ee75d06a3950054a22a1586a0a59be5d35
Can somebody explain me why is this occurring?
https://redd.it/1di6ngr
@r_lua
Lua.org site is down
Can someone in the mailing list please post an issue. This is blocking my team at work.
https://redd.it/1di6evb
@r_lua
Can someone in the mailing list please post an issue. This is blocking my team at work.
https://redd.it/1di6evb
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
Codea or Love2D
I’m looking to start making a card game concept I’ve come up with but am in between two minds on where to start.
From what I’ve read Love2D is likely to be the opinion of many of this sub however this will be my first project learning Lua and I’ve heard Codea is good error checking and the built in interpreter and it’s own engine.
I’m a software engineer by trade so hopefully I’ll pick things up quickly but ideally I’d like to work on my project from the comfort of my sofa in the evenings on my iPad.
So my predicament is, setup a Lua project with Love2D on my desktop and work on my normal iPad Code Editor (texttastic) and only run the project when I’m able at my desktop or use Codea and deal with consequences of learning a framework and engine that may not be that helpful in future projects.
Or any other thoughts. Happy to hear them.
https://redd.it/1di6ye6
@r_lua
I’m looking to start making a card game concept I’ve come up with but am in between two minds on where to start.
From what I’ve read Love2D is likely to be the opinion of many of this sub however this will be my first project learning Lua and I’ve heard Codea is good error checking and the built in interpreter and it’s own engine.
I’m a software engineer by trade so hopefully I’ll pick things up quickly but ideally I’d like to work on my project from the comfort of my sofa in the evenings on my iPad.
So my predicament is, setup a Lua project with Love2D on my desktop and work on my normal iPad Code Editor (texttastic) and only run the project when I’m able at my desktop or use Codea and deal with consequences of learning a framework and engine that may not be that helpful in future projects.
Or any other thoughts. Happy to hear them.
https://redd.it/1di6ye6
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community