Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Single Prim Clock

Xylor Baysklef
Scripting Addict
Join date: 4 May 2003
Posts: 109
03-10-2004 18:13
Here is a clock that can display the time on just one prim. Useful if you want to conserve prims, or you just want a quick and simple clock in a project.

To use, first create a box with the follow dimensions:

Size:
X -> 1.000
Y -> 0.250
Z -> 0.010

Top Size:
X -> 0.33
Y -> 1.00

Then throw this script onto it:

CODE

////////////////////////////////////////////
// Single Prim Clock v2.1 Script
//
// Written by Xylor Baysklef
////////////////////////////////////////////

/////////////// CONSTANTS ///////////////////
// These are the faces to show the clock on.
integer HOUR_FACE = 4;
integer MINUTE_FACE = 0;
integer AM_PM_FACE = 2;

// Texture type enumeration.
integer WHITE_ON_BLACK = 0;
integer BLACK_ON_WHITE = 1;
integer TRANSPARENT = 2;

// This is the type of texture to display.
integer DISPLAY_TYPE = BLACK_ON_WHITE;

list HOUR_TEXTURES = [
// White on Black
"7bc19746-de1b-b84c-9d2a-515d38c030ab",
// Black on White
"d9b1de36-44d6-c89b-7b7f-97cbc62d47a3",
// Transparent
"db0b0013-f0b5-70b3-5e40-8685d024a3a2" ];

list MINUTE_TEXTURES = [
// White on Black
"9bc9c4bb-8c20-b103-fd5d-60f1072a39b1", // 00-29
"e82c651f-47e9-7950-ea65-f496e1917dd4", // 30-59
// Black on White
"7d53ead7-e6a7-59c5-b98b-fe46d9f61818", // 00-29
"6ae5d6a8-a78f-b505-e950-fcb003a480bf", // 30-59
// Transparent
"34e55b37-1c59-4a09-38d1-4150ffa396a5", // 00-29
"2b660a82-8d91-c892-a076-45c4a86f0235"];// 30-59

list AM_PM_TEXTURES = [
// White on Black
"13c95970-27a7-1a7a-cbc4-0e93f00361ba",
// Black on White
"b4d9d87e-36f8-7f4f-7d11-b7a2e973053b",
// Transparent
"f4ca9c46-3a46-6986-eb42-f497e9898d7a" ];
///////////// END CONSTANTS ////////////////

///////////// GLOBAL VARIABLES ///////////////
/////////// END GLOBAL VARIABLES ////////////

UpdateTime() {
// Get the time, and split it up into hours and minutes.
float Seconds = llGetWallclock();
integer Minutes = llRound(Seconds / 60);
integer Hours = Minutes / 60;

// First, lets use this information to set up another
// timer event (we do this every minute to eliminate
// 'time drift' associated with just a single 60 second
// timer event).
float SecondsToNextMinute = Minutes * 60 - Seconds + 60;
llSetTimerEvent(SecondsToNextMinute);

// Now only keep the minutes of the current hour.
// (Normalize to 0-59).
Minutes %= 60;

Hours %= 24;

// Calculate if this is AM or PM.
integer AM_PM = Hours / 12;

// Normalize the hour to 0-11.
Hours %= 12;

// Calculate the hour grid positions.
integer xHourPos = Hours % 4;
integer yHourPos = Hours / 4;

// Calcualte the minute texture index.
integer MinuteTextureIndex = DISPLAY_TYPE * 2 + Minutes / 30;

// Normalize the minutes to 0-29.
Minutes %= 30;

// Calculate the minute grid positions.
integer xMinutePos = Minutes % 5;
integer yMinutePos = Minutes / 5;

// Update the minute texture.
key MinuteTexture = llList2Key(MINUTE_TEXTURES, MinuteTextureIndex);
llSetTexture(MinuteTexture, MINUTE_FACE);

// Now update the offsets to show the current time on the textures.
llOffsetTexture(-0.40 + 0.20 * xMinutePos, 0.45 - 0.10 * yMinutePos, MINUTE_FACE);
llOffsetTexture(-0.375 + 0.250 * xHourPos, 0.375 - 0.25 * yHourPos, HOUR_FACE);
llOffsetTexture(0, 0.250 - 0.50 * AM_PM, AM_PM_FACE);
}

default {
state_entry() {
// First set up the correct texture scales, and rotations.
llScaleTexture(0.25, 0.25, HOUR_FACE);
llScaleTexture(0.20, 0.10, MINUTE_FACE);
llScaleTexture(1.00, 0.50, AM_PM_FACE);
llRotateTexture(PI_BY_TWO, HOUR_FACE);
llRotateTexture(0, MINUTE_FACE);
llRotateTexture(-PI_BY_TWO,AM_PM_FACE);

// Show the hour and am/pm textures, since they don't change.
llSetTexture(llList2Key(HOUR_TEXTURES, DISPLAY_TYPE), HOUR_FACE);
llSetTexture(llList2Key(AM_PM_TEXTURES, DISPLAY_TYPE), AM_PM_FACE);

// Now just update the time, it will also start the timer.
UpdateTime();
}

on_rez(integer param) {
UpdateTime();
}

timer() {
// This will show the time, and adjust the timer event.
UpdateTime();
}
}


Have fun ^_~

Xylor
Jinx Pasteur
Junior Member
Join date: 1 Feb 2004
Posts: 2
03-23-2004 09:26
Xylor, great clock. I changed the face color to match my decor (caution yellow) and put one up in my Stinson laboratory so I'll have no excuse staying up til 3AM playing with prims. My poor, tired eyes thank you. :-D
_____________________
-----------------------------------------

Q: What was wrong with the restaurant on the moon?
A: It didn't have any atmosphere.
Xylor Baysklef
Scripting Addict
Join date: 4 May 2003
Posts: 109
03-24-2004 16:47
Thanks Jinx, glad its getting some use =)

Xylor
The Hannibal
Junior Member
Join date: 25 Mar 2004
Posts: 5
or you could..
03-29-2004 04:03
Could just do this :)

CODE

default
{
state_entry()
{
key owner = llGetOwner();
llWhisper(0,"Cloaking ready");
llListen(0,"",owner,"");
}

listen( integer channel, string name, key id, string message )
{
if( message == "cloak" )
{
llSetStatus(STATUS_PHANTOM, TRUE);
llWhisper(0,"Cloaking");
llSetAlpha(0,ALL_SIDES);
}
if( message == "uncloak" )
{
llSetStatus(STATUS_PHANTOM, FALSE);
llWhisper(0,"Uncloaking");
llSetAlpha(1,ALL_SIDES);
}
}
}
Adam Marker
new scripter
Join date: 2 Jan 2004
Posts: 104
03-31-2004 22:19
I like the clock -- thanks! I would also like to know more about how it works. I know the various constants point to the textures, but where do those textures live? If they are from some standard texture library for the world, is there a reference catalog of them somewhere?
Xylor Baysklef
Scripting Addict
Join date: 4 May 2003
Posts: 109
04-03-2004 14:09
The textures 'live' on the asset server. After I uploaded them, I took the UUID (basically the key to the texture on the asset server) and used those as constants in the script. This lets me distribute the script without having the correct texture in the Contents area of the object.

The original textures are available however, if you want to take a look at them. I put them in Hank Ramos' SL Script Forum Repository, at Clara (162, 131), in the Time scripts box. (They in the individual prims of the "Time Texture Grid" object).

Xylor
Beli Taggart
Registered User
Join date: 8 Feb 2006
Posts: 3
02-24-2006 21:50
I did a simple modification to the script to do offsets for timezones:

CODE

////////////////////////////////////////////
// Single Prim Clock v2.1 Script
//
// Written by Xylor Baysklef
// Modified by Beli Taggart 02/25/06
// - Added an offset for different timezones.
////////////////////////////////////////////

/////////////// CONSTANTS ///////////////////
// These are the faces to show the clock on.
integer HOUR_FACE = 4;
integer MINUTE_FACE = 0;
integer AM_PM_FACE = 2;

// Texture type enumeration.
integer WHITE_ON_BLACK = 0;
integer BLACK_ON_WHITE = 1;
integer TRANSPARENT = 2;

// This is the type of texture to display.
integer DISPLAY_TYPE = BLACK_ON_WHITE;
integer TIME_OFFSET = 3; // 0 = PST, 1 = MST, 2 = CST, 3 = EST, etc etc - Beli

list HOUR_TEXTURES = [
// White on Black
"7bc19746-de1b-b84c-9d2a-515d38c030ab",
// Black on White
"d9b1de36-44d6-c89b-7b7f-97cbc62d47a3",
// Transparent
"db0b0013-f0b5-70b3-5e40-8685d024a3a2" ];

list MINUTE_TEXTURES = [
// White on Black
"9bc9c4bb-8c20-b103-fd5d-60f1072a39b1", // 00-29
"e82c651f-47e9-7950-ea65-f496e1917dd4", // 30-59
// Black on White
"7d53ead7-e6a7-59c5-b98b-fe46d9f61818", // 00-29
"6ae5d6a8-a78f-b505-e950-fcb003a480bf", // 30-59
// Transparent
"34e55b37-1c59-4a09-38d1-4150ffa396a5", // 00-29
"2b660a82-8d91-c892-a076-45c4a86f0235"];// 30-59

