dim3 Forum

Full Version: GRR bug
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Fy Trooper, script with bug:
Code:
var mood='guard';
var state='idle';
var secondaryState='';
var target;
var targetDistance='na';

function fyConstruct(obj)
{
    obj.model.on=true;
    obj.model.name='FY Trooper';
    obj.model.lit=DIM3_MODEL_LIT_VERTEX;
    obj.model.shadow.on=true;


    obj.setting.team='UNSEEN';
    obj.setting.openDoors=false;
    obj.setting.damage=true;
    obj.setting.ignorePickUpItems=true;
    
    obj.size.x=1299;
    obj.size.z=1318;
    obj.size.y=4476;
    obj.size.weight=230;
    
    obj.health.maximum=15;
    obj.health.start=15;
    obj.setting.pushable=true;
    obj.health.fallDamageMinimumHeight=5000;
    obj.health.fallDamageFactor=15;

    obj.turnSpeed.facingWalk=5;
    obj.turnSpeed.motionWalk=5;
    obj.turnSpeed.facingRun=5.2;
    obj.turnSpeed.motionRun=5.2;
    obj.turnSpeed.facingCrawl=4;
    obj.turnSpeed.motionCrawl=4;
    obj.turnSpeed.facingAir=4;
    obj.turnSpeed.motionAir=4;
    
    obj.forwardSpeed.walk=96;
    obj.forwardSpeed.crawl=51;
    obj.forwardSpeed.air=81;
    obj.forwardSpeed.acceleration=5;
    obj.forwardSpeed.deceleration=9;
    obj.forwardSpeed.accelerationAir=2.0;
    obj.forwardSpeed.decelerationAir=1.5;
    
    obj.sideSpeed.walk=61;
    obj.sideSpeed.run=121;
    obj.sideSpeed.crawl=31;
    obj.sideSpeed.air=51;
    obj.sideSpeed.acceleration=5;
    obj.sideSpeed.deceleration=9;
    obj.sideSpeed.accelerationAir=2.0;
    obj.sideSpeed.decelerationAir=1.5;

    obj.verticalSpeed.normal=51;
    obj.verticalSpeed.acceleration=11;
    obj.verticalSpeed.deceleration=21;

    obj.objectSpeed.bumpHeight=500;

    
        // setup weapon
        
    obj.weapon.add('pistol_bot');
}

function fySpawn(obj)
{
    obj.model.animation.showMesh('BL15');
    obj.model.animation.start('idle_guard');
    obj.watch.start(50000);
}

function fyAnimation(obj)
{
    if (mood=='guard') {
        obj.motionVector.stop();
    }

    switch (state) {
        case 'idle':
        obj.model.animation.startThenChange('idle_'+mood+secondaryState,'idle_'+mood);
        secondaryState='';
        obj.motionVector.stop();
        return;

        case 'walk':
        obj.forwardSpeed.walk=96;
        obj.motionVector.walkToObject(target);
        obj.model.animation.startThenChange('walk_agg'+secondaryState,'walk_agg');
        secondaryState='';
        return;
        
        case 'run':
        obj.forwardSpeed.walk=156;
        obj.motionVector.walkToObject(target);
        obj.model.animation.startThenChange('run_agg'+secondaryState,'run_agg');
        secondaryState='';
        return;

        case 'fall':
        secondaryState='';
        obj.model.animation.startThenChange('trip_'+mood,'falling');
        obj.motionVector.stop();
        return;

        case 'dead':
        secondaryState='';
        obj.model.animation.start('dead');
        obj.motionVector.stop();
        return;

        case 'fell':
        secondaryState='';
        obj.model.animation.start('fell');
        obj.motionVector.stop();
        return;
    }
}

function fyWatch(obj,subEvent)
{
    if (obj.watch.objectTeam!='UNSEEN') {
        switch (subEvent) {
            case DIM3_EVENT_WATCH_OBJECT_NEAR:
            fyDistanceSubtract(obj);
            target=obj.watch.objectId;
            mood='agg';
            return;
            
            case DIM3_EVENT_WATCH_OBJECT_FAR:
            fyDistanceAdd(obj);
            fyAnimation(obj);
            return;
            
            case DIM3_EVENT_WATCH_OBJECT_DEATH:
            obj.motionVector.stop();
            targetDistance='n/a'
            state=idle;
            fyAnimation;
            return;
        }
    }
}

function fyDistanceSubtract(obj)
{
    switch (targetDistance) {
            case 'na':
            targetDistance='far';
            state='idle';
            fyAnimation(obj);
            obj.watch.start(40000);
            return;
            
            case 'far':
            targetDistance='medium';
            state='run';
            fyAnimation(obj);
            obj.watch.start(30000);
            return;
            
            case 'medium':
            targetDistance='close';
            state='walk';
            fyAnimation(obj);
            obj.watch.start(20000);
            return;

            case 'close':
            targetDistance='closest';
            state='idle';
            fyAnimation(obj);
            obj.watch.start(10000);
            return;
    }
}

