Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Discussion: Notecard Settings Reader

Konigmann Lippmann
Registered User
Join date: 15 Jun 2004
Posts: 40
01-20-2005 09:41
I've written a number of things that have a notecard in them to customize various settings. I wanted to release the code that reads the notecard for public use.

CODE
// SampleSettingsReader.lsl
// Written by Konigmann Lippmann
// Thanks to Apotheus Silverman for his MultiItem Vendor...
// It seems like everything I write is based on it in one way or another.


// Default values
integer iShowHoverText = TRUE;
string sHoverTextValue = "No Settings?";
vector vColor = <1.0,0.0,0.0>;


// Globals
integer iNotecardIndex;
integer iNotecardCount;
integer iNoteCardLine;
key kCurrentDataRequest;
string sSettingsNotecard;


integer StringLeftICompare( string sLeftMatch, string sLongString )
{
integer iLength;

iLength = llStringLength( sLeftMatch ) - 1;
if( llToLower(llGetSubString( sLongString, 0, iLength ) ) == llToLower(sLeftMatch) )
return( TRUE );
return( FALSE );
}


string GetValue( string sString )
{
integer iStart;
string sValue = "";
string sbValue = "";

iStart = llSubStringIndex( sString, "=" ) + 1;
if( iStart )
{
sValue = llGetSubString( sString, iStart, llStringLength(sString) - 1 );
if( sValue )
{
sbValue = llToLower( sValue );
if( sbValue == "true" )
sValue = "1";
if( sbValue == "false" )
sValue = "0";
return( sValue );
}
}
return( NULL_KEY );
}


default
{
on_rez( integer param )
{
llResetScript();
}

state_entry()
{
integer iii;

llSetText( "Initializing...", <0,0.5,0>, 1.0 );

iNotecardCount = llGetInventoryNumber( INVENTORY_NOTECARD );
iNotecardIndex = 0;
if( iNotecardCount > iNotecardIndex )
{
sSettingsNotecard = llGetInventoryName( INVENTORY_NOTECARD, iNotecardIndex );
iNoteCardLine = 0;
kCurrentDataRequest = llGetNotecardLine( sSettingsNotecard, iNoteCardLine );
iNotecardIndex++;
}
if( iNotecardIndex == 0 )
{
llWhisper( 0, "Using Default Values." );
state run_object;
}
}

dataserver( key kQuery, string sData )
{
list lSetting;

kCurrentDataRequest = "";
if( sData != EOF )
{


// you can string several of these tests for whatever values you may want.

if( StringLeftICompare( "ShowHoverText=", sData ) )
iShowHoverText = (integer)GetValue( sData );

else if( StringLeftICompare( "HoverTextValue=", sData ) )
sHoverTextValue = (string)GetValue( sData );

else if( StringLeftICompare( "Color=", sData ) )
vColor = (vector)GetValue( sData );


kCurrentDataRequest = llGetNotecardLine( sSettingsNotecard, ++iNoteCardLine );
}
else
{
iNotecardIndex++;
if( iNotecardIndex < llGetInventoryNumber( INVENTORY_NOTECARD ) )
{
sSettingsNotecard = llGetInventoryName( INVENTORY_NOTECARD, iNotecardIndex );

iNoteCardLine = 0;
llGetNotecardLine( sSettingsNotecard, iNoteCardLine );
}
else
{
state run_object;
}
}
}
}


state run_object
{
state_entry()
{
if( TRUE == iShowHoverText )
llSetText( sHoverTextValue, vColor, 1.0 );
else
llSetText( "", <0,0,0>, 0.0 );
}
}



Here is a sample notecard

CODE
ShowHoverText=True
HoverTextValue=It has worked!
Color=<1.0,1.0,1.0>
Little Gray
Registered User
Join date: 16 Oct 2006
Posts: 48
Discussion: Notecard Settings Reader
03-24-2007 18:18
This is an extremely handy script ... it's great for where you want people to be able to set variables but not modiy a script, and, where you need to have multiple copies of a script running in differen to objects each with different settings. It seemed to work fine, except, I'm now having problems using it in a script that requires permissions (for the object to give money).

