Jump to content
Sunbleached

School Bell twice a day SLT script

Recommended Posts

Hello! I'm trying to create a script to turn on/off the option to automatically play the school bell twice a day at 1.30pm and 3pm. With the turn on/off everything is clear, but how to configure the rest is not clear. I would appreciate any help!

Share this post


Link to post
Share on other sites

This is a logic question, so think it through...

Timer: What time is it? 

     -- is it 1:30 p.m. or 3:00 p.m.?

    -- Is the bell control switched on?

    Yes?  >> ring the bell

    No? >> don't ring the bell

    -- Is it 10 seconds after 1:30 p.m. or 3:00 p.m.?

    Yes?  >> stop ringing the bell

Touch toggle switch: Would you like to turn the bell control on?

   Yes? >> Turn it on

   No? >> Turn it off

  • Thanks 1

Share this post


Link to post
Share on other sites
1 hour ago, Rolig Loon said:

This is a logic question, so think it through...

Timer: What time is it? 

     -- is it 1:30 p.m. or 3:00 p.m.?

    -- Is the bell control switched on?

    Yes?  >> ring the bell

    No? >> don't ring the bell

    -- Is it 10 seconds after 1:30 p.m. or 3:00 p.m.?

    Yes?  >> stop ringing the bell

Touch toggle switch: Would you like to turn the bell control on?

   Yes? >> Turn it on

   No? >> Turn it off

Hello! thanks very much for the answer!

I've never dealt with SL time before. How can I check what time it is?

Share this post


Link to post
Share on other sites

Depending on which "time" you want, 

llGetGMTclock

llGetTime

llGetUnixTime

llGetTimeOfDay

llGetWallclock

llGetTimestamp

Whatever fits your situation best.

 

  • Thanks 1

Share this post


Link to post
Share on other sites
Posted (edited)
4 hours ago, Rolig Loon said:

llGetWallclock

Hello! decided to use llGetWallclock. This is what I got, but for some reason it does not work yet. Please help to figure out what is wrong?

//* script_starts_here
//
integer Flag;
integer run;
string BELL = "a451066e-6583-b13d-26b8-28b116e8dad8";
default
{
  state_entry()
  {
    Flag = -1;
    llSetTimerEvent(0.1);
  }
  touch_start(integer total_number)
  {
    if (llDetectedKey(0) == llGetOwner())
    {
      if (run)
      {
        run = FALSE;
        llSetTimerEvent(0.0);
      }
      else
      {
        run = TRUE;
        llSetTimerEvent(60.0);
      }
    }
  }
  timer()
  {
    float time = llGetWallclock();
    if (Flag == -1)
    {
      //            llSetTimerEvent(60.0);
    }
    if (time = 8090)
    {
      if (Flag)
      {
        Flag = 0;
        llTriggerSound(BELL, 1.0);
      }
    }
    else if (time = 8100)
    {
      if (Flag != 1)
      {
        Flag = 1;
        llTriggerSound(BELL, 1.0);      
      }
    }
    else if (Flag != 2)
    {
      llSetText("", < 1, 1, 1 > , 1.0);
      Flag = 2;
    }
  }
}
//* script_ends_here

I used this wiki script as an example.

Edited by Sunbleached

Share this post


Link to post
Share on other sites
Posted (edited)

A couple of issues:

First, the simple one that's probably causing most of your trouble is that you have used "=" instead of "==" in the if tests in your timer event.  Second, 8090 seconds after midnight is a little before 2:30 a.m. -- not the time you were  hoping for.  Third, you're triggering the bell sound a second time only 10 seconds after the first triggering event, not an hour and a half later.

Aside from that -- and purely from an aesthetic perspective -- you can simplify your touch_start event by writing

touch_start(integer total_number)
  {
    if (llDetectedKey(0) == llGetOwner())
    {
      llSetTimerEvent(60.0 * (run = !run));
    }
  }

