r/lua • u/Aggravating_Drag705 • Jan 10 '26
Discussion Is this good code for a beginner? (read desc)
No I am not trying to hack anybody, I just wanted to see if I could make something like this because I have adhd.
26
Upvotes


9
u/ShawSumma Jan 10 '26
Your code has a bug... see how you do `io.read() == 'Start' or 'srt' or 'start'`... that's not how "or" oreally works, it's not checking the thing you wrote is among those words, instead it's checking if it's start (which it might be) or if 'srt' is true... which it always is. Try typing something other than those words... Does it behave like you want?
4
u/Aggravating_Drag705 Jan 10 '26 edited Jan 10 '26
UPDATE: Fixed bug where password guesses would exceed 999 sometimes with,
print("Couldn't find password :(")returnendIn between lines 24-27.
3
u/blobules Jan 10 '26
Not horrible, but quite bad.... :-)
Remove the first if after repeat. It's not needed. Always check the order if operations... What do you want to repeat? -> make a random guess -> check if the guess is right -> loop until you get it right
As you see, any duplicated code (like your test if the password is good) is a sign that your code has a problem. Duplication of code is always bad and should always be avoided.
3
u/9peppe Jan 10 '26
Your indentation is confusing. Else should be aligned to if and until to repeat.Â
The interpreter of course won't care, but humans reading the code will be very confused.Â
4
u/HeavyCaffeinate Jan 10 '26
Looks fine by me, also I didn't even know Lua had repeat until syntax, I just used while loops
2
u/Synthetic5ou1 Jan 10 '26
Testing the following code I was getting the same answer unless I used
math.randomseed().Is that a me problem?
EDIT: I'm used to using PICO-8 rather than Scite (which was used) or the command line.
1
u/Jaded-Bison9490 Jan 16 '26
decent
0
u/[deleted] Jan 10 '26
[deleted] — view deleted comment
1
u/[deleted] Jan 12 '26 edited Jan 12 '26
[removed] — view removed comment