diff --git a/Stopwatch.lua b/Stopwatch.lua index 957c5a5..01a226a 100644 --- a/Stopwatch.lua +++ b/Stopwatch.lua @@ -49,11 +49,11 @@ end function Stopwatch:getTime() local timeDifference = nil; --If start and stop has been called return the difference - if(startTime and stopTime) then - timeDifference = endTime - startTime; + if((self.startTime ~= nil) and (self.stopTime ~= nil)) then + timeDifference = self.stopTime - self.startTime; --If start has been called but stop hasn't make the current time the end time. This simulates looking at a stopwatch while it is still running - elseif(startTime and not stopTime) then - timeDifference = os.time() - startTime; + elseif((self.startTime ~= nil) and (self.stopTime == nil)) then + timeDifference = os.time() - self.startTime; --Otherwise return -1 as an error else timeDifference = -1;