Jump to content




[error][question]


  • You cannot reply to this topic
2 replies to this topic

#1 ewart4fun

  • Members
  • 20 posts

Posted 10 September 2012 - 03:08 PM

i want to make a program that counts the time people has been near the computer.
but i want to save the information at a server restart so i used fs.open, but i get the error message:
Spoiler
this is my code
Spoiler


#2 ardera

  • Members
  • 503 posts
  • LocationGermany

Posted 10 September 2012 - 03:33 PM

First Issue: s1+s1 is the same as fs.open("sec", "w") + fs.open("sec", "w")

I think you wanted to code somethings like this:
local s=fs.open("sec", "r")
s1=assert(tonumber(s.readLine()), "Sec file corrupt")
s.close()
local m=fs.open("min", "r")
m1=assert(tonumber(m.readLine()), "Min file corrupt")
m.close()
term.clear()
term.setCursorPos(1, 1)
print("People has been around spawn for "..m1..":"..s1.." seconds")
sleep(1)
s1=s1+1
fs.delete("sec")
if s1 >= 60 then
    s1=0
    m1=m1+1
end
s=fs.open("sec", "w")
s.writeLine(tostring(s1))   -- s1 is currently a char, so it has to be converted to a string, by using tostring(number)
s.close()
m=fs.open("min", "w")
m.writeLine(tostring(m1)) --same with m1
m.close()
shell.run("startup")



#3 OmegaVest

  • Members
  • 436 posts

Posted 10 September 2012 - 03:33 PM

function saveTime(secons, minuns)
   s1 = fs.open("sec", "w")
   s1.write(secons)
   s1.close()

   m1 = fs.open("min", "w")
   m1.write(minuns)
   m1.close()
end
function loadTime(whichOne)
   if whichOne == "s" then
      s1 = fs.open("sec", "r")
      local outter = tonumber(s1.readLine())
      s1.close()

   elseif whichOne == "m" then
      m1 = fs.open("min", "r")
      local outter = tonumber(m1.readLine())
      m1.close()
   end
   return outter
end

while true do
   local secs = loadTime("s")
   local mins = loadTime("m")

   secs = secs + 1
   if secs == 60 then
      mins = mins +1
      secs = 0
   end

   term.clear()
   term.setCursorPos(1,1)

   print("People have been around Spawn for", mins, " minutes and ", secs, " seconds")

   sleep(1.0)

   saveTime(secs, mins)

If any of that confuses you, or you want to know why I made certain changes, pm me I don't have time right this second, but I want to help you understand if you do not.





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users