Jump to content

Flying Script not working properly. Need Help.


crazyben0721
 Share

You are about to reply to a thread that has been inactive for 4676 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Hello I'm new to LSL Scripting and to SL. So far I'm working on a script that will set a texture of a prim when in flight and set to another texture when not in flight. So far this the code that I have and I think is not working probably because I'm using it in a infinite loop. I'm NOT sure what I'm doing wrong. :/

 

integer ownerInfo;
integer flightSwitch;

integer flightStaus(integer ownerStatus)
{
    //Returns a 1 if Owner is flying.
       if( ownerStatus & AGENT_FLYING )
       {
           return 1;
       }
       else
       {
            return 0; 
       }
}

default
{
    
    changed( integer change )
    {
        if (change & CHANGED_OWNER)
        {
            llResetScript();
        }
    }
    
    on_rez(integer start_param)
    {
        llResetScript(); 
    }
    
    state_entry()
    {
       key ownerKey = llGetOwner();
       ownerInfo = llGetAgentInfo(ownerKey);
       
       //Check if Owner is flying or not.
       flightSwitch = flightStaus(ownerInfo);
        if (flightSwitch == 1)
        { state isFlying; }
        else
        { state notFlying; }
       
       
    }

    touch_start(integer total_number)
    {
        llSay(0, "Touched.");
    }
}
        
state isFlying
{
    state_entry()
  {
        llSetPrimitiveParams([PRIM_TEXTURE, ALL_SIDES, TEXTURE_PLYWOOD, <1.0, 1.0, 0.0>, <0.0, 0.0, 0.0>, 0.0]);
        
        //Check if Owner is flying or not.
        flightSwitch = flightStaus(ownerInfo);
        if (flightSwitch == 1)
        { state isFlying; }
        else
        { state notFlying; }
  }

}
  
state notFlying
{
      state_entry()
    {
      llSetPrimitiveParams([PRIM_TEXTURE, ALL_SIDES, TEXTURE_TRANSPARENT, <1.0, 1.0, 0.0>, <0.0, 0.0, 0.0>, 0.0]);
    
        //Check if Owner is flying or not.
        flightSwitch = flightStaus(ownerInfo);
        if (flightSwitch == 1)
        { state isFlying; }
        else
        { state notFlying; }
    }
    
}

 

Link to comment
Share on other sites

The way to do what you're trying is to put your llGetAgentInfo call in a fast timer, checking it every second or less.  Potentially that's a lag problem in some circumstances, but it's the only way you can get a continuous monitor of your flying status.  Something like this .....

integer gON;default{	touch_start(integer total_number)	{		llSetTimerEvent(0.2* (gON = !gON));	}	timer()	{		if (llGetAgentInfo(llGetOwner())& AGENT_FLYING)		{			llSetPrimitiveParams([PRIM_TEXTURE, ALL_SIDES, "89556747-24cb-43ed-920b-47caed15465f", <1.0, 1.0, 0.0>, <0.0, 0.0, 0.0>, 0.0]);		}		else		{			llSetPrimitiveParams([PRIM_TEXTURE, ALL_SIDES, "8dcd4a48-2d37-4909-9f78-f7a9eb4ef903", <1.0, 1.0, 0.0>, <0.0, 0.0, 0.0>, 0.0]);		}	}}

 

Link to comment
Share on other sites

you can get a little better performance by checking if the flight status has changed rather than hitting prim params every single time regardless

integer gBitSwp; //-- swap variablekey     vKeyOwn; //-- owner keydefault{    state_entry(){        gKeyOwn = llGetOwner();        llSetTimerEvent( 1.0 );    }        timer(){ //-- lsl variable evaluation runs right to left        if ((gBitSwp = (llGetAgentInfo( gKeyOwn ) & AGENT_FLYING)) == gBitSwp){            if (gBitSwp){ //-- has a value                //-- changed to flight            }else{ //-- is zero                //-- changed to not flying            }        }    }        changed( integer vBitChg ){        if (CHANGED_OWNER & vBitChg){            llResetScript();        }    }}

 

  • Like 1
Link to comment
Share on other sites

  • 4 weeks later...

@Zack -- Take some time out to learn some basic building skills and to practice making simple scripted objects before you try things that are very complex.  Big goals are nice.  Baby steps are the way to get there.  Also, if you have a new question, feel free to start a new thread instead of appending it to an old one. 

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 4676 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...