Hi, when I run my script I get the following error message. These are array variables I am passing into the playerAttack function. I can't figure out what is wrong it looks fine to me. Any help greatly appreciated. Thanks. Derek
Code:
attack posted
Fatal error: Cannot use string offset as an array in C:\wamp\www\SUN_DRAGON_GAME\gamestart.php on line 202
Code:
$currentMonster='octalisk';
///////////////////////////////////////////////////////////battle////////////////////////////
//function monsterEncounter($echoMonster,$monsterImage)
if(!empty($_POST['attack']))
{
echo "attack posted";
playerAttack($currentMonster,$player['stats']['playerHitRollLow'],$player['stats']['playerHitRollHigh'],
$player['stats']['playerDmgLow'],$player['stats']['playerDmgHigh'],$monsters['Ocean']['octalisk']['defense'],$monster['Ocean']['octalisk']['hp'],$player['faction']['Teardrop_Ocean_Protectors']);
$doesItAttack=encounter($monsters['ocean']['octalisk']['seeInvis'],$monsters['ocean']['octalisk']['aggro'],$player['factions']['Teardrop_Ocean_Protectors']);
//insert octalisk stats into monsterattack function.
if($doesItAttack =='yes')
{
monsterAttack($currentMonster,$monsters['Ocean']['octalisk']['hitRollLow'],$monsters['Ocean']['octalisk']['hitRollHigh'] ,
$monsters['Ocean']['octalisk']['dmgLow'],$monsters['Ocean']['octalisk']['dmgHigh'],
$player['stats']['playerDefense'],$player['stats']['playerHp'],$monsters['Ocean']['octalisk']['hp']);
}
else
{
echo "do nothing";
}
}
here is the attack function
Code:
function playerAttack($currentMonster,$hitRollLow,$hitRollHigh,$dmgLow,$dmgHigh,$monsterDefense, $monsterHp,$playerFaction)
{
echo "in player attack";
$playerRoll= rand($playerHitRollLow, $playerHitRollHigh);
if($playerHitRoll>=$monsterDefense)
{
global $theMessage; //**** had to make it global
$playerDamage= rand($playerDmgLow,$playerDmgHigh);
$theMessage = "You have hit a ". $currentMonster." for "."<strong>". $playerDamage."</strong> points of damage!";
$monsterHp= $monsterHp- $playerDamage;
$theMessage.=" The ".$currentMonster."'s hp is now ".$monsterHp;
if($monsterHp<=0)
{
if($playerFaction<=0)
{
$theMessage="Your faction standing with ".$playerFaction. "could not possibly get any worse.";
}
}
$theMessage.=" You have killed the ".$currentMonster. "Your faction standing with ".$playerFaction." is now ".$playerFaction-1;
}
else
{
global $theMessage; //WTF i dont know what im doing.
$theMessage= " Whoa! You missed the ".$currentMonster;
}
}
here are my arrays
Code:
$monster ['name']='';
$Teardrop_Ocean_Protectors='';
$random='';
$error='';
$monsterMessage='';
$echoMonster='';
$name='';
$ocean='';
$monster='';
$monsters='';
$monsters['ocean']='';
$player['factions']['Teardrop Ocean Protectors']='';
$monsters['ocean']['octalisk']['seeInvis']='';
$spells = array
(
"red" => "red",
"green"=>"green",
"blue" =>"blue"
);
//////////////////////////////////////////////////////////////
$player = array
(
'inventory'=>'',
'spells'=>'',
'stats'=> array
(
'int'=>16,
'playerHp'=>100,
'playerDmgLow'=>1,
'playerDmgHigh'=>10,
'playerHitRollLow'=>1,
'playerHitRollHigh'=>20,
'playerDefense'=>5
),
'armor'=> array
(
'shield'=>'gold'
),
'weapons' =>array
(
'sword'=>'silver'
)
,
'faction'=> array
(
'Teardrop_Ocean_Protectors'=>3 //zero means the worst faction you can have, 10 being best , 5 being indifferent.
)
);
///////////////////////////////////////////////////////////////
$monsters = array
(
'Ocean'=>array
(
'octalisk'=>array
(
'name'=>'octalisk',
'hp'=>100,
'exp'=>10,
'mana'=>100,
'dmgLow'=>1,
'dmgHigh'=>10,
'seeInvis'=>true,
'aggro'=>true,
'defense'=>5,
'faction'=>'Teardrop_Ocean_Protectors',
'hitRollLow'=>1,
'hitRollHigh'=>20),
'shark'=>array
(
),
'eel'=>array
(
)
),
'Desert'=>array
(
'sand_snake'
),
'Forest'=>array
(
'frog',
'lizard',
'spider'
)
);