dim3 Forum

Full Version: Problem, "Missing after function body"
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Right, so I was playing around with alex's terrorist script (With permission), and it keeps complaining in the console:

Code:
218, SyntaxError: Missing  after function body


Between missing and after, I think, is a double space. I imagine this means something I havn't put in yet, or something.

Heres the modifyed script:

Code:
//
//    Terrorist Bot Script
//  -----------------
//
//  Stationary Type
//
// ******************************************************************************** ************

var maxShots;
var currentShots;
var lastHitTick;
var closehitrand;

function construct(obj) {
    obj.model.on=true;
    obj.model.name="enemy_terrorist1";
    obj.model.lit=DIM3_MODEL_LIT_VERTEX;
    obj.setting.damage=true;
    obj.size.x=1000;
    obj.size.z=948;
    obj.size.y=3212;
    obj.size.weight=250;

    obj.radar.on=true;
    obj.radar.icon="enemy";
    obj.radar.on=true;
    obj.radar.motionOnly=true;

    obj.radar.on=true;
    obj.radar.icon="enemy";
    obj.radar.on=true;

// melee time!

    obj.melee.strikeBoneTag='barr';
    obj.melee.strikePoseName='Hit2.2';
    obj.melee.radius=1000;
    obj.melee.distance=1000;        
    obj.melee.damage=20;
    obj.melee.force=15;

    obj.sight.sideFieldAngle=0;
    obj.sight.lookFieldAngle=90;
//    obj.sight.sideFieldDivision=1;
//    obj.sight.lookFieldDivision=8;
    obj.sight.distance=5000;
    obj.weapon.add('terrorist_smg');
    obj.weapon.add('splatter');

    obj.health.maximum=50;
    obj.health.start=50;

    obj.turnSpeed.motionWalk=6;
    obj.turnSpeed.facingWalk=6;

    obj.setting.openDoors=false;
    obj.setting.ignorePickUpItems=true;        // don't pickup the weapons/ammo

}

function spawn(obj) {

    obj.watch.start(5000);

}

function watch(obj,subEvent) {

    if((!obj.sight.testPlayer)||(!obj.watch.objectIsPlayer)||(subEvent!=DIM3_EVENT_WATCH_OBJECT_NEAR))return;
    else {
    var rand=utility.random.getInteger(1,10);
    obj.event.chain(rand,'standup');
    }
    if((obj.watch.objectIsPlayer)&&(subEvent!=DIM3_EVENT_WATCH_OBJECT_NEAR)) {
    obj.event.clearTimer();
    obj.event.clearChain();
    }
}

