Timer Sim Issue
Results 1 to 4 of 4

Thread: Timer Sim Issue

  1. #1
    Senior Member
    Join Date
    Apr 2005
    Posts
    1,325

    Timer Sim Issue

    I'm building a small simulation game using HTML, PHP, AJAX, MySQL.

    I've got it all designed except one issue I can't solve.

    I want the simulation to change month every 5 mins (configurable). At each interval a series of 'services' are called. This will update my simulation with all the relevant events.

    Initially I thought, I'll do a set Timer internal in JS. Easy but if the page refreshes for any reason then the timer starts again.

    I thought, when I update the current interval I could do a 'Next Interval' timestamp. I could then check every 5 seconds if the current timestamp is greater than the next interval stamp and if so true 'true' but this seems like hard work and a lot of extra load on the server with a heap more extra AJAX calls.

    Can I get some thoughts on how to solve this please?

  2. #2
    Senior Member cluelessPHP's Avatar
    Join Date
    Apr 2015
    Location
    Scotland
    Posts
    334
    Doing it with JS should be easy enough
    HTML Code:
    setInterval(function() {      
    		  $.ajax({    
    			type: "GET",
    			url: "your page here",             
    			dataType: "html",          
    			success: function(response){                    
    				$("your div/span here").html(response); 
    			}
    
    		   });
    		}, 1000 //set time here);
    Then you could set a trigger in your database, an easy to follow tutorial

    http://tutsheap.com/web/create-triggers-phpmyadmin/
    You need to believe in things that aren't true. How else can they become?― Terry Pratchett, Hogfather
    Blog

    Six month project

  3. #3
    Senior Member
    Join Date
    Apr 2005
    Posts
    1,325
    Quote Originally Posted by cluelessPHP View Post
    Doing it with JS should be easy enough
    HTML Code:
    setInterval(function() {      
    		  $.ajax({    
    			type: "GET",
    			url: "your page here",             
    			dataType: "html",          
    			success: function(response){                    
    				$("your div/span here").html(response); 
    			}
    
    		   });
    		}, 1000 //set time here);
    Then you could set a trigger in your database, an easy to follow tutorial

    http://tutsheap.com/web/create-triggers-phpmyadmin/
    But when a user refreshes the page the timer starts again. I want to disable that.

  4. #4
    Senior Member cluelessPHP's Avatar
    Join Date
    Apr 2015
    Location
    Scotland
    Posts
    334
    Ah sorry I'm with you now, you want some sort of push, here is a list of most languages them in git

    https://github.com/pushtechnology
    You need to believe in things that aren't true. How else can they become?― Terry Pratchett, Hogfather
    Blog

    Six month project

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •