Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Dialog Timer for Safe

Lylani Bellic
Evil Genius
Join date: 2 Jul 2008
Posts: 42
08-25-2008 16:42
So I'm trying to make a Prize Safe, a safe (duh) that has a settable timer. Upon expiration of the timer the safe opens and rezzes the prize giver. Simple enough in concept. My issue is I wanted more then just a set timer increment. Things like "Add 30 Min" are easy to do. My desire was something a little more customizable, but sadly it seems it is over my head. I've tried with what I know to make the script but as you can see I never got it working:

The way I figured it was something like a microwave timer, the timer starts at 00:00:00 and hitting 1 will make it 00:01:00, now a minute is added, but then hitting another number doesn't just add another minute; hitting one again would show 00:11:00. It would push the 1 into the next field making it 11 minutes in total. Like a microwave.

Don't know if I'm going about it wrong but chances are I am :p. Any help would be appreciated.

------------------------------------------------------------------------------------------------------

// Global Variables
// Integers
integer TimerActive = FALSE;
integer SettingPTimer = FALSE;
integer SettingCTimer = FALSE;
integer channel = -1;
integer PrizeTimer = 0;
integer ClaimTimer = 120;
integer TimeSelected;
// Vectors
// Floats
// Keys
key Key_Holder = NULL_KEY;
// Strings
string SActive = "Inactive";
string Duration = "00:00:00"; // This is not for function, I know that, it's just there to fill in what would otherwise be a blank field as I couldn't get the thing to work
string PDuration;
string CDuration;
// Lists
list Main = ["Safe Timer", "Claim Timer"];
list TimerMenu = ["Clear", "0", "Start", "1", "2", "3", "4", "5", "6", "7", "8", "9"];
list Observation = ["-", "-", "-"];


