Author Topic: Help with Coding loop  (Read 1500 times)

0 Members and 1 Guest are viewing this topic.

Offline assface33

  • Newbie
  • *
  • Posts: 2
  • Karma: 0
Help with Coding loop
« 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.
« Last Edit: August 15, 2016, 04:12:27 PM by JamminR »

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Help with Coding loop
« Reply #1 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.
(Tons of lua tutorials, I just picked that one out of hundreds of google search found pages)
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Bytewave

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 718
  • Karma: 116
  • :)
    • My Homepage
Re: Help with Coding loop
« Reply #2 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.
bw81@ulysses-forums ~ % whoami
Homepage