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

[LUA]Clearing A Function

Started by RevolutionLite, 30 October 2012 - 06:52 PM
RevolutionLite #1
Posted 30 October 2012 - 07:52 PM
I was wondering, Would it be possible to clear a function as i'm trying to do a timing system.



print("Login Duration: "..logindur()) -- Logindur needs to be cleared to make sure that the number can increase


function logindur()
i = ""
shell.run("clear") -- Wont this clear the whole screen?
i=i+1
print(i)
sleep(0.25)
end

Thanks..

-RevolutionLite
PixelToast #2
Posted 30 October 2012 - 09:28 PM
i dont really understand what you are trying to do :s
ChunLing #3
Posted 31 October 2012 - 07:23 AM
Pass i as an argument to logindur and only initialize it if it isn't already initialized. Then return i at the end. So:
function logindur(i)
   i = i or ""
   shell.run("clear") -- Wont this clear the whole screen?
   i = i+1 --Um, you initialized i as a string, so this probably isn't a good idea
   print(i)
   sleep(0.25)
return i end
Then when you call logindur to alter i, use i = logindur(i) so that the alteration of i inside of the function is saved outside the function.
RevolutionLite #4
Posted 31 October 2012 - 10:06 AM
Pass i as an argument to logindur and only initialize it if it isn't already initialized. Then return i at the end. So:
function logindur(i)
   i = i or ""
   shell.run("clear") -- Wont this clear the whole screen?
   i = i+1 --Um, you initialized i as a string, so this probably isn't a good idea
   print(i)
   sleep(0.25)
return i end
Then when you call logindur to alter i, use i = logindur(i) so that the alteration of i inside of the function is saved outside the function.
Pass i as an argument to logindur and only initialize it if it isn't already initialized. Then return i at the end. So:
function logindur(i)
   i = i or ""
   shell.run("clear") -- Wont this clear the whole screen?
   i = i+1 --Um, you initialized i as a string, so this probably isn't a good idea
   print(i)
   sleep(0.25)
return i end
Then when you call logindur to alter i, use i = logindur(i) so that the alteration of i inside of the function is saved outside the function.
, Well I've removed it atm.. I'll properly re-add it later

Mega fail x.x