EDIT:  Incidentally, I'm sure it has not escaped you that a day in SL is only 4 hours long, so 1:30 p.m. and 3:00 p.m. in RL won't translate into meaningful times in world unless you rethink your definition of time.

Edited by Rolig Loon
  • Thanks 1

Share this post


Link to post
Share on other sites
Posted (edited)
13 hours ago, Rolig Loon said:

A couple of issues:

First, the simple one that's probably causing most of your trouble is that you have used "=" instead of "==" in the if tests in your timer event.  Second, 8090 seconds after midnight is a little before 2:30 a.m. -- not the time you were  hoping for.  Third, you're triggering the bell sound a second time only 10 seconds after the first triggering event, not an hour and a half later.

Aside from that -- and purely from an aesthetic perspective -- you can simplify your touch_start event by writing


touch_start(integer total_number)
  {
    if (llDetectedKey(0) == llGetOwner())
    {
      llSetTimerEvent(60.0 * (run = !run));
    }
  }

EDIT:  Incidentally, I'm sure it has not escaped you that a day in SL is only 4 hours long, so 1:30 p.m. and 3:00 p.m. in RL won't translate into meaningful times in world unless you rethink your definition of time.

Thank you very much!

Here's what I got.

However, the timer had to be changed from 60 to 1. It looked like it checked time every 60 seconds and obviously skipped the right time. And it is still not clear what the second timer 

llSetTimerEvent(0.1);

is for.

//* script_starts_here
//
integer Flag;
integer run;
string BELL = "a451066e-6583-b13d-26b8-28b116e8dad8";
default
{
  state_entry()
  {
    Flag = -1;
    llSetTimerEvent(0.1);
  }
  touch_start(integer total_number)
  {
    if (llDetectedKey(0) == llGetOwner())
    {
      if (run)
      {
        run = FALSE;
        llSetTimerEvent(0.0);
        llSay(0, "Bell is off!");
      }
      else
      {
        run = TRUE;
        llSetTimerEvent(1.0); // <<<<<<<  Timer changed from 60 to 1
        llSay(0, "Bell is on!");
      }
    }
  }
    
  
  timer()
  {
    float time = llGetWallclock();
    if (Flag == -1)
    {
      //            llSetTimerEvent(60.0);
    }
    if (time == 48600)
    {
      if (Flag)
      {
        Flag = 0;
        llTriggerSound(BELL, 1.0);
      }
    }
    else if (time == 54000)
    {
      if (Flag != 1)
      {
        Flag = 1;
        llTriggerSound(BELL, 1.0);
      }
    }
    else if (Flag != 2)
    {
      llSetText("", < 1, 1, 1 > , 1.0);
      Flag = 2;
    }
  }
}
//* script_ends_here

 

Edited by Sunbleached

Share this post


Link to post
Share on other sites

Yes, 60 seconds was way too long an interval, for exactly the reason you discovered.  The challenge is that it's almost impossible to hit the target times of 48600 and 54000 precisely.  When the timer is set to trigger only once a minute, the chance of triggering it at exactly the target second is really low.  Triggering thee timer every single second increases your chances of hitting the target precisely. Unless it's truly important to hit 48600 and 5400 right on the nose, though, that's still  overkill.  In this case, do you really care whether the bell rings  a few seconds early or late?

Instead of asking "Is the time 48600?", it's wiser to ask, "Is the time about 48600?"  Give the timer some wiggle room and don't make the script work quite so hard

if ( time > 48595 && time < 48605)  // ring the bell.

Then you can afford to run your timer with a ten second interval, since you know that it will have to trigger somewhere between 48595 and 48605.

Now, about that very first timer ....  That's a jump start.  When you reset the script, the timer event will trigger almost instantly, 0.1 seconds later.  After that, you've told it to trigger once a second.  You didn't really need to give it that first kick, but doing it meant, "Don't wait!  Start right NOW!"  It was an important jump start when you were running the timer once a minute.  Now that you've sped the timer up, it's not as important.

  • Thanks 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...