Ulysses

General => Off-Topic => Topic started by: assface33 on August 15, 2016, 03:25:39 PM

Title: Help with Coding loop
Post by: assface33 on August 15, 2016, 03:25:39 PM
I'm trying edit some code for a garry's mod addon and I try this

Code: [Select]
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

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.
Title: Re: Help with Coding loop
Post by: JamminR on August 15, 2016, 04:16:22 PM
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 (http://www.tutorialspoint.com/lua/lua_loops.htm).
(Tons of lua tutorials, I just picked that one out of hundreds of google search found pages)
Title: Re: Help with Coding loop
Post by: Bytewave on August 15, 2016, 04:27:23 PM
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.