default
{
state_entry()
{
llListen(channel, "", "", "";);
}

touch_start(integer total_number)
{
if (llDetectedKey(0) == llGetOwner()) {
llDialog(llGetOwner(), "\t-- Timelock -- \n\nTimer Duration:" + PDuration + "\nClaim Duration: " + CDuration, Main, channel);
} else if (llDetectedKey(0) != llGetOwner()) {
llDialog(llDetectedKey(0), "\t-- Prize Safe -- \n\nTimer: " + SActive + "\nLocked by: " + llKey2Name(Key_Holder), Observation, channel);
}
}
listen (integer channel, string name, key id, string message)
{
////// Safe Timer //////////////////////////////////////////////////////////////////////////////////////////////////////////
if (message == "Safe Timer";) {
llDialog(llGetOwner(), "\t-- Prize Timer -- \n\nTimer: " + SActive + "\nTimer Duration: " + PDuration, TimerMenu, channel);
SettingPTimer = TRUE;
SettingCTimer = FALSE;
///// Claim Timer //////////////////////////////////////////////////////////////////////////////////////////////////////////
} else if (message == "Claim Timer";) {
llDialog(llGetOwner(), "\t-- Claim Timer -- \n\nTimer Duration: " + CDuration, TimerMenu, channel);
SettingPTimer = FALSE;
SettingCTimer = TRUE;
///// Clear Timers /////////////////////////////////////////////////////////////////////////////////////////////////////////
// Clear Prize Timer //
} else if (message == "Clear";) {
if (SettingPTimer == TRUE && SettingCTimer == FALSE) {
// Clear PDuration
PrizeTimer = 0;
llSetTimerEvent(PrizeTimer);
SActive = "Inactive";
llDialog(llGetOwner(), "\t-- Timelock -- \n\nTimer: " + SActive + "\nTimer Duration: " + PDuration, TimerMenu, channel);
// Clear Claim Timer //
} else if (SettingPTimer == FALSE && SettingCTimer == TRUE)
// Clear CDuration
ClaimTimer = 0;
llSetTimerEvent(ClaimTimer);
llDialog(llGetOwner(), "\t-- Timelock -- \n\nTimer: " + SActive + "\nTimer Duration: " + CDuration, TimerMenu, channel);
///// Start Timers /////////////////////////////////////////////////////////////////////////////////////////////////////////
// Start Prize Timer //
} else if (message == "Start";) {
if (SettingPTimer == TRUE && SettingCTimer == FALSE) {
SActive = "Active";
PrizeTimer = TimeSelected;
llSetTimerEvent(PrizeTimer);
Key_Holder = llGetOwner();
PDuration = Duration;
llDialog(llGetOwner(), "\t-- Timelock -- \n\nTimer Duration:" + PDuration + "\nClaim Duration: " + CDuration, Main, channel);
// Close Safe
SettingPTimer = FALSE;
SettingCTimer = FALSE;
// Set Claim Timer //
} else if (SettingPTimer == FALSE && SettingCTimer == TRUE)
ClaimTimer = TimeSelected;
CDuration = Duration;
llDialog(llGetOwner(), "\t-- Timelock -- \n\nTimer Duration:" + PDuration + "\nClaim Duration: " + CDuration, Main, channel);
SettingPTimer = FALSE;
SettingCTimer = FALSE;
///// Add to Timers ////////////////////////////////////////////////////////////////////////////////////////////////////////
} else if (message == "0";) {
// Add a 0
llDialog(llGetOwner(), "\t-- Timelock -- \n\nTimer Duration: " + Duration, TimerMenu, channel);
} else if (message == "1";) {
// Add a 1
llDialog(llGetOwner(), "\t-- Timelock -- \n\nTimer Duration: " + Duration, TimerMenu, channel);
} else if (message == "2";) {
// Add a 2
llDialog(llGetOwner(), "\t-- Timelock -- \n\nTimer Duration: " + Duration, TimerMenu, channel);
} else if (message == "3";) {
// Add a 3
llDialog(llGetOwner(), "\t-- Timelock -- \n\nTimer Duration: " + Duration, TimerMenu, channel);
} else if (message == "4";) {
// Add a 4
llDialog(llGetOwner(), "\t-- Timelock -- \n\nTimer Duration: " + Duration, TimerMenu, channel);
} else if (message == "5";) {
// Add a 5
llDialog(llGetOwner(), "\t-- Timelock -- \n\nTimer Duration: " + Duration, TimerMenu, channel);
} else if (message == "6";) {
// Add a 6
llDialog(llGetOwner(), "\t-- Timelock -- \n\nTimer Duration: " + Duration, TimerMenu, channel);
} else if (message == "7";) {
// Add a 7
llDialog(llGetOwner(), "\t-- Timelock -- \n\nTimer Duration: " + Duration, TimerMenu, channel);
} else if (message == "8";) {
// Add a 8
llDialog(llGetOwner(), "\t-- Timelock -- \n\nTimer Duration: " + Duration, TimerMenu, channel);
} else if (message == "9";) {
// Add a 9
llDialog(llGetOwner(), "\t-- Timelock -- \n\nTimer Duration: " + Duration, TimerMenu, channel);
}
}
timer ()
{
if (PrizeTimer = 0) {
SActive = "Inactive";
llSetTimerEvent(0);
// Open Safe
llRezObject("Prize", llGetPos() + <0.0,0.0,1.0>, <0.0,0.0,0.0>, <0.0,0.0,0.0,1.0>, 0); // Object "Prize" would hand out the prize to anyone who clicks on it, adding their name to a list which prevents them from getting more then one prize of that type.
} else if (ClaimTimer = 0) {
// Close Safe
}
}
object_rez (key id)
{
llSay(SecureChannel, "PRIZESTART";); // Run a script within the rezzed object "Prize" that uses llDie to remove itself from the Safe. This will allow the Safe to close and have no object inside it (physically) which prevents people from using their camera to look inside and click the prize after the (claim prize) timer is up.
llSetTimerEvent(ClaimTimer);
}
}
Kaluura Boa
Polygon Project
Join date: 27 Mar 2007
Posts: 194
08-26-2008 02:03
OK... I made your script work. I don't know if this is what you had in mind but it works. The dialogs work, the timers work in a way that makes sense to me.

