Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Fatal error: Cannot use string offset as an array in C:\wamp\www\S
Old 08-02-2010, 02:33 PM Fatal error: Cannot use string offset as an array in C:\wamp\www\S
Webmaster Talker

Posts: 611
Trades: 0
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'
   )
);
silverglade is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-02-2010, 02:49 PM Re: Fatal error: Cannot use string offset as an array in C:\wamp\www\S
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Which line is 202?
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is offline
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 08-02-2010, 03:04 PM Re: Fatal error: Cannot use string offset as an array in C:\wamp\www\S
Webmaster Talker

Posts: 611
Trades: 0
oops sorry.

Code:
//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']);
silverglade is offline
Reply With Quote
View Public Profile
 
Old 08-03-2010, 05:08 AM Re: Fatal error: Cannot use string offset as an array in C:\wamp\www\S
Webmaster Talker

Posts: 611
Trades: 0
nevermind I got it to work, not right, but it works. Thanks. Derek
silverglade is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Fatal error: Cannot use string offset as an array in C:\wamp\www\S
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.13455 seconds with 12 queries