General > Off-Topic

Help with Coding loop

(1/1)

assface33:
I'm trying edit some code for a garry's mod addon and I try this


--- Code: ---function (this part doesn't matter)
   local i = 1
       if i<11 then
            (code stuff line 1)
            (code stuff line 2)
            i = i + 1
end
--- End code ---

but it doesn't work. If someone could tell me what I should do and why mine doesn't work I'd really appreciate it.

JamminR:
If you're calling that function repeatedly and expecting it to count, it's always assigning i = 1

If you're expecting it to loop, you have no loop statement.
(Tons of lua tutorials, I just picked that one out of hundreds of google search found pages)

Bytewave:
Defining "doesn't work" would be nice. Knowing your use case means we can help you more accurately and not just provide broad solutions.

Also, I don't know if this was from cropping out code or whatever, but you're missing an end to close that if statement.

Navigation

[0] Message Index

Go to full version