(Sorry but I can't stand the way you used the braces so I re-formated everything.)

Tested and debugged in world...
----------------------------------------------------------------------------
// Global Variables
// Integers
integer Channel = -111222;
integer SecureChannel = -222111;
integer Handle;
integer PRIZE = 0;
integer CLAIM = 1;
integer WhichTimer;
integer CurrentTimer;
// Vectors
// Floats
float PrizeTimer = 0.0;
float ClaimTimer = 300.0; // 5 minutes
integer CurrentValue;
// Keys
key Key_Holder = NULL_KEY;
key Owner;
// Strings
string Status = "Inactive";
// Lists
list KeyPad = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"];
list Observation = ["-", "-", "-"];

string uuFormated(integer value)
{
return llGetSubString("0" + (string)(value / 100), -2, -1) + ":"
+ llGetSubString("0" + (string)(value % 100), -2, -1) + ":00";
}

integer uuConverted(float value)
{
integer hours = (integer)(value / 3600.0);
return hours * 100 + (integer)(value - ((float)hours * 3600.0)) / 60;
}

uuMainDialog()
{
Handle = llListen(Channel, "", Owner, "";);
llDialog(Owner, "\t-- Timelock -- \n\nTimer Duration: " + uuFormated(uuConverted(PrizeTimer))
+ "\nClaim Duration: " + uuFormated(uuConverted(ClaimTimer)),
["Safe Timer", "Claim Timer", "OK / Close"], Channel);
}

uuTimerDialog()
{
string text = "\t-- ";
if (WhichTimer == PRIZE)
{
text += "Prize Timer -- \n\nTimer: " + Status;
}
else if (WhichTimer = CLAIM)
{
text += "Claim Timer -- \n";
}
Handle = llListen(Channel, "", Owner, "";);
llDialog(Owner, text + "\nTimer Duration: " + uuFormated(CurrentValue),
["Start", "0", "Clear", "1", "2", "3", "4", "5", "6", "7", "8", "9"],
Channel);
}

default
{
state_entry()
{
Owner = llGetOwner();
}

touch_start(integer total_number)
{
if (llDetectedKey(0) == Owner)
{
uuMainDialog();
}
else
{
// No listen for this dialog
llDialog(llDetectedKey(0), "\t-- Prize Safe -- \n\nTimer: " + Status
+ "\nLocked by: " + llKey2Name(Key_Holder),
Observation, Channel);
}
}

listen (integer Channel, string name, key id, string message)
{
llListenRemove(Handle); // Will be restarted if needed.
////// Safe Timer //////////////////////////////////////////////////////////////////////////////////////////////////////////
if (message == "Safe Timer";)
{
WhichTimer = PRIZE;
CurrentValue = uuConverted(PrizeTimer);
uuTimerDialog();
}
///// Claim Timer //////////////////////////////////////////////////////////////////////////////////////////////////////////
else if (message == "Claim Timer";)
{
WhichTimer = CLAIM;
CurrentValue = uuConverted(ClaimTimer);
uuTimerDialog();
}
///// Clear Timers /////////////////////////////////////////////////////////////////////////////////////////////////////////
else if (message == "Clear";)
{
llSetTimerEvent(0.0); // Stop current timer
// Clear Prize Timer //
if (WhichTimer == PRIZE)
{
Status = "Inactive";
PrizeTimer = 0.0;
CurrentValue = 0;
uuTimerDialog();
}
// Clear Claim Timer //
else if (WhichTimer == CLAIM)
{
ClaimTimer = 0.0;
CurrentValue = 0;
uuTimerDialog();
}
}
///// Start Timers /////////////////////////////////////////////////////////////////////////////////////////////////////////
else if (message == "Start";)
{
// Start Prize Timer //
if (WhichTimer == PRIZE)
{
Key_Holder = Owner;
Status = "Active";
PrizeTimer = (float)(CurrentValue / 100) * 3600.0 + (float)(CurrentValue % 100) * 60.0;
CurrentTimer = PRIZE;
llSetTimerEvent(PrizeTimer);
uuMainDialog();
// Close Safe
}
// Set Claim Timer //
else if (WhichTimer == CLAIM)
{
ClaimTimer = (float)(CurrentValue / 100) * 3600.0 + (float)(CurrentValue % 100) * 60.0;
uuMainDialog();
}
}
///// Add to Timers ////////////////////////////////////////////////////////////////////////////////////////////////////////
else
{
integer digit = llListFindList(KeyPad, [message]);
if (digit != -1)
{
integer new_value = (CurrentValue * 10) + digit;
if ((new_value % 100) < 60) // 59 minutes
{
if ((new_value / 100) < 24) // 23 hours
{
CurrentValue = new_value;
}
}
uuTimerDialog();
}
}
}

timer ()
{
llSetTimerEvent(0.0); // Stop current timer;
if (CurrentTimer == PRIZE)
{
// Open Safe
Status = "Inactive";
CurrentTimer = CLAIM;
llRezObject("Prize", llGetPos() + <0.0, 0.0, 1.0>, ZERO_VECTOR, ZERO_ROTATION, SecureChannel);
}
else if (CurrentTimer == CLAIM)
{
// Close Safe
CurrentTimer = PRIZE;
llSetTimerEvent(PrizeTimer); // Should be appropriate...
}
}

object_rez (key id)
{
llSay(SecureChannel, "PRIZESTART";);
llSetTimerEvent(ClaimTimer);
}
}
----------------------------------------------------------------------------
Quote me and you'll retrieve the layout.

Hope it helps...
Lylani Bellic
Evil Genius
Join date: 2 Jul 2008
Posts: 42
08-26-2008 02:22
I knew it was over my head. Lot more complicated then I thought.

I found it a bit odd, but very nice, that it didn't take my input of 00:90:00 but insisted it be written like 01:30:00. It will certainly take some getting used to for me as I was thinking literary like a microwave (well at least mine) where I can punch in 01:00:00 or 00:60:00 for a minute.

As for the braces, to each their own :) I find its easier to read as I do it.

Thank you very much for the help, it is certainly a step in the right direction and one I don't think I couldn't have gotten on my own.