Jump to content

Fatal error: Cannot use string offset as an array in C:\wamp\www\S


Recommended Posts

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

 

 

attack posted
Fatal error: Cannot use string offset as an array in C:\wamp\www\SUN_DRAGON_GAME\gamestart.php on line 202

 

$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

 

function playerAttack($currentMonster,$hitRollLow,$hitRollHigh,$dmgLow,$dmgHigh,$monsterDefense, $monsterHp,$playerFaction)
{     
echo "in player attack";
$playerRoll= rand($playerHitRollLow, $playerHitRollHigh);
if($playerHitRoll>=$monsterDefense)
{   
 global $theMessage; //shit 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;
}
}

Thank you. I don't see any duplicate values. Here are my arrays, do you see anything I need to change please? I can't figure it out. Thanks. Derek.

 

$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'
)
);

oops sorry

 

//I NEED THE FOLLOWING CODE BUT IT GAVE AN ERROR SO I COMMENTED IT OUT
                //   echo "attack posted";
            //    playerAttack($currentMonster,$player['stats']['playerHitRollLow'],$player['stats']['playerHitRollHigh'],
            // line 202   $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']);

You have problems in this chunk of code. I indicate them with "// <<------" on the lines

<?php
$monster ['name']='';
$Teardrop_Ocean_Protectors='';
$random='';
$error='';
$monsterMessage='';
$echoMonster='';

$name='';
$ocean='';
$monster='';  // <<-----   Already used $monster as an array above
$monsters='';
$monsters['ocean']='';  // <<----  Already used $monsters as a string
$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'
)
);
?>

 

Ken

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.