title: How do I execute a global function on a specific day at a specific time in Lua?
body: <p>I'm writing a script in Lua that among many other functions will perform a single loop at a specific time on a specific day. The loop is started when a button is pressed, pondering over this for a while now I have gathered that I will have to check the system time in millis using os.time which in table form can return the date too which is very helpful. The only thing I am stuck with is how to express it, and if it would be possible to include multiple definitions of os.time; so on day (x), loop1 will run and on day (y) loop 2 will occur and so on. I'm most likely over complicating this a lot...</p>
  
  <p>Here's my code so far: (it crashes and burns when called by the button press)</p>
  
  <pre><code>function runiftime()
  
  day1 = a;
  day2 = b;
  day3 = c;
  day4 = d;
  status = 0; -- Default status == 0
  target = day4;
  
  
  -- Where a, b, c &amp; d are shown above I would like different os.time outputs which relate to days in the future an example output of os.time is =&gt; = os.time() outputs '1384988715'.
  
      repeat
  
   if os.time() == "day1" then
  
      os.execute("Some command");
      result = Shell.Execute("Some program", "open", "", "",     SW_SHOWNORMAL, false);
      status = 1;
  end
  
   if os.time() == "day2" then
  
      os.execute("Some command");
      result = Shell.Execute("Some program", "open", "", "", SW_SHOWNORMAL, false);
      status = 1;
  end
  
   if os.time == "day3" then
  
      os.execute("Some command");
      result = Shell.Execute("Some program", "open", "", "",     SW_SHOWNORMAL, false);
      status = 1;
  end
  
   if os.time == "day4" then
  
      os.execute("Some command");
      result = Shell.Execute("Some program", "open", "", "",     SW_SHOWNORMAL, false);
      status = 1;
  end
  
  
      if status == 1 then
          Input.SetText("feed", "Routine Successful!                                  Waiting for Command...");
      else
          Input.SetText("feed", "Automated Routine Started!           Waiting for OS Clock...");
      end
  
  until (os.time == target);  
  end
  </code></pre>