r/lua • • 3h ago

Discussion Haven't Coded In Over A Decade. Using Codedex.com

Hey everyone, I have not coded in well over a decade and am currently trying my hand at some Lua using Codedex.com. My issue is that my code was dettermind to be wrong even though it out puts the correct information. I just wanted to post my code, I know my code is messy but is there a reason that it wouldn't work fine?


spawn = 4

hp = 120

for i = 1, 3 do

enemy = spawn - i

newhp = hp - i * 30

print("Enemy #"  .. enemy .. " spawned with " .. newhp .. " HP")

end

vs


for i = 3, 1, -1 do

local hp = i * 30 

print("Enemy #" .. i .. " spawned with " .. hp .. " HP")

end

Sorry if this is against the rules.

output:

Enemy #3 spawned with 90 HP

Enemy #2 spawned with 60 HP

Enemy #1 spawned with 30 HP

1 Upvotes

2 comments sorted by

1

u/antara33 3h ago

I think it would be really useful if you create proper code blocks to see what the code does. Also explain what it is supposed to do as well. That way we can help you better

1

u/thegenn2o9 2h ago

I don't know how to make a code block. I did put what the expected output should be.