Jump to content

Why wont my IF statement work? ><


LaniFlower
 Share

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

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

Recommended Posts

Hey all, noob to LSL (although I have a little knowledge of other languages like c#).   I'm really sorry but I have such a dumb issue I simply cant fix myself and I wondered if I could ask for you wise words on this;

What I'm trying to do;

I have a prim with a simple function,#; it toggles a boolean integer value TRUE and FALSE and using a timer, spins a prim for a couple of seconds in one direction if the value is TRUE, the reverses the spin if the value is FALSE, like you would see the swing of a pendulum.  I haven't been able to make it change direction.  After spending hours going down a rabbit hole thinking my llSetTargetOmega call was dodgy, i realised its actually the control logic that is flawed.  

I then wondered whether my state handling was doing it, (the prim has an on off state toggled by touch_start) but when i removed that and just used the default state, I still have the problem. 

So here is the code snippet without any state logic and with just the control logic enabled plus a couple of debug messages so I can watch the code paths taken.  As you will see when you run it, it never reaches the code in the else statement.  I have tried two IF without ELSES, didn't work either.  

integer direction = TRUE;

default
{
    state_entry()
    {
        llSetText("ON", <0,1,0>, 1.0);
        llSetTimerEvent(2.0);
    }

    timer()
    {

        if ( direction = TRUE )
        { 
            llSay(0,"Back");
            //llTargetOmega(<0,0,-0.5>,0.5,PI);
        }        
        else
        {
            llSay(0,"Forth");
            //llTargetOmega(<0,0,0.5>,0.5,PI); 
        }

        direction = !direction;
    }
}
 

I'm tearing my hair out here, I thought I knew how to code!! Please could someone help me see what I'm doing wrong?

Many many thanks in advance, Lisa x ♥

Link to comment
Share on other sites

You need to use == instead of =. What you are actually doing is assigning the value with a single = sign instead of comparing it. It's the most common of all coding errors, not just in LSL, but through all the similar-syntax languages such as C, java, ...

 

I far preferred Fortran's .EQ. .NE. and so on. far less chance of this sort of error cropping up.

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 1644 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...