Jump to content
  • 0

How can i say "if this is bigger than that" in LSL?


Philip Elegy
 Share

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

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

Question

5 answers to this question

Recommended Posts

  • 0

Then what is wrong with my script?

I am trying to make two elevators. This is the script from what I call the "Elevator control panel". It is supposed to receive commands from the caller-buttons, calculate the difference they have from both elevators and then, if the left one has a bigger difference from the right one, send the right one to the caller's floor or else send the left one to the caller's floor.

This is my script so far...

integer RLevel; // Right elevator's level
integer LLevel; // Left elevator's level
integer CLevel; // Caller's level
string sRLevel; // Right elevator's level (string)
string sLLevel; // Left elevator's level (string)
string sCLevel; // Caller's level (string)
integer RDiff; // Right elevator's difference from caller's level
integer LDiff; // Left elevator's difference from caller's level
default
{
    state_entry()
    {
        ShowText = 1;
        llSetText("Starting up", <1,1,0>, 1);
        llRegionSay(-1, "R90"); // This tells the right elevator to go to ground level
        RLevel = 0;
        llRegionSay(-1, "L90"); // This tells the left elevator to go to ground level
        LLevel = 0;
        llRegionSay(-1, "0D190"); // This opens the right ground level's door
        llRegionSay(-1, "0D290"); // This opens the left ground level's door
        llRegionSay(-1, "1D191"); //*
        llRegionSay(-1, "1D291"); //*
        llRegionSay(-1, "2D191"); //*
        llRegionSay(-1, "2D291"); //*
//* = Closes a door
        llListen(-1, "", "", "");
        llSetText("Waiting for command", <0,1,0>, 1);
    }
    listen(integer channel, string name, key id, string message)
    {
        llSetText("Got command", <0,1,0>, 1);
        if (message == "901") // This is from caller button the digit in the middle (0 in this case) indicates the level
        {
            CLevel = 0;
        }
        else if (message == "911")
        {
            CLevel = 1;
        }
        else if (message ==  "921")
        {
            CLevel = 2;
        }
        llSetText("Finding nearest elevator", <0,1,0>, ShowText);
        if (LLevel < CLevel)
        {
            LDiff = CLevel - LLevel;
        }
        else if (LLevel > CLevel)
        {
            LDiff = LLevel - CLevel;
        }
        if (RLevel < CLevel)
        {
            RDiff = CLevel - RLevel;
        }
        else if (RLevel > CLevel)
        {
            RDiff = RLevel - CLevel;
        }
        llSetText("Changing variables to strings", <0,1,0>, 1);
        sRLevel = (string)RLevel;
        sLLevel = (string)LLevel;
        sCLevel = (string)CLevel;
        llSetText("Calling elevator", <0,1,0>, 1);
        if (RDiff < LDiff)
        {
            llRegionSay(-1, sRLevel + "D191"); // Right elevator's door close
            llRegionSay(-1, sCLevel + "911"); // Tell the caller that the right elevator is comming
            llRegionSay(-1, "R9" + sCLevel); // Right elevator go to caller level
            RLevel = CLevel;
            llRegionSay(-1, sCLevel + "D190"); // Door open
        }
        else
        {
            llRegionSay(-1, sLLevel + "D291"); // Left elevator's door close
            llRegionSay(-1, sCLevel + "912"); // Tell the caller that the left elevator is coming
            llRegionSay(-1, "L9" + sCLevel); // Left elevator go to caller level
            LLevel = CLevel;
            llRegionSay(-1, sCLevel + "D290"); // Door open
        }
        llSetText("Waiting for command", <0,1,0>, 1);
    }
}
Link to comment
Share on other sites

  • 0

There's nothing obviously wrong in there, apart from the logic being a little overcomplicated.  Without having the whole system it's going to be difficult for us to debug this in the forum.  Feel free to contact me inworld if you get really stuck.

The best way for you to troubleshoot this is to insert outputs into the significant parts of the logic so you can see what's going on (use llOwnerSay()), so you know when certain conditions are being met.  For example...

if(x > y)

{

     llOwnerSay("x is greater than y");

     <existing code>

}

else

{

     llOwnerSay("x is NOT greater than y");

}

Hope that helps.

Link to comment
Share on other sites

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