It seems no matter where I put the llRequestPermissions statement, the script always wants to check for permissions immediately upon rez or reset. I.E. I can put the permissions request in a non-default state that requires a user to interact with the script before entering, or, put the permissions request in a condititional statement that is not me when the script initially loads. The problem occurs where I want to load information pertaining to what permissions are granted from the notecard.

Am I missing something, or, is there no way to delay request permissions until after the settings have loaded from a notecard? Are permissions requests always performed immediately?
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
Original Thread
04-09-2007 05:05
/15/0a/33517/1.html
_____________________
i've got nothing. ;)
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
04-09-2007 06:22
From: Little Gray
This is an extremely handy script ... it's great for where you want people to be able to set variables but not modiy a script, and, where you need to have multiple copies of a script running in differen to objects each with different settings. It seemed to work fine, except, I'm now having problems using it in a script that requires permissions (for the object to give money).

It seems no matter where I put the llRequestPermissions statement, the script always wants to check for permissions immediately upon rez or reset. I.E. I can put the permissions request in a non-default state that requires a user to interact with the script before entering, or, put the permissions request in a condititional statement that is not me when the script initially loads. The problem occurs where I want to load information pertaining to what permissions are granted from the notecard.

Am I missing something, or, is there no way to delay request permissions until after the settings have loaded from a notecard? Are permissions requests always performed immediately?


It depends what you are doing, i.e. when do you request the permissions?

If you are requesting permissions as you read the notecard then of course that will happen. If you just keep track of what permissions you want and then request them only when you have finished reading the notecard(s)
Raedel Flatley
Registered User
Join date: 16 Feb 2008
Posts: 4
Problem getting a LIST to work
12-13-2008 22:48
First of all,

Thank you VERY much for this script I love it. I does wonders when you need to configure a script via a notecard.

However I'm having one small problem with it. When I try to place a list in the configuration notecard, it does not work at all. What I want to do is add a notecard line containing a list of numbers to be used in a llSetPayPrice event. I want to enter the 4 payment options in the list and then call the list via set pay price.. something like this:

llSetPayPrice(DEFAULT, SUGGESTED);

where DEFAULT is a variable from the notecard setting the default pay price (This works fine) and SUGGESTED is the list of amounts for the fast pay buttons.

it seems that when I try to bring the amounts over from the notecard, the values somehow never make it into the list.

I've tried
else if( StringLeftICompare( "SUGGESTED =", sData ) )
SUGGESTED = (list)GetValue( sData );

and
else if( StringLeftICompare( "SUGGESTED =", sData ) )
SUGGESTED = llParseString2List(GetValue( sData ), [","],[]);

both with no luck.

Could someone point me in the right direction? I've checked the wiki and was thinking of using csv2list.. not sure if that would work or not Any help would be greatly appreciated.
Yingzi Xue
Registered User
Join date: 11 Jun 2008
Posts: 144
12-14-2008 04:45
I did see one discrepancy... you have a space between SUGGESTED and the = sign in your test string. Is your notecard data the same? If not then it won't work because it's looking for SUGGESTED = instead of SUGGESTED= in your test code. This may be what's keeping the line from being recognized.

In this example I used your second test code line in your post (removing the space) and set up four amount integers: amount1, amount2, amount3 and amount4. I check to see if the values are greater than zero. If not send a message to the owner. I then added a changed event so that if you save the notecard the script resets without having to do it manually. Another thing... since the amounts 1 thru 4 are going to be used by other parts of the script I made them global. I made the suggested list local because after the data is pulled from the list it's no longer used.

Here's what I've got...

From: someone

// Written by Konigmann Lippmann
// Thanks to Apotheus Silverman for his MultiItem Vendor...
// It seems like everything I write is based on it in one way or another.


// Default values
integer iShowHoverText = TRUE;
string sHoverTextValue = "No Settings?";
vector vColor = <1.0,0.0,0.0>;


// Globals
integer iNotecardIndex;
integer iNotecardCount;
integer iNoteCardLine;
key kCurrentDataRequest;
string sSettingsNotecard;
integer amount1;
integer amount2;
integer amount3;
integer amount4;

