Author Topic: do something every X seconds  (Read 1323 times)

0 Members and 1 Guest are viewing this topic.

Offline Tazerenix

  • Enthusiast
  • Posts: 228
  • Gender: Male
  • Call me taz :D
    • View Profile
    • Tazerenix Productions
Re: do something every X seconds
« Reply #15 on: March 12, 2010, 07:10:56 PM »
unless the server needs to be acting on the data all the time you dont really need to. But i suppose if you really needed too, something like a search engine that updates its searches or something
Quote
"War does not determine who is right... Only who is dead" - Unknown



NOTE: Most of the code I post is untested. So hope for the best

Offline thorpe

  • Administrator
  • 'Mind Boggling!'
  • *
  • Posts: 29,255
    • View Profile
Re: do something every X seconds
« Reply #16 on: March 12, 2010, 07:15:05 PM »
Quote
unless the server needs to be acting on the data all the time you dont really need to.

No kidding. I'm just saying you didn't have enough information to say what you did.

Offline Tazerenix

  • Enthusiast
  • Posts: 228
  • Gender: Male
  • Call me taz :D
    • View Profile
    • Tazerenix Productions
Re: do something every X seconds
« Reply #17 on: March 12, 2010, 07:16:11 PM »
fair enough
Quote
"War does not determine who is right... Only who is dead" - Unknown



NOTE: Most of the code I post is untested. So hope for the best

Offline TeddyKillerTopic starter

  • Devotee
  • Posts: 1,055
  • Gender: Male
  • What is today without tomorrow or yesterday?
    • View Profile
Re: do something every X seconds
« Reply #18 on: March 13, 2010, 10:29:08 AM »
It doesn't work, what I'm assuming, when the echo comes it's not starting the function.
Can you help?

Code: [Select]
<?php
include("lib.php");
define("PAGENAME""Resting");
$player check_user($secret_key$db);
?>

<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
<script type="text/javascript">
function updateTable() {
  $.load('enhp.php');
  alert("You healed 1HP and 1Energy point!");
}
</script>
</head>
<?php
echo '<center>';
if (
$player->hp == $player->maxhp && $player->energy == $player->maxenergy)
{
echo "<i>You have full HP and Energy.</i>\n";
exit;
}
else
{
if ($_GET['act'] == "rest") {
echo '<script type="text/javascript">setInterval("updateTable()",12000);</script>';
echo 'You are now resting. You will gain 1hp and 1energy point every 5 seconds. To unrest type "unrest"';
    }
}
echo 
'</center>';
?>
Please use [code][/code] and [php][/php] when posting code.

Please use proper PHP opening tags. <?php code here ?>

If I have posted false information, feel free to correct me.

Offline Tazerenix

  • Enthusiast
  • Posts: 228
  • Gender: Male
  • Call me taz :D
    • View Profile
    • Tazerenix Productions
Re: do something every X seconds
« Reply #19 on: March 13, 2010, 06:22:58 PM »
<html>
<?
php
include("lib.php");
define("PAGENAME""Resting");
$player check_user($secret_key$db);
?>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
<script type="text/javascript">
function updateTable() {
  $("#resting").load('enhp.php');
  alert("You healed 1HP and 1Energy point!");
}
</script>
</head>
<body>


<?php
echo '<center>';
if (
$player->hp == $player->maxhp && $player->energy == $player->maxenergy)
{
   echo 
"<i>You have full HP and Energy.</i>\n";
   exit;
}
else
{
   if (
$_GET['act'] == "rest") {
      echo 
'<div id="resting"></div>';
      echo 
'<script type="text/javascript">setInterval("updateTable()",12000);</script>';
      echo 
'You are now resting. You will gain 1hp and 1energy point every 5 seconds. To unrest type "unrest"';
    }
}
echo 
'</center>';
?>
</body>
</html>


That should work. Your problem was that the .load jQuery function requires a selector to load into. I've created the div resting. If enhp.php outputs any text it will be loaded into #resting. But as enhp is just getting database querys (isnt it?) it shouldnt do anything. But that should work.
Quote
"War does not determine who is right... Only who is dead" - Unknown



NOTE: Most of the code I post is untested. So hope for the best