little question
is there a downloadable lua program that i can use with my friend?
like a multiplayer lua program
https://redd.it/kxsnqy
@r_lua
I'm a complete noob and would like to know a good place to start learning (books, forums, tutorials, and etc.)
Over the past 2 months I've been trying to reach myself lua, but every step I make, I end up taking 2 steps back. I tried reading, "Programming in Lua, 2nd Edition, " but it still feels like I'm missing something.
Also I've heard that learning C++ would make this exponentially easier, but is that true?
https://redd.it/kx5tcr
@r_lua
How popular is Lua compared to Java, Csharp, PHP, Kotlin and others? Take the developer survey and support the programming language of your choice.
https://www.developereconomics.net/?utm_medium=some_org&utm_source=reddit&utm_campaign=de20
https://redd.it/kvutev
@r_lua
Critique my understanding of metatables and prototypes
I'm learning about the "object-oriented" aspects of Lua, but browsing through different resources on the web I noticed that people are using extremely different ways of achieving pretty much the same thing.
I combined all the knowledge I could gather to create a class system that works for my application, but I'm worried that I'm still misunderstanding some of terms or underlying logic of it all and that it's gonna come back to haunt me in the future.
I would be extremely glad if you guys could take a look at my implementation and point out things that could potentially be wrong.
Code on pastebin for those who prefer and the same thing below:
-- Point Class
-- Prototype of the Point class
-- If instance of class Point or instance of a class that inherits from this has no value, it will look here
local Point = { name = "Point", x = 0, y = 0 }
-- What now was a prototype table is now both a prototype and a metatable
-- Once indexed, it will look inside of itself and make things like tostring and other metaevents work
Point.index = Point
-- The constructor function to create a new instance of class Point
function Point:new(x, y)
-- We override the predefined self
variable pointing to Point
table, and treat it like a new instance, THIS IS A GIMMICK
self = {}
-- Put some data into the instance depending on user input while remembering that if those are nil
they'll use values in the Point
prototype
self.x = x
self.y = y
-- Assign the newly created instance to the Point
table to use it as a metatable and a prototype
return setmetatable(self, Point)
end
-- One of many metaevents, allowing us to nicely represent our object
function Point:tostring()
return string.format("%s X:%d Y:%d", self.name, self.x, self.y)
end
function Point:setX(x)
-- Assign OR remove (if nil
is passed) the value from x
key of the instance
self.x = x
end
function Point:getX()
-- If the instance holds x
, return it, if not return the x
value from Point
prototype or if it doesn't have it, return nil
return self.x
end
-- Rectangle Class
-- Like previously with Point
, we create a prototype table, but this time we know that we'll be inheriting from the Point
class
-- so there's no need to define x
and y
variables
local Rectangle = { name = "Rectangle", w = 0, h = 0 }
-- Make querying this object look in itself
Rectangle.index = Rectangle
-- This is where inheritance really happens, after instance of Rectangle
looked in itself, then the Rectangle
prototype (because of the line above),
-- make it look in the Point
prototype / metatable
setmetatable(Rectangle, { index = Point })
-- If this was not defined, calling Rectangle:new()
would simply result in Point:new()
being called
function Rectangle:new(x, y, w, h)
-- Create instance of the Point
class and pass in variables from our new constructor
self = Point:new(x, y)
-- Define extra stuff this class needs, as before it will look in the Rectangle
prototype and then the Point
prototype
self.w = w
self.h = h
-- Assign the instance as part of the Rectangle
class, to use it's methods and prototype
return setmetatable(self, Rectangle)
end
-- Override the Point
tostring and include extra stuff from this class
function Rectangle:tostring()
return string.format("%s X:%d Y:%d W:%d H:%d", self.name, self.x, self.y, self.w, self.h)
end
function Rectangle:setW(w)
-- Assign new value to the instance
self.w = w
end
function Rectangle:getW()
-- As before, look in self, Rectangle
prototype and Point
prototype, even though Point
shuld never have it defined
return self.w
end
-- Testing:
local p =
How to Minify Lua Code?
Are you using Lua Code? If yes then this tutorial is a must helpful for you because everyone likes minified code because it improves the loading of files.
So you are manually minifying Lua code, why not use an automatic minifier.
So today in this tutorial I will introduce Lua Minifier.
​
https://preview.redd.it/5w5gknwnria61.png?width=1602&format=png&auto=webp&s=dff860dce451929e60ad2016701c5aa2e6ceab35
# Here is How to Minify Lua Code?
1. First Open this Lua Minifier
2. Click on Clear Button to Clear Demo Code
3. Paste Lua Code
4. Click on Minify Button
5. Now Press Copy Button to Copy Minified Lua Code
If you have any suggestion for this tool then please let me know via comment :)
https://redd.it/kufu4f
@r_lua
Autoclicker for Mouse Button 2 or 3?
Hello,
I was trying to have a little script like this running on RMB or MMB.
if (event == "MOUSEBUTTONPRESSED" and arg == (2)) then
repeat
PressKey("a")
Sleep(8)
ReleaseKey("a")
until not IsMouseButtonPressed(2)
end
This script works perfectly as long as I use it with LMB (arg 1), but it won't work for RMB or MMB.
Is there a SIMPLE way to make it work for those buttons aswell or is it just going to work on LMB only?
Thx
https://redd.it/kub6ix
@r_lua
Can Someone Fix This Code?
​
​
local Tween = game:GetService("TweenService"):Create(game.Workspace.Baseplate,TweenInfo.new(100,Enum.EasingStyle.Linear,Enum.EasingDirection.In,0,false,0),(Size = Vector3.new(0,2000,0:Play)
​
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:connect(function(char)
char.Humanoid.Died:connect(function()
player:Kick "You Died."
end)
end)
)))
https://redd.it/ktk90l
@r_lua
Trouble with learning Lua
So I am now learning Lua from the book programming in Lua 4th edition and I’m having trouble.I want to use Lua for roblox which uses a modified version of Lua.Would learning the normal Lua language be good enough?Or would I need to do something else to use it for roblox?In some examples the code is written in a way which won’t work in roblox studio and I don’t know what to do.I have heard learning Normal Lua is just enough but I don’t know if it’s true.Basically what I’m saying is should I learn Lua by itself first or the modified ones I’m using it for?
https://redd.it/ks4oeq
@r_lua
Learn Lua For Dummies
Is there any new methods as of 2021 up to date methods to learn this language?
https://redd.it/krn58n
@r_lua
How can I mention the RoleId of a role
so im making a mute command for my discord bot, and i want to know how to get the roleId of a role
for example:
I get the guild Id by doing local GuildId =
`message.member.guild.id`
and i dont know how to get the RoleId
is this what Im supposed to be doing or not? thanks
https://redd.it/kqi29a
@r_lua
The most important links to useful Lua 5.1 resources ("Get started with Defold. Lua." )
https://agulev.com/en/defold-s-chego-nachat-lua/
https://redd.it/kq93j1
@r_lua
A complete implementation of the Set data structure in Lua
https://github.com/EvandroLG/set-lua
https://redd.it/kptm4p
@r_lua
Lua writing style? (when using LÖVE)
Just working my way through a couple of the tutorials for programming games with the LÖVE game engine and (almost immediately) ran into two different writing styles for functions:
function love.update(dt)
-- do something
end
love.udpate = function(dt)
-- do something
end
From a practical standpoint, they both appear to do the same thing, just with different notations (and they both give the same results). Is there any advantage to picking one over the other? From the practical view, there doesn’t appear to be – but that most likely means each involves a different thought process when approaching a project?
https://redd.it/kp8jne
@r_lua
stringstream - an object that loads chunks of strings on demand compatible with a subset of the Lua string API suitable for parsing
https://github.com/gilzoide/stringstream-lua
With string streams, we can pass streams (e.g.: files) to parser functionality that expects strings and use method notation (like text:match(...)
), removing the need to duplicate code for parsing strings vs files vs etc, or reading whole files at once before using the contents =D
It is a single lua file compatible with 5.1+
https://redd.it/kxiw9y
@r_lua
Question about lua
Is there any common things that can be done with lua? A person at my school is buying some ‘lua scripting software’ for btc. And you know if your using btc to buy somthing it’s usually when you want to stay anonymous, so I was wondering what are some common ‘suspicious’ uses for lua?
https://redd.it/kwump4
@r_lua
Map works like a hashtable but preserving the key insertion order :)
https://github.com/EvandroLG/Map
https://redd.it/kwevtp
@r_lua
Point:new(1, 2)
print(p) --> Point X:1 Y:2
p:setX(123)
print(p:getX()) --> 123
local r = Rectangle:new()
print(r:getX()) --> 0 (got from the Point
prototype)
r:setX(777)
r:setW(999)
print(r) --> Rectangle X:777 Y:0 W:999 H:0
https://redd.it/kuy58l
@r_lua
Generating Enemies???
Hey everyone,
I'm making progress on my little galaga clone, but now I've run into a major road block that I can't seem to get passed.
I've tried implementing a table for my enemy class, but it won't spawn more than 1 enemy. Period.... I've tried implementing a table in a bunch of different places and either no change occurs, or my game blue screens and comes back with an error...
Would anyone with more programming knowledge than me be able to help me out with this?
Here's a link to my code. I'd be eternally grateful for anyone's help in anyway.
https://github.com/juliosuarez95/cs50-final.git
https://redd.it/kuje00
@r_lua
Share Lua code snippets easily with your friends
I am happy to announce that I launched a new feature in GoOnlineTools which you can use to share Lua code snippets easily with your friends or colleagues.
Currently, this code sharing tool supports HTML, JSON, CSS, SQL, Lua, XML, PHP code languages
Screenshot
## How to share code snippets
1. Open Share code snippets
2. Select code language (e.g - Lua)
3. Write or paste code on the editor.
4. Now click on the share code button to get a sharable URL.
You must be logged in to GoOnlineTools to use this feature. You can share the published URL with anyone.
# Here is how the shared code snippet looks:
https://preview.redd.it/hnqkgef8xia61.png?width=1537&format=png&auto=webp&s=1fc45854da906efccd703aa149191622983be754
I hope this feature help to solve the developer code sharing problem.
If you think any feature added to this code sharing tool then please let me know. I am looking for developers feedback 😍
https://redd.it/kugfwb
@r_lua
Trying to convert my personal chromekilling .bat file into a Lua version
Trying to do this mainly because making a .bat file that waits between actions is confusing for me, whereas in Lua it's just "wait(5)" repeatedly,
This is the .bat command :
@echo off
SETLOCAL EnableExtensions
set EXE=chrome.exe
FOR /F %%x IN ('tasklist /NH /FI "IMAGENAME eq %EXE%"') DO IF %%x == %EXE% goto ProcessFound
goto ProcessNotFound
:ProcessFound
echo %EXE% is running
Taskkill /IM chrome.exe /F
echo %EXE% has been closed
goto END
:ProcessNotFound
echo %EXE% is not running
goto END
:END
echo Finished!
The main reason I want it to do waiting intervals is so that I can make it into a program that runs on startup, as having to kill a process that takes up my CPU despite the fact I don't use Chrome anymore, except for when I need to get old passwords is tiring when done manually,
Basically, what I want it to do is make it detect whether or not Chrome.exe is running, if it doesn't detect it, as a safe measure it purges it, but then waits 5 seconds, before detecting again, it does this for about 5 minutes, once it reaches it's last interval, it purges, prints "Found no Chrome instances, purging one last time" and then closes,
However, if it does detect a Chrome instance, it will purge, and then print "Purged Chrome instances" and then end,
thank you,
https://redd.it/kua6pu
@r_lua
More trouble with Lua
So sorry if it's s simple question but I've heard in some places that Lua is enough to make my own game and stuff but from other places I've heard it's only good with game engines.I honestly don't know what to believe and I came for help.
https://redd.it/kt4yz7
@r_lua
Making a Garry's mod addon and I keep getting this error message, can anyone help with this?
The Error https://pastebin.com/Nkq09fDB
The Base Code https://pastebin.com/zTJeEDeV
I've been trying to make an addon for an addon called Vehicle Radio (Link here https://steamcommunity.com/sharedfiles/filedetails/?id=1419487677), I have done this about twice beforehand and both mods had worked perfectly. The error only showed up after I had tried to add a few new songs into one of my other mods. I have spent the last 2 hours trying to fix this, and no solution has shown itself, if you have any knowledge about what this is, it would be greatly appreciated.
https://redd.it/ks5j5s
@r_lua
Examining how Lua Game Engines work with Android
https://opensourcegamedeveloper.com/2021/01/06/examining-how-lua-game-engines-work-with-android/
https://redd.it/krp2hd
@r_lua
help with a G502 script
I think I've gotten pretty far, but I'm not a coder at all and I clearly have missed something.
What I want: when I press a button, it toggles on a repeating action of pressing the Left Mouse Button for 2 seconds, then releasing it. When I hit that button again, the loop stops.
What I got: the loop does indeed start, but clicking the button a second time does not stop it. I also have noticed that I probably should add in a 300ms pause after releasing the button.
I've basically cobbled this script together by looking at one person's script for a "rapid click" while holding down the LMB, and someone else's script for a toggle to hold down the LMB. Had I been able to find a toggle rapid click script, I could have just extended the time between click and release. But I can't seem to find that. So this is the Frankenstein that I put together instead:
function OnEvent(event, arg)
--OutputLogMessage("Event: "..event.." Arg: "..arg.."\n")
end
function OnEvent(event, arg)
if event == "MOUSEBUTTONPRESSED" and arg == 6 then
toggle = not toggle
if toggle then
repeat
PressKey("1")
Sleep(2000)
ReleaseKey("1")
until not toggle
else
ReleaseKey("1")
end
end
end
Reddit messed up my formatting, but the last two "end"s are not on the same indentation. If that even matters. The only scripting experience I have was typing for a programmer who injured his wrist in the middle of an important deadline. He just dictated the code to me and I typed. I learned a little, but that was Python. I digress... how'd I screw up the thing above? Something with the toggle line, right?
https://redd.it/krjj32
@r_lua
Execution engine for Lua, comparing Emilua to Node.js
https://emilua.gitlab.io/blog/post/comparing-emilua-to-nodejs/
https://redd.it/kqbblr
@r_lua
i dont know if ima t the right palce but i need your help
hi all.
so my problem is with Onset.
the game itself is a strong base for rolep\^laying and the server have all needed functions.
but the thing is , ther eis only one person "helping" and its an admin.
ive tried many base rp script after trying my own code for weeks , no help.
im gettign a problem related to a nil valie.
so my code is PlayerData[player].accountid = mariadb_get_value_index(1, 1)
and when joining the game it give Error in MariaDB callback: [string "******/base/server_base.lua"]:106: attempt to index a nil value (field '?')
the "admin" on the forum just answer nosense thing that im doing something wrong...
but EVERY code online do the same thing. every other database query work fine.
ive been reading somewhere that many scripter abandonned it because oif problems similar and there is no help or no update to fix this problem... but what we read on internet isnt always right so...
jsut to name a few that do the same error ( OnsetRP , OkayyFramework Basic , ORP Framework , ORP Plus ). all are supposedly working according to him , but none do work.
im pretty sure the dev changed something ( or somethign is wrong with the mariadb plugin ?? ) but was too lazy to update his shit. and too busy to help he jsut reply nosense things to look like helping.
last time he said it seem that the "player" variable was nil...
im not a lua master , but god dammit i have enought experience from other game server ( samp , mta:sa , fivem ) to know that you CAN'T get such an error from WRITING to a variably. if it was READING the "player"variable , ok maybe. but its WRITING.
ps: i can create a new variable , let say TestVariable = mariadb_get_value_index(1, 1) , the result will ALWAYS be the nil value error. i tried other way of getting the result from the database , it doesnt matter.
so where could the problem be ? what can i do to fix ? is it my fault ?
if it help , it work exactly the same way as fivem do.
https://redd.it/kq8l7p
@r_lua
I am new to Lua
never learned any programming language before, where do i start?
https://redd.it/kphuo5
@r_lua
Learning Lua but need some help
local date = "1-1-2021 this is a string"
local matchDate = string.match(date, "%d+-%d+-%d+")
print(matchDate) -- this works
print(string.format("%02d-%02d-%04d", matchDate)) -- I get an error here: bad argument #2 to 'format' (number expected, got string)
stack traceback:
[C\]: in function 'string.format'
I tried to combine two things I learned from a tutorial to format the date so that it outputs like: 01-01-2021
https://redd.it/kp7csl
@r_lua