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

Variable Add 1

Started by Crowdy199, 24 January 2013 - 11:24 AM
Crowdy199 #1
Posted 24 January 2013 - 12:24 PM
hay guys i want to log how many times the computer is opened how do i do that i thought i would do it like this

timesopened = timesopend + 1

print(times opened)

but i just get errors how do i do it
Orwell #2
Posted 24 January 2013 - 12:28 PM
hay guys i want to log how many times the computer is opened how do i do that i thought i would do it like this

timesopened = timesopend + 1

print(times opened)

but i just get errors how do i do it
You just have a bunch of spelling errors in there. Can you post your exact code and the error message?
NeverCast #3
Posted 24 January 2013 - 12:29 PM
Well firstly there is a spelling error.

Here's some code to help


local timesOpened = 0
local function loadHistory()
  local h = fs.open("times", "r")
  if h then
   timesOpened = tonumber(h.readAll())
   h.close()
  else
   timesOpened = 0
  end
end
local function saveHistory()
  local h = fs.open("times", "w")
  if h then
   h.write(tostring(timesOpened))
   h.close()
  end
end
loadHistory()
timesOpened = timesOpened + 1
saveHistory()


Edit: Ninja'd by the spelling errors comment, Blast!