Jump to content

My First Class (MMORPG related, I am NOT entering the contest)


mattd8752

Recommended Posts

Ok, just so you know, I am NOT entering the contest.

 

This IS my first class, so I am quite sure it is something small, but if someone can help:

 

<?php
class research {
var $z;
var $update;

function set_time($x){
$this->z = $x;
}

function update(){
$lastvisit = date("M-d-Y H:m:s a", time());
$diff = $this->z;
$nextup = $lastvisit+$diff;
$timenow = time();
if ($timenow > $nextup) {
$this->update = "yes";
} else {
$this->update = "no";
}
}

function calc(){
if($this->update == "yes"){
echo "Update!";
}
}


}


$myvar = new research;
$myvar->set_time("600");//10 mins
$myvar->update();
$myvar->calc();
?>

 

Can you see why it says update! all of the time.  It shouldn't say update, EVER according to this script.  Also, how would I check how many sets of 600seconds or 10 minutes there are between two times, thats something I want to add to calc();.

 

Yes this is for a mmorpg, no, I am NOT entering the contest.

 

Thanks, Matt

You are adding:

 

Feb-23-2007 17:02:23 pm + 600

 

And obviously it can't make any sense out of that so, $nextup = 600. So that if is always going to check out as "yes". I'm not totally sure what you are trying to do, but you want to do $time+600 if anything. However, this will always be the same too  ("No")... Can you explain what the update function is doing and what the point of $lastvisit is?

 

If you want to do a calculation between two times, you do

$time1 = 400; //In seconds
$time2 = 1000; //In seconds
$result = ($time2 - $time1) / 60; //In this case $result = 10

 

time() returns the number of seconds after the Unix Epoch. You don't really need to worry about that, but for this application, it will essentially tell you how many seconds elapsed, and from that you can determine how many minutes are in between.

are you running php5, if so, ,you need to update how you structure your class.

 

if you're running four, i say that you need to change your set_time method to be a real constructor by naming it research. that way when you call the class, you can pass the 600 val without having to call a seperate method

 

class research{

function research($val){

$this->val = $val;

}

}

 

$x = new research(600);

 

 

and jbs is absolutely correct. you're adding an integer to a string.  you need to convert $lastvisit to an integer before you add the property z ($this->z)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.