looping in javascript

I am currently working on a project that deals with in-game time. I have 3D models of buildings and am using a “glow” type texture/mesh to make the windows on them appear “lighted”. I have a bit of code here:

  var lightGlow : MeshRenderer;

  function Update(){

  var seconds : int = Time.time;

    if(seconds < 5)
       renderer.enabled = true;
    else if(seconds > 5)
       renderer.enabled = false;

    if(seconds > 8)
       renderer.enabled = true;
    else if(seconds > 10)
       renderer.enabled = false;

    Debug.Log(seconds);}

I am trying to figure out how to make the seconds start over again after “x” amount, so that the lightglow variable is able to repeat continuously. I know there has to be a simple solution, but I’ve googled myself (almost) to death, and I’ve only been writing my own scripts for a little over a month now. Any help/tips would be greatly appreciated.

Time.Time is just going to keep counting up from the start of your game, so I don’t think that you are going to be able to reset it.

This should do roughly what you want (my JS might have syntax issues as I use C#). It will flip the texture between enabled and disabled every 0.5 seconds. You can change the change rate to whatever you like. If you wanted a less static rate, you could update the code to have 2 different change rates that it flips between instead of just using the one.

var lightGlow : MeshRenderer;
private var nextTextureChange = 0.0;
var changeRate = 0.5;
   
function Update(){    
if (Time.Time > nextTextureChange)
{
renderer.enabled = !renderer.enabled;
nextTextureChange = Time.Time + changeRate;
}
}