Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do constantly add numbers without it being the same result?

Asked by 2 years ago
Edited 2 years ago

Hello, I need to be able to print() and make it so that it will count to 100. I was thinking like

for i = 1, 100 do
a = 0
a = a + 1
print(a)
end

but that doesnt work

Thanks for the help!

An example of the output: 1 2 3 4 5 6 7 ... 99 100

It could even go past 100 to infinity, I don't mind. I just need it to infinitely add. Thanks!

0
Bruh. Dude. Just print i AlexanderYar 788 — 2y

2 answers

Log in to vote
1
Answered by 2 years ago

Your problem is that every time you run the loop you are setting a back to 0. Instead, do this:

local a = 0

for i = 1, 100 do
    a = a + 1
    print(a)
end

A pretty easy mistake to make and I'm sure everyone has done this before. Let me know if you have any questions about the difference between the two scripts.

0
Printing the value of the i variable would work too and it would use less code appxritixn 2235 — 2y
0
@phxntxsmic unfortunately there are scenarios that will be more complex than this and will require more than the i value. I decided to help him understand why the value of the variable didnt change cmgtotalyawesome 1418 — 2y
Ad
Log in to vote
0
Answered by 2 years ago

Please provide explanation with your answers. Simply posting code does not spread knowledge of integral scripting processes which helps people understand the logic and reasoning behind your answer.
A = 0
while true do
      A = A + 1
      print(A)
      wait(0) -- change the 0 to however long you want the wait to be
end

Answer this question