function standup(obj) {

    obj.size.x=1000;
    obj.size.z=948;
    obj.size.y=3212;
    obj.radar.on=true;

    obj.model.animation.startThenChange('crouchtostand','standing');
    obj.event.chain(2,'openfire');

    if (obj.position.distanceToPlayer()>3000) {

    var closehitrand = utility.random.getInteger(1,4);

    if (closehitrand == 1) {

    obj.event.chain('meleestrike');

}

    if (closehitrand == 2) {

    obj.event.chain('meleestrike');

}

    if (closehitrand == 3) {

    obj.event.chain('meleestrike');

}

    if (closehitrand == 4) {

    obj.event.chain(2,'openfire');

}

}

function openfire(obj) {
    maxShots=utility.random.getInteger(5,20);
    currentShots=0;
    obj.motionVector.turnToPlayer();
    obj.event.startTimer(1,0); // alter refire rate here;
}

function timer(obj) {
    obj.model.animation.start('fire');
    obj.weapon.fire('terrorist_smg',0);
    if (currentShots<maxShots) {
    currentShots=currentShots+1;
    }
    else {
    obj.event.clearTimer();
    obj.radar.on=false;
    obj.model.animation.startThenChange('standtocrouch','crouch');
    obj.motionAngle.turnStop();
    var rand=utility.random.getInteger(20,60);
    obj.event.chain(rand,'standup');
    }
}

function damage(obj,tick) {
    var        health,pauseCount;    
    health=obj.health.current;
    if (health<=0) return;    
    obj.event.clearChain();
    obj.model.lit=DIM3_MODEL_LIT_VERTEX;        
    switch (obj.hit.hitBoxName) {
    
        case 'Object':
            var anim=utility.random.getInteger(1,3);
            obj.model.animation.interrupt('flinch'+anim);
            pauseCount=4;
            break;

        default:
            var anim=utility.random.getInteger(1,3);
            obj.model.animation.interrupt('flinch'+anim);
            pauseCount=4;
            break;            
    }
    
    obj.watch.stop();
        
    obj.motionVector.stop();
    obj.motionAngle.turnStop();

    obj.event.chain(pauseCount,'standup');
}

function die(obj) {
    obj.model.animation.startThenChange('dying','dead');
    obj.weapon.fire('splatter');
    obj.radar.on=false;
    obj.setting.contact=false;
    obj.setting.suspend=true;
    obj.event.clearTimer();
    obj.event.clearChain();
    obj.radar.on=false;
    obj.watch.stop();
}

function meleestrike(obj) {

    obj.size.x=0;
    obj.size.z=0;
    obj.size.y=0;

    obj.model.animation.start('Hit');    

    obj.event.chain(10,'standup');
}

function event(obj,event,subEvent,id,tick) {
    switch(event) {
    case DIM3_EVENT_CONSTRUCT:
    construct(obj);
    break;

    case DIM3_EVENT_SPAWN:
    obj.watch.start(70000);
    obj.model.animation.start('crouch');
    break;

    case DIM3_EVENT_WATCH:
    watch(obj,subEvent);
    break;

    case DIM3_EVENT_TIMER:
    timer(obj);
    break;

    case DIM3_EVENT_DAMAGE:
    damage(obj,tick);
    break;

    case DIM3_EVENT_DIE:
    die(obj);
    break;

    }
}

Yeah in the standup() function you're missing a } at the end. You open an 'if' but never close it.
Okay, thanks, i'll try it, and edit this post with the results.

EDIT: so now they appear, but the royalists just stand there, doing nothing. If you shoot them, they kinda fire once or twice but no shots come out, then they either duck and freeze again or stand and freeze. And there are no console errors.
It's my script, but I didn't make it! MacintoshHD did. Smile I don't want anyone thinking I'm good enough to do something like that.

Typewriter Wrote:
Okay, thanks, i'll try it, and edit this post with the results.

EDIT: so now they appear, but the royalists just stand there, doing nothing. If you shoot them, they kinda fire once or twice but no shots come out, then they either duck and freeze again or stand and freeze. And there are no console errors.


iface.console.write('xxxx'); is your best friend in cases like this. With so many events and timers, sometimes you'll just want to know WHAT the script is doing at any moment. For instance, standup:

Code:
function standup(obj) {

    iface.console.write('in standup()');

    obj.size.x=1000;
    obj.size.z=948;
    obj.size.y=3212;
    obj.radar.on=true;

    obj.model.animation.startThenChange('crouchtostand','standing');
    obj.event.chain(2,'openfire');

    if (obj.position.distanceToPlayer()>3000) {

      var closehitrand = utility.random.getInteger(1,4);

      if (closehitrand == 1) {
        iface.console.write('closehitrand was 1');
        obj.event.chain('meleestrike');
     }

      if (closehitrand == 2) {
        iface.console.write('closehitrand was 2');
        obj.event.chain('meleestrike');
      }


Then you can watch the console and see what the script is doing. The error is always something obvious like a timer didn't get restarted or your not getting the numbers that you think you are, or the watch, etc.

Also, try to be careful with the indents. The reason you want to indent properly is it helps you catch when {} are off and certainly helps you watch the flow of the logic.

As for problems, check out this function:

Code:
function watch(obj,subEvent) {

    if((!obj.sight.testPlayer)||(!obj.watch.objectIsPlayer)||(subEvent!=DIM3_EVENT_WATCH_OBJECT_NEAR))return;
    else {
    var rand=utility.random.getInteger(1,10);
    obj.event.chain(rand,'standup');
    }
    if((obj.watch.objectIsPlayer)&&(subEvent!=DIM3_EVENT_WATCH_OBJECT_NEAR)) {
    obj.event.clearTimer();
    obj.event.clearChain();
    }
}


Not sure what's going on there, but the else { doesn't belong to anything. What's the logic supposed to be for that?

[>] Brian

Okay, I did that, and it always stopped on the standup. Meaning i get:
Damage,
Then standup,
When I shoot it, In the console. So I tried changing the last bit to:

Code:
function damage(obj,tick) {
    var        health,pauseCount;    
    health=obj.health.current;
    if (health<=0) return;    
    obj.event.clearChain();
    obj.model.lit=DIM3_MODEL_LIT_VERTEX;        
    switch (obj.hit.hitBoxName) {
    
        case 'Object':
            var anim=utility.random.getInteger(1,3);
            obj.model.animation.interrupt('flinch'+anim);
            pauseCount=4;
            break;

        default:
            var anim=utility.random.getInteger(1,3);
            obj.model.animation.interrupt('flinch'+anim);
            pauseCount=4;
            break;            
    }
    
    obj.watch.stop();
        
    obj.motionVector.stop();
    obj.motionAngle.turnStop();

    obj.event.chain(pauseCount,'watch');
}

function die(obj) {
    obj.model.animation.startThenChange('dying','dead');
    obj.weapon.fire('splatter');
    obj.radar.on=false;
    obj.setting.contact=false;
    obj.setting.suspend=true;
    obj.event.clearTimer();
    obj.event.clearChain();
    obj.radar.on=false;
    obj.watch.stop();
}

function meleestrike(obj) {

    obj.size.x=0;
    obj.size.z=0;
    obj.size.y=0;

    obj.model.animation.start('Hit');    

    obj.event.chain(10,'watch);
}

Then I get:
Damage, then watching, then standup, when I shoot it.
If you didn't notice, the change is that the meleestrike and damage now chain to "Watch". So the watch works, but the problem is that it goes right back to standup. And I think the problem is that for some reason, the Royalist's sight distance has been reduced to zero or something, but I cant workout why.
Great thanks if you can help.

When you do this in the damage function:

Code:
obj.event.chain(pauseCount,'watch');


You're just calling the watch function once, not actually starting a watch. Do you want:

Code:
obj.watch.start(5000);


That's probably one mistake. Can you post the current watch function in this thread, what's there in the original is wacky and I want to see what it looks like now, as it might need some fixing.

Side note: Chain means "wait this long, then call this function." Setting a watch means "call this function WHENEVER (i.e., multiple times) other objects go into or out of the watch distance".

Think of chains as a ... chain Smile Go to function A, then B, then C. Think of timers and watches as "keep going back to A over and over" and waits as single fire timers.

[>] Brian

Code:
//

//    Terrorist Bot Script
//  -----------------
//
//  Stationary Type
//

// ******************************************************************************** ************



var maxShots;
var currentShots;
var lastHitTick;
var closehitrand;

function construct(obj) {

    obj.model.on=true;
    obj.model.name="enemy_terrorist1";
    obj.model.lit=DIM3_MODEL_LIT_VERTEX;
    obj.setting.damage=true;
    obj.size.x=1000;
    obj.size.z=948;
    obj.size.y=3212;
    obj.size.weight=250;

    obj.radar.on=true;
    obj.radar.icon="enemy";
    obj.radar.on=true;
    obj.radar.motionOnly=true;

    obj.radar.on=true;
    obj.radar.icon="enemy";
    obj.radar.on=true;

// melee time!

    obj.melee.strikeBoneTag='barr';

    obj.melee.strikePoseName='Hit2.2';

    obj.melee.radius=1000;

    obj.melee.distance=1000;        

    obj.melee.damage=20;

    obj.melee.force=15;

    obj.sight.sideFieldAngle=0;
    obj.sight.lookFieldAngle=90;
//    obj.sight.sideFieldDivision=1;
//    obj.sight.lookFieldDivision=8;
    obj.sight.distance=5000;
    obj.weapon.add('terrorist_smg');
    obj.weapon.add('splatter');

    obj.health.maximum=50;
    obj.health.start=50;

    obj.turnSpeed.motionWalk=6;
    obj.turnSpeed.facingWalk=6;

    obj.setting.openDoors=false;
    obj.setting.ignorePickUpItems=true;        // don't pickup the weapons/ammo

}

function spawn(obj) {

    iface.console.write('Spwned()');

    obj.watch.start(5000);

}

function watch(obj,subEvent) {

    iface.console.write('Watchin()');

    if((!obj.sight.testPlayer)||(!obj.watch.objectIsPlayer)||(subEvent!=DIM3_EVENT_WATCH_OBJECT_NEAR))return;
    else {
    var rand=utility.random.getInteger(1,10);
    obj.event.chain(rand,'standup');
    }
    if((obj.watch.objectIsPlayer)&&(subEvent!=DIM3_EVENT_WATCH_OBJECT_NEAR)) {
    obj.event.clearTimer();
    obj.event.clearChain();
    }
}

function standup(obj) {

    iface.console.write('in standup()');
    obj.radar.on=true;

    obj.model.animation.startThenChange('crouchtostand','standing');
    obj.event.chain(2,'openfire');

    if (obj.position.distanceToPlayer()>3000) {

    var closehitrand = utility.random.getInteger(1,4);

    if (closehitrand == 1) {

    obj.event.chain('meleestrike');

}

    if (closehitrand == 2) {

    obj.event.chain('meleestrike');

}

    if (closehitrand == 3) {

    obj.event.chain('meleestrike');

}

    if (closehitrand == 4) {

    obj.watch.start(25000);

}
}

}

function openfire(obj) {

    iface.console.write('in openfire()');


    maxShots=utility.random.getInteger(5,20);
    currentShots=0;
    obj.motionVector.turnToPlayer();
    obj.event.startTimer(1,0); // alter refire rate here;
}

function timer(obj) {
    obj.model.animation.start('fire');
    obj.weapon.fire('terrorist_smg',0);
    if (currentShots<maxShots) {
    currentShots=currentShots+1;
    }
    else {
    obj.event.clearTimer();
    obj.radar.on=false;
    obj.model.animation.startThenChange('standtocrouch','crouch');
    obj.motionAngle.turnStop();
    var rand=utility.random.getInteger(20,60);
    obj.event.chain(rand,'standup');
    }
}

function damage(obj,tick) {

    iface.console.write('Damage()');
    var        health,pauseCount;    

    health=obj.health.current;

    if (health<=0) return;    

    obj.event.clearChain();

    obj.model.lit=DIM3_MODEL_LIT_VERTEX;        

    switch (obj.hit.hitBoxName) {

    

        case 'Object':

            var anim=utility.random.getInteger(1,3);
            obj.model.animation.interrupt('flinch'+anim);

            pauseCount=4;

            break;

        default:

            var anim=utility.random.getInteger(1,3);
            obj.model.animation.interrupt('flinch'+anim);

            pauseCount=4;

            break;            

    }

    

    obj.watch.stop();

        

    obj.motionVector.stop();

    obj.motionAngle.turnStop();

    obj.watch.start(25000);
}

function die(obj) {
    iface.console.write('Die()');
    obj.model.animation.startThenChange('dying','dead');
    obj.weapon.fire('splatter');
    obj.radar.on=false;
    obj.setting.contact=false;
    obj.setting.suspend=true;
    obj.event.clearTimer();
    obj.event.clearChain();
    obj.radar.on=false;
    obj.watch.stop();
}

function meleestrike(obj) {

    iface.console.write('Melee()');

    obj.size.x=0;
    obj.size.z=0;
    obj.size.y=0;

    obj.model.animation.start('Hit');    

    obj.watch.start(25000);
}

function event(obj,event,subEvent,id,tick) {
    switch(event) {
    case DIM3_EVENT_CONSTRUCT:
    construct(obj);
    break;

    case DIM3_EVENT_SPAWN:
    obj.watch.start(70000);
    obj.model.animation.start('crouch');
    break;

    case DIM3_EVENT_WATCH:
    watch(obj,subEvent);
    break;

    case DIM3_EVENT_TIMER:
    timer(obj);
    break;

    case DIM3_EVENT_DAMAGE:
    damage(obj,tick);
    break;

    case DIM3_EVENT_DIE:
    die(obj);
    break;

    }
}


Right, thanks i changed those two bits. I can see thatit always gets stuck in the standup, and the only changes i have made from that are this:

Code:
    var closehitrand = utility.random.getInteger(1,4);

    if (closehitrand == 1) {

    obj.event.chain('meleestrike');

}

    if (closehitrand == 2) {

    obj.event.chain('meleestrike');

}

    if (closehitrand == 3) {

    obj.event.chain('meleestrike');

}

    if (closehitrand == 4) {

    obj.watch.start(25000);

}
}


So, why doesn't that work?

For starters, use a switch(). Second, shouldn't the chain() func have two inputs? Pause count and function.

Code:
var closehitrand = utility.random.getInteger(1,4);

    switch(closehitrand) {

    case 1:
    obj.event.chain('meleestrike');
    break;

    case 2:
    obj.event.chain('meleestrike');
    break;

    case 3:
    obj.event.chain('meleestrike');
    break;

    case 4:
    obj.watch.start(25000);
    break;

}

Okay thanks teh1ghool, that was me kinda experimenting with randomness, something i have yet to master.

Teh1 ghool + ggadwa = 2 legends.

EDIT:

okay, slowly progressing.

Now i have

Code:
//

//    Terrorist Bot Script
//  -----------------
//
//  Stationary Type
//

// ******************************************************************************** ************



var maxShots;
var currentShots;
var lastHitTick;
var closehitrand;

function construct(obj) {

    obj.model.on=true;
    obj.model.name="enemy_terrorist1";
    obj.model.lit=DIM3_MODEL_LIT_VERTEX;
    obj.setting.damage=true;
    obj.size.x=1000;
    obj.size.z=948;
    obj.size.y=3212;
    obj.size.weight=250;

    obj.radar.on=true;
    obj.radar.icon="enemy";
    obj.radar.on=true;
    obj.radar.motionOnly=true;

    obj.radar.on=true;
    obj.radar.icon="enemy";
    obj.radar.on=true;

// melee time!

    obj.melee.strikeBoneTag='barr';

    obj.melee.strikePoseName='Hit2.2';

    obj.melee.radius=1000;

    obj.melee.distance=1000;        

    obj.melee.damage=20;

    obj.melee.force=15;

    obj.sight.sideFieldAngle=0;
    obj.sight.lookFieldAngle=90;
//    obj.sight.sideFieldDivision=1;
//    obj.sight.lookFieldDivision=8;
    obj.sight.distance=5000;
    obj.weapon.add('terrorist_smg');
    obj.weapon.add('splatter');

    obj.health.maximum=50;
    obj.health.start=50;

    obj.turnSpeed.motionWalk=6;
    obj.turnSpeed.facingWalk=6;

    obj.setting.openDoors=false;
    obj.setting.ignorePickUpItems=true;        // don't pickup the weapons/ammo

}

function spawn(obj) {

    iface.console.write('Spwned()');

    obj.watch.start(25000);

}

function watch(obj,subEvent) {

    iface.console.write('Watchin()');

    if((!obj.sight.testPlayer)||(!obj.watch.objectIsPlayer)||(subEvent!=DIM3_EVENT_WATCH_OBJECT_NEAR))return;
    else {
    var rand=utility.random.getInteger(1,10);
    obj.event.chain(rand,'standup');
    }
    if((obj.watch.objectIsPlayer)&&(subEvent!=DIM3_EVENT_WATCH_OBJECT_NEAR)) {
    obj.event.clearTimer();
    obj.event.clearChain();
    }
}

function standup(obj) {

    iface.console.write('in standup()');
    obj.radar.on=true;

    obj.model.animation.startThenChange('crouchtostand','standing');
    obj.event.chain(2,'openfire');

    if (obj.position.distanceToPlayer()>3000) {

    var closehitrand = utility.random.getInteger(1,4);

var closehitrand = utility.random.getInteger(1,4);

    switch(closehitrand) {

    case 1:
    obj.event.chain(1,'meleestrike');
    break;

    case 2:
    obj.event.chain(1,'meleestrike');
    break;

    case 3:
    obj.event.chain(1,'meleestrike');
    break;

    case 4:
    obj.event.chain(1,'openfire');
    break;

}
}

}

function openfire(obj) {

    iface.console.write('in openfire()');


    maxShots=utility.random.getInteger(5,20);
    currentShots=0;
    obj.motionVector.turnToPlayer();
    obj.event.startTimer(1,0); // alter refire rate here;
}

function timer(obj) {
    obj.model.animation.start('fire');
    obj.weapon.fire('terrorist_smg',0);
    if (currentShots<maxShots) {
    currentShots=currentShots+1;
    }
    else {
    obj.event.clearTimer();
    obj.radar.on=false;
    obj.model.animation.startThenChange('standtocrouch','crouch');
    obj.motionAngle.turnStop();
    var rand=utility.random.getInteger(20,60);
    obj.event.chain(rand,'standup');
    }
}

function damage(obj,tick) {

    iface.console.write('Damage()');
    var        health,pauseCount;    

    health=obj.health.current;

    if (health<=0) return;    

    obj.event.clearChain();

    obj.model.lit=DIM3_MODEL_LIT_VERTEX;        

    switch (obj.hit.hitBoxName) {

    

        case 'Object':

            var anim=utility.random.getInteger(1,3);
            obj.model.animation.interrupt('flinch'+anim);

            pauseCount=4;

            break;

        default:

            var anim=utility.random.getInteger(1,3);
            obj.model.animation.interrupt('flinch'+anim);

            pauseCount=4;

            break;            

    }

    

    obj.watch.stop();

        

    obj.motionVector.stop();

    obj.motionAngle.turnStop();

    obj.watch.start(25000);
}

function die(obj) {
    iface.console.write('Die()');
    obj.model.animation.startThenChange('dying','dead');
    obj.weapon.fire('splatter');
    obj.radar.on=false;
    obj.setting.contact=false;
    obj.setting.suspend=true;
    obj.event.clearTimer();
    obj.event.clearChain();
    obj.radar.on=false;
    obj.watch.stop();
}

function meleestrike(obj) {

    iface.console.write('Melee()');

    obj.size.x=0;
    obj.size.z=0;
    obj.size.y=0;

    obj.model.animation.start('Hit');    

    obj.watch.start(25000);
}

function event(obj,event,subEvent,id,tick) {
    switch(event) {
    case DIM3_EVENT_CONSTRUCT:
    construct(obj);
    break;

    case DIM3_EVENT_SPAWN:
    obj.watch.start(70000);
    obj.model.animation.start('crouch');
    break;

    case DIM3_EVENT_WATCH:
    watch(obj,subEvent);
    break;

    case DIM3_EVENT_TIMER:
    timer(obj);
    break;

    case DIM3_EVENT_DAMAGE:
    damage(obj,tick);
    break;

    case DIM3_EVENT_DIE:
    die(obj);
    break;

    }
}


And now whenever i get within the watch range (25000), it does the melee, instead of the openfire. *Annoyed*

Pages: 1 2
Reference URL's