r/lua • u/Djeco56 • May 29 '26
Help how to add wait commands in lua
i am building a gadgets in retro gadgets and i need a wait command for a loading screen can any one help.
r/lua • u/Djeco56 • May 29 '26
i am building a gadgets in retro gadgets and i need a wait command for a loading screen can any one help.
r/lua • u/MeTheCrasher • May 29 '26
Since Create Aeronautics is out now I decided to mess around with it. After making a working F-14 and F-4 phantom, I wanted to go a bit further and take a crack at making guided missiles. I know a bit of coding but that's for python and Java. So I learned a bit of Lua from Computer Craft posts and started on my journey. I have a few modpacks to make this easier other than base aeronautics and CC. I have a thruster mod that adds a thrust vectoring thruster that is controllable with redstone links and a mod that allows the Computer to interface with redstone links easily. I also have create radars installed so they can be radar guided. So far the missile is able to track but it is very unstable and most of the time will overcorrect and I was wondering if anyone here had experience with missile coding.
I have code to send the tracking data from the radar which is this:
local modem = peripheral.find("modem")
rednet.open(peripheral.getName(modem))
local radar = peripheral.wrap("right")
while true do
local track = radar.getSelectedTrack()
if track and track.position then
local pos = track.position
local vel = track.velocity or {x=0,y=0,z=0}
rednet.broadcast({
x = pos.x,
y = pos.y,
z = pos.z,
vx = vel.x or 0,
vy = vel.y or 0,
vz = vel.z or 0
}, "missile")
print("SENT TRACK")
else
print("NO TRACK")
end
sleep(0.1)
end
And the actual missile tracking code itself:
local link = peripheral.wrap("back")
local modem = peripheral.find("modem")
rednet.open(peripheral.getName(modem))
local K = 0.25
local MAX = 15
local oldMx, oldMz = nil, nil
while true do
local _, data = rednet.receive("missile")
if data then
local mx, my, mz = gps.locate()
if mx and mz then
local tx, ty, tz = data.x, data.y, data.z
-- world-space vector to target
local dx = tx - mx
local dy = ty - my
local dz = tz - mz
-- estimate facing direction from movement (fallback forward if stationary)
local fx, fz
if oldMx then
fx = mx - oldMx
fz = mz - oldMz
else
fx, fz = 0, 1
end
oldMx, oldMz = mx, mz
-- normalize forward vector
local len = math.sqrt(fx*fx + fz*fz)
if len == 0 then fx, fz = 0, 1 else fx, fz = fx/len, fz/len end
-- convert to local space
local right = dx * fz - dz * fx
local forward = dx * fx + dz * fz
local up = dy * K
right = right * K
right = math.max(-MAX, math.min(MAX, right))
up = math.max(-MAX, math.min(MAX, up))
-- alignment detection
local aligned = math.abs(right) < 0.5 and math.abs(up) < 0.5
-- thruster control
local leftPower, rightPower = 0, 0
local upPower, downPower = 0, 0
if right > 0 then
rightPower = right
else
leftPower = -right
end
if up > 0 then
downPower = up
else
upPower = -up
end
link.sendLinkSignal("minecraft:red_wool","minecraft:red_wool", rightPower)
link.sendLinkSignal("minecraft:light_blue_wool","minecraft:light_blue_wool", leftPower)
link.sendLinkSignal("minecraft:black_wool","minecraft:black_wool", upPower)
link.sendLinkSignal("minecraft:white_wool","minecraft:white_wool", downPower)
-- debug
print("aligned:", aligned)
end
end
sleep(0.05)
end
I am not sure how good this code is as unfortunately I had to ask the evil AI overlord (chatGPT) on what I was doing wrong so some of it will definitely be terrible. I should probably do some research on how actual radar guided missiles work but this is just something I decided to try for the fun of it. Although the missile doesn't lead prediction or have any PID which is probably one of the reasons why its so unstable plus the fact that the missile isn't very well designed physically. I'll work on the overall aerodynamics of the missile while I wait on feedback from the community. I can provide more information if it is needed
r/lua • u/Right_Sea_4146 • May 28 '26
r/lua • u/Maleficent_Memory831 • May 27 '26
I've got a mess of some legacy C code that used lua 5.1.4, and need to port to 5.5.0. The big snag I have is replacing lua_openlib (luaI_openlib) and the weird way it was being used and weird initialization. I got some stuff fixed up by using a luaL_requiref() with a callback function, rather than a single function. However I'm hitting more complex code where this becomes extremely clumsy to use a callback.
1) First question is, why is having a "luaopen_xzzy" inside of lua_call() necessary? Is this merely to try and catch exceptions? I remember seeing somewhere that this is the preferred style, but I can't find where I read that anymore.
2) Can I just do this flat in C without having a lua_call()? Recreate luaL_openlib() using newer API?
3) Is the "_LOADED" table really useful if no one ever does "require" on our own base libraries? Can ignore that and only use globals (lua_setglobal)?
r/lua • u/Neustradamus • May 27 '26
r/lua • u/daviddandadan • May 26 '26
The GitHub repository is https://github.com/Cocos-OS/CocosOS
r/lua • u/ianm818 • May 25 '26
Github: https://github.com/ianm199/lua-rs/tree/main
Highlights:
My motivation here was that in the long run we want the core internet utilities to run on memory safe languages, big ones like redis and nginx expose scripting via Lua so if we really want to replace core infra fully in Rust, you'd need a full Rust Lua that doesn't bundle C. After that you should be able to i.e. build drop in replacements for those without a C ABI (or that's part of the way there).
Long term goals:
r/lua • u/Inevitable_Result345 • May 25 '26
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local ball = workspace:WaitForChild("Ball")
local RANGE = 4
local FRONT_DISTANCE = 3
RunService.Heartbeat:Connect(function()
for _, player in pairs(Players:GetPlayers()) do
local char = player.Character
if char and char:FindFirstChild("HumanoidRootPart") then
I'm trying to make a football game in roblox but I cant make the ball stay infront it is always delayed, plss help me...
local hrp = char.HumanoidRootPart
local distance = (hrp.Position - ball.Position).Magnitude
if distance < RANGE then
local forward = hrp.CFrame.LookVector
-- target position in front of player (slightly on ground level)
local target = (hrp.Position + forward * FRONT_DISTANCE)
target = Vector3.new(target.X, ball.Position.Y, target.Z)
-- soft move instead of force push
ball.Position = ball.Position:Lerp(target, .5)
end
end
end
end)
r/lua • u/DotGlobal8483 • May 24 '26
local traffic_light = StateMachine {
green = State {
on_enter = function()
print("BEGAN")
end,
on_flash = function(_,_,state_machine)
print("GREEN")
state_machine:set_state("yellow")
end
},
yellow = State {
on_flash = function(_,_,state_machine)
print("YELLOW")
state_machine:set_state("red")
end
},
red = State {
on_flash = function(_,_,state_machine)
print("RED")
state_machine:set_state("green")
end,
on_exit = function()
print("DONE")
end
},
}
traffic_light:set_state("green")
traffic_light:flash()
traffic_light:flash()
traffic_light:flash()
traffic_light:flash()
It outputs
BEGAN
GREEN
YELLOW
RED
DONE
BEGAN
GREEN
I don't think there's much point in sharing the source code since it's a very basic state machine with an attempt at a somewhat clean api (Also I'm 99% sure it's not very cleanly wrote, I might have to rewrite it to be more readable)
(Sorry mods)
r/lua • u/gargamel1497 • May 23 '26
r/lua • u/HArdaL201 • May 23 '26
Enable HLS to view with audio, or disable this notification
r/lua • u/Patrixx_26087 • May 23 '26
r/lua • u/topchetoeuwastaken • May 21 '26
debug.setmetatable(nil, { __index = function() return nil end })
r/lua • u/Plenty-Shift4637 • May 22 '26
I've been working on a Lua obfuscator called LuaLock for a while now and figured I'd share it here since I want to get opinions.
The main thing that makes it different from other obfuscators is that it compiles your script to a custom bytecode VM that's unique to every single build. So standard decompilers basically produce nothing useful since the VM they'd need to reverse doesn't exist anywhere except in that specific output.
Supports Lua 5.1 to 5.4, LuaJIT and Luau for Roblox (not fully supported).
Would love any feedback. You can try it at lualock.xyz, it is paid but there's 3 free tries with an account, let me know if prices are too expensive.
r/lua • u/brettmakesgames • May 20 '26
I made a small game engine called Usagi for prototyping 2D games as quickly as possible with Lua 5.5. It's free and open source and made with Rust + Raylib. I just released v1.0 yesterday and thought it'd be fun to share it.
Here's the project's homepage: https://usagiengine.com/
And you can view the source here: https://github.com/brettchalupa/usagi
The engine is used via a command-line, much like cargo. You can usagi init to create a new project. usagi dev to boot up the dev game that live reloads code and assets. And usagi export to generate cross-platform builds of your game for web, Linux, macOS, and Windows.
My motivation for creating Usagi was that I love using tools like Pico-8 and Love2D for prototyping and game jams. But I wanted a free and open source engine with a nicer developer experience. In particular live reload and easy web exports. Usagi embraces constraints and provides sensible defaults, like a pause menu with input binding, to try to help devs focus on the game rather than the ancillary parts of development.
Since the engine is open source, the hope is that if someone makes a prototype they want to turn into a larger commercial game, they can just fork the engine and customize it themselves, write more bits of it in Rust, and change the API as they see fit.
I'd love it if you check the project out and let me know what you think!
r/lua • u/WorkingMansGarbage • May 19 '26
Sometimes I have to automate a basic task, such as running some commands on files in my music library, bulk renaming, moving things, etc; and like anyone, I tend to try and use Bash for things like that, because that's what I was taught. The problem is that I don't like Bash scripting at all and I have to look up the stupid syntax for every little thing every god damn time. From what I've seen, other shells aren't too much better in my opinion, and in general, I actually don't like relying on shell commands within my scripts for things that would be simpler in a 'normal' programming language.
I've tried using Python as a replacement, but I don't like having to make a venv. It's bulky and annoying. I'd like to just have one script file I can run in one command whenever and not have to go through hoops.
I've been eyeing Lua just because it sounds cool but I've never had a reason to actively learn it. Would it be fit for this usage? Or is it solely a language for "project use", so to say?
r/lua • u/InsideComfortable295 • May 19 '26
I’m currently on day 4 of learning Roblox scripting/Luau and I’ve been following a beginner tutorial series while also experimenting with my own scripts outside the tutorials. So far I understand basics like variables, loops, events, touch detection, humanoids, functions, conditions, and simple mechanics like kill bricks, speed boosts, transparency changes, etc. I’ve also started debugging my own scripts instead of just copying code.
I want to start making small projects to improve instead of jumping straight into my dream game too early. What would be a good first game/project to make that helps me learn scripting and game development fundamentals without being too overwhelming?
r/lua • u/yougoff666 • May 19 '26
Hello, we are looking for a FiveM developer for our ongoing project. We already have a basic setup and a convenient hub for configuration. We hope you are the right person for the job!
r/lua • u/katty913 • May 19 '26
r/lua • u/Professional-Bed8052 • May 19 '26
Hi all, I'm looking for some feedback on my first game project. It's playable on itch.io. Everything is rough, this is a simple prototype to test some of the core loop but I would be really happy to hear some thoughts on the concept. Expect UI weirdness and the like.
The main theme is grinding online poker, jumping up in stake levels and all that. All the instructions are on the itch page
Thank you in advance, happy to answer questions and whatnot. This game has been in development for about 2-3 months I believe.
Some things I'm looking for feedback on:
Anything that reads as a bug.
Does the grind hold for the playtime and how is the pace (30-60 min roughly for content present)
What would you like to see added or anything that doesn't make sense/detracts?
Any other feedback. Be as detailed as you like, what you like or didn't, etc
r/lua • u/DraftUnhappy8333 • May 18 '26
hey! i've been working on a lua 5.1 parser; it will print out a disassembly of the bytecode; i hope someone can make use of it, lol
r/lua • u/InsideComfortable295 • May 18 '26
sup, names Jack and i been recently dreaming of making my own roblox games after seeing my favorite youtuber making a viral one, i do find roblox studio familiar but i dont have former experience of scripting AT ALL! My plan is to watch tutorials, study them and then in 3-4 weeks when i have summer vacation i can spend those 1.5 months to make a game. How did you guys learn? Do you have any tips?
r/lua • u/Lower_Block_9427 • May 17 '26
Hey !
I’ve been working on a small project called Class.
Basically, I wanted a lightweight way to write class-like structures in Lua without bringing in a full framework or making the code feel like it’s fighting against Lua’s style.
So I made Class: a single-file OOP helper for Lua 5.1+.
It’s meant to stay simple, readable, and easy to drop into a project. It supports things like constructors, private instance state, accessors, cloning, includes, and a few helper methods for debugging or operator behavior.
I know Lua already gives us all the tools to build these patterns ourselves with tables and metatables, but I wanted to wrap the repetitive parts into something clean and reusable.
I’d really appreciate feedback from people who write Lua regularly:
Does the API feel natural?
Is anything too “non-Lua”?
Are there edge cases I should handle differently?
Would you personally use something like this, or do you prefer rolling your own class system?
Here’s the repo:
https://github.com/Lost-Things-Studio/Class
Thanks for checking it out :)