function fyDistanceAdd(obj)
{
    switch (targetDistance) {
            case 'closest':
            targetDistance='close';
            state='idle';
            fyAnimation(obj);
            obj.watch.start(5000);
            return;
            
            case 'far':
            targetDistance='na';
            state='run';
            fyAnimation(obj);
            obj.watch.start(30000);
            return;
            
            case 'medium':
            targetDistance='far';
            state='walk';
            fyAnimation(obj);
            obj.watch.start(20000);
            return;

            case 'close':
            targetDistance='medium';
            state='idle';
            fyAnimation(obj);
            obj.watch.start(10000);
            return;
    }
}

function event(obj,mainEvent,subEvent,id,tick)
{
    switch (mainEvent) {
    
        case DIM3_EVENT_CONSTRUCT:
            fyConstruct(obj);
            return;
    
        case DIM3_EVENT_SPAWN:
            fySpawn(obj);
            return;

        case DIM3_EVENT_FALL:
            state='fall';        
            return;

        case DIM3_EVENT_LAND:
            state='fell';
            return;

        case DIM3_EVENT_DIE:
            if (state!='fell') state='dead';
            return;

        //case DIM3_EVENT_COLLIDE:
        //    fyCollide(obj);
        //    return;

        //case DIM3_EVENT_DAMAGE:
        //    fyDamage(obj);
        //    return;

        case DIM3_EVENT_WATCH:
            fyWatch(obj,subEvent);
            return;
    }
}
PROBLEMS/QS:
*solved*Do I need the ' and 's when I assign a variable something thats not true false or a number?
*solved*Does this work?: if (state!='fell') state='dead';
*solved*Error, No anim named idle
*solved*Engine freezes
*solved*They chase after eachother
The game runs less than one fps with a bunch of these characters (usually runs about 25-45 fps, though it can go down to 15 or up to 60 in different parts of the map)
ccccc Wrote:And do I need the ' and 's when I assign a variable something thats not true false or a number?

Yes.
Theres a new bug, and I can't figure it out. Look ^^
teh1ghool Wrote:
ccccc Wrote:And do I need the ' and 's when I assign a variable something thats not true false or a number?

Yes.

The reason you need quotes is because the compiler can't tell the difference between a VARIABLE and a STRING, because BOTH can start with a letter.  All variables must start with a letter, as a matter of fact.

So ABC the variable versus ABC the constant value aren't something the compiler can figure out.  So you quote in this case.

Since numbers do NOT start with a letter, the compiler knows they are numbers, so they do NOT need quotes.

Same with true and false, which are special KEYWORDS.  Keywords are words that you can NOT use for variables because the compiler has special uses for them.

So:

Code:
var myString='ABC';     // need quotes
var myString2=myString;   // assigning contents of variable myString
                                     // to myString2, no quotes, it's a variable
var myNumber=5;    // number, don't need quotes
var myBoolean=true;  // true/false keywords, no quotes

Also, something that you'll see in my code a lot, is this:

Code:
if (myBoolean) {
....
}

Take this as shorthand for:

Code:
if (myBoolean==true) {
....
}

Also, the ! can be used:

Code:
if (!myBoolean) {
...
}
// is equal to
if (myBoolean==false) {
...
}

[>] Brian
On to why it freezes the engine:

Code:
function fyLoopHandler(obj)
{
    while (state=='run') {
        obj.forwardSpeed.walk=156;
        mood='agg';
    }
    while (state=='walk') {
        obj.forwardSpeed.walk=96;
        mood='agg';
    }
    while (state=='falling') {
        secondaryState='';
    }
    while (state=='dead') {
        obj.motionVector.stop();
        secondaryState='';
    }
    while (state=='fell') {
        secondaryState='';
    }
    while (mood=='guard') {
        obj.motionVector.stop();
    }
}

I assume you want "if" in place of "while".  You are asking for a number of infinite loops there.  You can probably simplify this a bit with:

Code:
function fyLoopHandler(obj)
{
    switch (state) {
      case 'run':
        obj.forwardSpeed.walk=156;
        mood='agg';
        break;
...
... rest here ....
    }

    if (mood=='guard') {
        obj.motionVector.stop();
    }
}

But first, replace the 'while's with 'if's and you should be good. The switch statement is basically a giant collection of ifs.

[>] Brian
Brian, does JS read "foo" where it reads inside the quotes as well as 'foo' where it takes exactly what is inside as a single string? I suppose it wouldn't, but I'm not sure?
teh1ghool Wrote:Brian, does JS read "foo" where it reads inside the quotes as well as 'foo' where it takes exactly what is inside as a single string? I suppose it wouldn't, but I'm not sure?

I'm not sure I get you here, but " and ' should be interchangable but they HAVE to match, of course.  I always just use ' for consistancy, but you can use either.

Note that if you want a ' in a string, you have to slash quote it:

Code:
var myString='Here\'s my string';

The \ character is a special character that tells the compiler to treat the next character different.  Of course, how do you get the \ character in a string?  \\, of course Smile

[>] Brian
In PHP it will read variables and functions inside a string surrounded by " and will not insinde a string surrounded by '.
Oh, I thought while only checked when it changed. As in I thought this:
[code]
while (a) {
doFoo(obj);
}
[code]
Would only check if the var changed. Not that that makes any sense, but, I thought the engine would just freeze every time you used while if that wasn't true lol.
(sorry for the double post)
Howcome when I set them to only chase non-UNSEEN teams team they still chase after eachother?
Code updated ^^

Sorry for all the Qs, I just can't figure this out :|!
Pages: 1 2
Reference URL's