Jump to content

Between these or between these or between these...


Sabastian Zane
 Share

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

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

Recommended Posts

Dear All,

I have been in SL quite a few years, but my scripting skills are still quite raw.  I'm after some tips please to reduce my scripting down to less lines, as I am sure there must be a better way and I just can't understand on the wiki as they don't always explain all the possible configurations.

I want to check the value of a time is between certain minutes (i.e. between 21and 30, between 31 and 40, between 41 and 50 or above 50) so that my "speaking clock" will read out "20","30","40" or "50" before it reads the minutes (i.e. "50" "1" for 51 minutes.

Could anybody kindly help me in getting the syntax right so that it can check all of the above in one "IF" instead of having to do IF > ELSE in the same way I have?

I'm basically hoping to say something like 

if (Minute>=21 && Minute<30) or (Minute>=31 && Minute<40) or (Minute>=41 && Minute<50) or (Minute>50)

For your reference "Minute" is the variable taken from the time and represents the minutes in the hour. unimin = the unit measurement of the minutes, decmin = the tens measurement of the minutes  (i.e. if the time is 15:34 then the decmin would equal "3" and the unimin would equal "4")

a snippet of my huge code below  - Thank you so much in advance!! 

 

       if (Minute>=21 && Minute<30)
         {
             if (unimin==1)
            {
                llPlaySound("1",1.0);
            }
            else if (unimin==2)
            {
                llPlaySound("2",1.0);
            }
            else if (unimin==3)
            {
                llPlaySound("3",1.0);
            }
            else if (unimin==4)
            {
                llPlaySound("4",1.0);
            }
            else if (unimin==5)
            {
                llPlaySound("5",1.0);
            }
            else if (unimin==6)
            {
                llPlaySound("6",1.0);
            }
            else if (unimin==7)
            {
                llPlaySound("7",1.0);
            }
            else if (unimin==8)
            {
                llPlaySound("8",1.0);
            }
            else if (unimin==9)
            {
                llPlaySound("9",1.0);
            }
           
        } 
        else
                 if (Minute>=31 && Minute<40)
         {
             if (unimin==1)
            {
                llPlaySound("1",1.0);
            }
            else if (unimin==2)
            {
                llPlaySound("2",1.0);
            }
            else if (unimin==3)
            {
                llPlaySound("3",1.0);
            }
            else if (unimin==4)
            {
                llPlaySound("4",1.0);
            }
            else if (unimin==5)
            {
                llPlaySound("5",1.0);
            }
            else if (unimin==6)
            {
                llPlaySound("6",1.0);
            }
            else if (unimin==7)
            {
                llPlaySound("7",1.0);
            }
            else if (unimin==8)
            {
                llPlaySound("8",1.0);
            }
            else if (unimin==9)
            {
                llPlaySound("9",1.0);
            }
           
        } 
        else
                 if (Minute>=41 && Minute<50)
         {
             if (unimin==1)
            {
                llPlaySound("1",1.0);
            }
            else if (unimin==2)
            {
                llPlaySound("2",1.0);
            }
            else if (unimin==3)
            {
                llPlaySound("3",1.0);
            }
            else if (unimin==4)
            {
                llPlaySound("4",1.0);
            }
            else if (unimin==5)
            {
                llPlaySound("5",1.0);
            }
            else if (unimin==6)
            {
                llPlaySound("6",1.0);
            }
            else if (unimin==7)
            {
                llPlaySound("7",1.0);
            }
            else if (unimin==8)
            {
                llPlaySound("8",1.0);
            }
            else if (unimin==9)
            {
                llPlaySound("9",1.0);
            }
           
        } 
        else
                 if (Minute>50)
         {
             if (unimin==1)
            {
                llPlaySound("1",1.0);
            }
            else if (unimin==2)
            {
                llPlaySound("2",1.0);
            }
            else if (unimin==3)
            {
                llPlaySound("3",1.0);
            }
            else if (unimin==4)
            {
                llPlaySound("4",1.0);
            }
            else if (unimin==5)
            {
                llPlaySound("5",1.0);
            }
            else if (unimin==6)
            {
                llPlaySound("6",1.0);
            }
            else if (unimin==7)
            {
                llPlaySound("7",1.0);
            }
            else if (unimin==8)
            {
                llPlaySound("8",1.0);
            }
            else if (unimin==9)
            {
                llPlaySound("9",1.0);
            }
           
        } 
        else
                 if (Minute<10)
         {
             if (unimin==1)
            {
                llPlaySound("1",1.0);
            }
            else if (unimin==2)
            {
                llPlaySound("2",1.0);
            }
            else if (unimin==3)
            {
                llPlaySound("3",1.0);
            }
            else if (unimin==4)
            {
                llPlaySound("4",1.0);
            }
            else if (unimin==5)
            {
                llPlaySound("5",1.0);
            }
            else if (unimin==6)
            {
                llPlaySound("6",1.0);
            }
            else if (unimin==7)
            {
                llPlaySound("7",1.0);
            }
            else if (unimin==8)
            {
                llPlaySound("8",1.0);
            }
            else if (unimin==9)
            {
                llPlaySound("9",1.0);
            }
           
        }
        

Link to comment
Share on other sites

I'm feeling a bit foggy today, but maybe something like this…

float volume = 1.0;

list units = ["exactly", "1", "2", "...all the rest...", "18", "19"]; //the sounds for 0 - 19
list tens = ["20", "30", "40", "50"]; //the sounds for 20 - 50

integer GetMinuteSomehow ()
{
    return (integer) llFrand (60.0);
}

default
{
    state_entry ()
    {
        llSetSoundQueueing (TRUE);
    }

    touch_start (integer count)
    {
        integer minute = GetMinuteSomehow ();
        if (minute < 20) llPlaySound (llList2String (units, minute), volume);
        else
        {
            llPlaySound (llList2String (tens, minute / 10 - 2), volume);
            //-2 because the list starts at 20 rather than 0
            llPlaySound (llList2String (units, minute % 10), volume);
        }
    }
}

 

Link to comment
Share on other sites

Notice the very important modulo operator in KT's example:

1 hour ago, KT Kingsley said:

llPlaySound (llList2String (units, minute % 10), volume);

That simple operator can often save you a lot of fiddly if tests.  Modulo means basically "this is how much is left over if I divide X by Y and the answer doesn't come out to be ZERO."  So 12%10 = 2 and 134%50 = 34.  If you are interested in dealing with the "leftover" part, as you are, modulo makes it easy:

integer iMinutes = 252;

integer iHours = iMinutes/60;    // Answer: 4

integer iMinutesLeft = iMinutes%60;   // Answer: 12 

Edited by Rolig Loon
  • Like 1
Link to comment
Share on other sites

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