integer StringLeftICompare( string sLeftMatch, string sLongString )
{
integer iLength;

iLength = llStringLength( sLeftMatch ) - 1;
if( llToLower(llGetSubString( sLongString, 0, iLength ) ) == llToLower(sLeftMatch) )
return( TRUE );
return( FALSE );
}


string GetValue( string sString )
{
integer iStart;
string sValue = "";
string sbValue = "";

iStart = llSubStringIndex( sString, "=" ) + 1;
if( iStart )
{
sValue = llGetSubString( sString, iStart, llStringLength(sString) - 1 );
if( sValue )
{
sbValue = llToLower( sValue );
if( sbValue == "true" )
sValue = "1";
if( sbValue == "false" )
sValue = "0";
return( sValue );
}
}
return( NULL_KEY );
}


default
{
on_rez( integer param )
{
llResetScript();
}

state_entry()
{
integer iii;

llSetText( "Initializing...", <0,0.5,0>, 1.0 );

iNotecardCount = llGetInventoryNumber( INVENTORY_NOTECARD );
iNotecardIndex = 0;
if( iNotecardCount > iNotecardIndex )
{
sSettingsNotecard = llGetInventoryName( INVENTORY_NOTECARD, iNotecardIndex );
iNoteCardLine = 0;
kCurrentDataRequest = llGetNotecardLine( sSettingsNotecard, iNoteCardLine );
iNotecardIndex++;
}
if( iNotecardIndex == 0 )
{
llWhisper( 0, "Using Default Values." );
state run_object;
}
}

changed(integer change)
{
if ( change & CHANGED_INVENTORY )
{
llOwnerSay("Inventory has changed. Resetting script so new changes take effect.";);
llSleep(1);
llResetScript();
}
}

dataserver( key kQuery, string sData )
{
list lSetting;

kCurrentDataRequest = "";
if( sData != EOF )
{


// you can string several of these tests for whatever values you may want.

if( StringLeftICompare( "ShowHoverText=", sData ) )
iShowHoverText = (integer)GetValue( sData );

else if( StringLeftICompare( "HoverTextValue=", sData ) )
sHoverTextValue = (string)GetValue( sData );

else if( StringLeftICompare( "Color=", sData ) )
vColor = (vector)GetValue( sData );

else if( StringLeftICompare( "SUGGESTED=", sData ) )
{
list suggested;
suggested = llParseString2List(GetValue( sData ), [","],[]);

if (llList2Integer(suggested,0) > 0)
{amount1 = llList2Integer(suggested,0);}
else { llOwnerSay("NOTECARD ERROR: Zero or null value for suggested amount #1 in notecard.";);}

if (llList2Integer(suggested,1) > 0)
{amount2 = llList2Integer(suggested,1);}
else { llOwnerSay("NOTECARD ERROR: Zero or null value for suggested amount #2 in notecard.";);}

if (llList2Integer(suggested,2) > 0)
{amount3 = llList2Integer(suggested,2);}
else { llOwnerSay("NOTECARD ERROR: Zero or null value for suggested amount #3 in notecard.";);}

if (llList2Integer(suggested,3) > 0)
{amount4 = llList2Integer(suggested,3);}
else { llOwnerSay("NOTECARD ERROR: Zero or null value for suggested amount #4 in notecard.";);}
}

kCurrentDataRequest = llGetNotecardLine( sSettingsNotecard, ++iNoteCardLine );
}
else
{
iNotecardIndex++;
if( iNotecardIndex < llGetInventoryNumber( INVENTORY_NOTECARD ) )
{
sSettingsNotecard = llGetInventoryName( INVENTORY_NOTECARD, iNotecardIndex );

iNoteCardLine = 0;
llGetNotecardLine( sSettingsNotecard, iNoteCardLine );
}
else
{
state run_object;
}
}
}
}


state run_object
{
state_entry()
{
if( TRUE == iShowHoverText )
llSetText( sHoverTextValue, vColor, 1.0 );
else
llSetText( "", <0,0,0>, 0.0 );
}

changed(integer change)
{
if ( change & CHANGED_INVENTORY )
{
llOwnerSay("Inventory has changed. Resetting script so new changes take effect.";);
llSleep(1);
llResetScript();
}
}
}