Im trying to do a small RPG and have the creature class hold a body container where I place an body object (containing different slots like haedslot, handslot and so on. I do this way so it will be easy to mix different classes to get new monstertypes..
anyway I want the body container to report the sum of all buffs (like +str or + hp) for the objects it holds to the creature class.
I give the body class all the buff properties and thought i would add for example all $this->diffslot->hitpoints into (body class)->hitpoints and then simply return the bodyclass hitpoints with get_hitpoints(){return $this->hitpoints}
However if I dont do an if_object check and have an empty slot I get error for calling an object parameter where it is no object (something like that) and if I try to check if it is an object i get the unexpected T_IF error.
I cant find out what is wrong.
Code: Select all
class humanoidSlots {
//-------------Armour Slots--------------------------------
public $HeadSlot;
public $EarSlot = array("Right","Left");
public $NeclaceSlot;
/../ SHORTENED FOR READABILITY
private $hitpoints;
private $manapoints;
private $actionpoints;
/../ Shortened for readability
private function set_hitpoints(){
$this->hitpoints = (
if(is_object($this->HeadSlot)){$this->HeadSlot->get_hitpoints()} + <-----------This gets me the T_IF error
if(is_object($this->EarSlot[Right])){$this->EarSlot[Right]->get_hitpoints()}+
$this->EarSlot[Left]->get_hitpoints()+ <----- This give me the no object error if the slot is empty
$this->NeclaceSlot->get_hitpoints()+
/../Shortened
);
}
public function get_hitpoints(){$this->set_hitpoints(); return $this->hitpoints;}