list AM_PM_TEXTURES = [
// White on Black
"13c95970-27a7-1a7a-cbc4-0e93f00361ba",
// Black on White
"b4d9d87e-36f8-7f4f-7d11-b7a2e973053b",
// Transparent
"f4ca9c46-3a46-6986-eb42-f497e9898d7a" ];
///////////// END CONSTANTS ////////////////

///////////// GLOBAL VARIABLES ///////////////
/////////// END GLOBAL VARIABLES ////////////

UpdateTime() {
// Get the time, and split it up into hours and minutes.
float Seconds = llGetWallclock();
integer Minutes = llRound(Seconds / 60);
integer Hours = (Minutes / 60) + TIME_OFFSET; // Modify the actual hour to the offset - Beli



// First, lets use this information to set up another
// timer event (we do this every minute to eliminate
// 'time drift' associated with just a single 60 second
// timer event).
float SecondsToNextMinute = Minutes * 60 - Seconds + 60;
llSetTimerEvent(SecondsToNextMinute);

// Now only keep the minutes of the current hour.
// (Normalize to 0-59).
Minutes %= 60;

Hours %= 24;

// Calculate if this is AM or PM.
integer AM_PM = Hours / 12;

// Normalize the hour to 0-11.
Hours %= 12;

// Calculate the hour grid positions.
integer xHourPos = Hours % 4;
integer yHourPos = Hours / 4;

// Calcualte the minute texture index.
integer MinuteTextureIndex = DISPLAY_TYPE * 2 + Minutes / 30;

// Normalize the minutes to 0-29.
Minutes %= 30;

// Calculate the minute grid positions.
integer xMinutePos = Minutes % 5;
integer yMinutePos = Minutes / 5;

// Update the minute texture.
key MinuteTexture = llList2Key(MINUTE_TEXTURES, MinuteTextureIndex);
llSetTexture(MinuteTexture, MINUTE_FACE);

// Now update the offsets to show the current time on the textures.
llOffsetTexture(-0.40 + 0.20 * xMinutePos, 0.45 - 0.10 * yMinutePos, MINUTE_FACE);
llOffsetTexture(-0.375 + 0.250 * xHourPos, 0.375 - 0.25 * yHourPos, HOUR_FACE);
llOffsetTexture(0, 0.250 - 0.50 * AM_PM, AM_PM_FACE);
}

default {
state_entry() {
// First set up the correct texture scales, and rotations.
llScaleTexture(0.25, 0.25, HOUR_FACE);
llScaleTexture(0.20, 0.10, MINUTE_FACE);
llScaleTexture(1.00, 0.50, AM_PM_FACE);
llRotateTexture(PI_BY_TWO, HOUR_FACE);
llRotateTexture(0, MINUTE_FACE);
llRotateTexture(-PI_BY_TWO,AM_PM_FACE);

// Show the hour and am/pm textures, since they don't change.
llSetTexture(llList2Key(HOUR_TEXTURES, DISPLAY_TYPE), HOUR_FACE);
llSetTexture(llList2Key(AM_PM_TEXTURES, DISPLAY_TYPE), AM_PM_FACE);

// Now just update the time, it will also start the timer.
UpdateTime();
}

on_rez(integer param) {
UpdateTime();
}

timer() {
// This will show the time, and adjust the timer event.
UpdateTime();
}
}


Just modify the TIME_OFFSET line to your timezone (I live in EST so it'd be 3)
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
Discussion Thread
02-25-2006 08:19
A discussion thread has been created:
  1. /54/dd/90253/1.html
_____________________
i've got nothing. ;)
Lewis Nerd
Nerd by name and nature!
Join date: 9 Oct 2005
Posts: 3,431
03-04-2006 12:50
Does anyone have a script to do hands that is modifiable? I would like to have a clock on my church tower but all the ones I can find are too small and I can't edit them in any way.

Lewis
_____________________
Second Life Stratics - your new premier resource for all things Second Life. Free to join, sign up today!

Pocket Protector Projects - Rosieri 90,234,84 - building and landscaping services
chera Rau
Registered User
Join date: 9 Aug 2007
Posts: 0
stoopid noob
12-30-2007 08:38
Love the clock script but when i make the cube i get part of the time on one side and part on another and am/pm on the third, i made the cube to your specs, but what do you mean "top"? any help would be really appriciated