unexpected $ (about 70 lines)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • RenTechie

    #1

    unexpected $ (about 70 lines)

    I get this error:
    Parse error: parse error, unexpected $ in [file] on line 63
    Where [file] is the path and filename for a file containing:
    <?php
    function cityname($style ="10engdir eng 50engloc"){//creates name for city
    return 'a city';
    };

    function powercentres($p op){//determines power centres for a city
    return array(1=>array( 'name'=>'pc1',' align'=>'true
    neutral','views '=>array(1=>'se lf'),'type'=>'c onventional'));
    $pcs=array();
    if($pop<=80){
    $roll=rand(1,20 );
    $align=rand(1,1 00);
    if($align<=35){
    $pcs[1]=array('align'= >'lawful good');
    }elseif($align< =39){
    $pcs[1]=array('align'= >'neutral good');
    }elseif($align< =41){
    $pcs[1]=array('align'= >'chaotic good');
    }elseif($align< =61){
    $pcs[1]=array('align'= >'lawful neutral');
    }elseif($align< =63){
    $pcs[1]=array('align'= >'true neutral');
    }elseif($align< =64){
    $pcs[1]=array('align'= >'chaotic neutral');
    }elseif($align< =90){
    $pcs[1]=array('align'= >'lawful evil');
    }elseif($align< =98){
    $pcs[1]=array('align'= >'neutral evil');
    }else{
    $pcs[1]=array('align'= >'chaotic evil');
    }
    if($roll-1<=13){
    $pcs[1]['type']='conventional' ;
    if(rand(1,20)== 1){
    }elseif($roll-1<=18){
    $pcs[1]['type']='nonstandard';
    }else{
    $pcs[1]['type']='magical';
    }
    };

    function npc($pop){//creates NPC population of city
    return
    array(1=>array( 'name'=>'npc1', 'lvl'=>array('f tr'=>1),'race'= >'human','stats '=>array('int'= >10,'wis'=>10,' str'=>10,'dex'= >10,'cha'=>10,' con'=>10),'save s'=>array('f'=> 2,'r'=>1,'w'=>1 ),'ac'=>10,'ali gn'=>'true
    neutral','skill s'=>20,'feats'= >2,'gear'=>'gea r','spells'=>'' ));
    };

    function sherrif($npcs){//chooses the sherrif
    return 1;
    };

    function makecity($pop){//creates stats for 1 city
    $city=array(
    'name'=>citynam e(),
    'pop'=>$pop,
    'urbanarea'=>($ pop/38850),//38,850 people per square mile
    'supportarea'=> ($pop/180),//1 square mile can support 180 people
    'powercentres'= >powercentres($ pop),
    'NPCs'=>npc($po p),
    'fulltimeLEO'=> floor($pop/100),//1 LEO per 100 people (DMG)
    'conscriptable' =>floor($pop/20)//1 conscriptable individual per 20 pop
    (DMG)
    );
    $city['sherrif']=sherrif($city['NPCs']);
    return($city);
    }
    ?>

    I know that some of the functions are returning before they do anything
    (I'm going bugeyed and want to make sure the overall works). What's
    this error from?

    TIA,
    RT
    If you wanna email me, remove the "SPAM."
  • Rik

    #2
    Re: unexpected $ (about 70 lines)

    RenTechie wrote:[color=blue]
    > I get this error:
    > Parse error: parse error, unexpected $ in [file] on line 63
    > Where [file] is the path and filename for a file containing:
    > <snip code>[/color]

    Check your nesting, opening and closing {}, I don't think they're right.
    Maybe it's disappeared in posting, but you function powercentres() doesn't
    seems to close here.

    Also, think about switch statements instead of elseif's.

    Further
    if($roll-1<=13){
    $pcs[1]['type']='conventional' ;
    if(rand(1,20)== 1){ // do you have a particular use for a new rand()?
    // you don't do anything here
    }elseif($roll-1<=18){
    $pcs[1]['type']='nonstandard';
    }else{
    $pcs[1]['type']='magical';
    }
    };

    Reads as: $pcs[1]['type'] is 'conventional' is $roll < 14, if $roll is > 14
    AND a new rand(1,20)==1, $pcs[1]['type'] doesn't get set at all!

    Also: all the code in your powercentres() function doesn't get executed, as
    the first thing you do is returning a statical array.

    Proper tools for coding (syntax highlighting) and indenting code could have
    told you a lot.

    It's not pretty, no it sure ain't.
    --
    Rik Wasmus


    Comment

    • RenTechie

      #3
      Re: unexpected $ (about 70 lines)

      Rik wrote:[color=blue]
      > RenTechie wrote:[color=green]
      >> I get this error:
      >> Parse error: parse error, unexpected $ in [file] on line 63
      >> Where [file] is the path and filename for a file containing:
      >> <snip code>[/color]
      > Check your nesting, opening and closing {}, I don't think they're right.
      > Maybe it's disappeared in posting, but you function powercentres() doesn't
      > seems to close here.
      > Also, think about switch statements instead of elseif's.
      > Reads as: $pcs[1]['type'] is 'conventional' is $roll < 14, if $roll is > 14
      > AND a new rand(1,20)==1, $pcs[1]['type'] doesn't get set at all!
      > Also: all the code in your powercentres() function doesn't get executed, as
      > the first thing you do is returning a statical array.
      > Proper tools for coding (syntax highlighting) and indenting code could have
      > told you a lot.
      > It's not pretty, no it sure ain't.[/color]

      It was a couple of unclosed blocks right where you pointed. I wanted to
      test the bigger function, and was returning static results to make sure
      that the structure came through. The bad indentations were because I
      went back and was adding stuff and decided to test.

      Thanks for the help,
      RT

      Comment

      Working...