Me and my Function

It seems like just yesterday my functions were working perfectly. And now I can’t even make a simple one. What’s wrong with me?

function baddy_touch(object){
    if(cursor.hitTest(object)==true){
        object_ovr=true;
        }
    if(cursor.hitTest(object)==false){
        object_ovr=false;
        }
}
onEnterFrame=function(){
    baddy_touch(baddy1);
    baddy_touch(baddy2);
}

I think it may be something with the way I’m defining my function. But…it just seems like it was working this way before.
(-:

is cursor an mc?

Yes, cursor is an MC, I just named it than since I was switching from a cursor interface to an object based control.
:goatee:

i think you will find that object is a reserved word…it would be like calling a variable this…its getting confused…try renaming the object variable to something else like “thing”

:wasted:
Changed it to thing. Still runs the second one but not the first.

function baddy_touch(thing){
    if(cursor.hitTest(thing)==true){
        object_ovr=true;
        }
    if(cursor.hitTest(thing)==false){
        object_ovr=false;
        }
}
onEnterFrame=function(){
    baddy_touch(baddy1);
    baddy_touch(baddy2);
}

you did that? im assuming baddy1 and baddy 2 have been declared as movie clips, and that their instance names have both been set correctly?

I love it when things do this to me.
Yes, that’s the exact code I have.
And the mc’s are inctanced correctly.
love that word “Inctanced”
:frowning:

where and how is “object_ovr” declared?

farther up, above the function and a bunch of other code.
It’s declared at

object_ovr=false;

try putting a var in front of it as you declare it

Same thing. Only detects the second mc, never the first.

so baddy1 never works?? im guessing the problem is in that, thats where id be searching…

If I re-order them

[FONT=Courier New][COLOR=#0000ff]onEnterFrame[/COLOR]=[COLOR=#000000]**function**[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000]{[/COLOR]
     baddy_touch[COLOR=#000000]([/COLOR]baddy2[COLOR=#000000])[/COLOR];
     baddy_touch[COLOR=#000000]([/COLOR]baddy1[COLOR=#000000])[/COLOR];
[COLOR=#000000]}

[/COLOR][/FONT]
only baddy1 works.
:stunned:

If I re-order them.

ActionScript Code:
[FONT=Courier New][LEFT][FONT=Courier New][COLOR=#0000ff]onEnterFrame[/COLOR]=[COLOR=#000000]function[/COLOR]COLOR=#000000[/COLOR][COLOR=#000000]{[/COLOR]
baddy_touchCOLOR=#000000[/COLOR];
baddy_touchCOLOR=#000000[/COLOR];
[COLOR=#000000]}[/COLOR][/FONT]
[/LEFT]
[/FONT]

[FONT=Courier New][COLOR=#000000]It only detects baddy1.
:smirk:
[/COLOR][/FONT]


function baddy_touch(thing1, thing2){
    if(cursor.hitTest(thing1)==true || cursor.hitTest(thing2)==true){
        object_ovr=true;
    } else {
        object_ovr=false;
    }
}
onEnterFrame=function(){
    baddy_touch(baddy1, baddy2);
}

try that

This happens because you’re having them define the same variable (object_ovr). If you traced the variable between the two function calls, it would have the correct value for whichever one came first (and the second if you traced that variable again after the second call).

C:-)
Thanx for trying and all, but I know that will work. But in the future I might have to define more baddys etc. So getting the other way to work is a prieority (sp?)

as the last guy has just said, your logic is flawed…one result is overwriting the other…

I don’t quite get you.
:cantlook:
Gee, I’m sorry. But if you could write out a code snippet.
:*(

baddy1 is tested, it returns true, however when baddy2 is tested after it, it can not possibly be true because the hit test is on the other one, so it is automatically false, however it resets the object_ovr value to false, thus negating the original value of true.

you need to rethink your logic…maybe a touched value for every baddy (ie baddy1.is_ovr)…