unexpected $ (about 70 lines)

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
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:
function cityname($style="10engdir eng 50engloc"){//creates name for city
    return 'a city';
function powercentres($pop){//determines power centres for a city
    return array(1=>array('name'=>'pc1','align'=>'true  
            $pcs[1]=array('align'=>'lawful good');
            $pcs[1]=array('align'=>'neutral good');
            $pcs[1]=array('align'=>'chaotic good');
            $pcs[1]=array('align'=>'lawful neutral');
            $pcs[1]=array('align'=>'true neutral');
            $pcs[1]=array('align'=>'chaotic neutral');
            $pcs[1]=array('align'=>'lawful evil');
            $pcs[1]=array('align'=>'neutral evil');
            $pcs[1]=array('align'=>'chaotic evil');
function npc($pop){//creates NPC population of city
function sherrif($npcs){//chooses the sherrif
    return 1;
function makecity($pop){//creates stats for 1 city
        'urbanarea'=>($pop/38850),//38,850 people per square mile
        'supportarea'=>($pop/180),//1 square mile can support 180 people
        'fulltimeLEO'=>floor($pop/100),//1 LEO per 100 people (DMG)
        'conscriptable'=>floor($pop/20)//1 conscriptable individual per 20 pop  

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?

If you wanna email me, remove the "SPAM."

Re: unexpected $ (about 70 lines)

RenTechie wrote:
Quoted text here. Click to load it

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.

    if(rand(1,20)==1){ // do you have a particular use for a new rand()?
    // you don't do anything here

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

Re: unexpected $ (about 70 lines)

Rik wrote:
Quoted text here. Click to load it

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,

Site Timeline