This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Agent Silence's profile picture

problem with 'x = x + 1'

Started by Agent Silence, 12 May 2014 - 07:50 PM
Agent Silence #1
Posted 12 May 2014 - 09:50 PM

x = 1
while true do
x = x + 1
print(x)
sleep(1)
end
all it does is print "1", any fix?
Lyqyd #2
Posted 12 May 2014 - 10:16 PM
Are you sure you don't mean something like:


x = 0
while true do
  local x = x + 1
  print(x)
  sleep(1)
end

Because the code you have above should increment just fine.
cptdeath58 #3
Posted 12 May 2014 - 10:54 PM
I think its actually this:
local x = 0
while true do
x = x + 1
print(x)
sleep(1)
end

[Edit] Because don't you got to set a variable before you do the arithmetic part?
Edited on 12 May 2014 - 08:56 PM
Lyqyd #4
Posted 13 May 2014 - 12:53 AM
Your code would work fine, as does his original code. The code I posted above is the only close variant I can think of that would exhibit the symptoms he describes.
cptdeath58 #5
Posted 13 May 2014 - 01:25 AM
Your code would work fine, as does his original code. The code I posted above is the only close variant I can think of that would exhibit the symptoms he describes.
oh ok