Dataserver Questions
|
|
Ryker Beck
Photographer & Designer
Join date: 23 Feb 2007
Posts: 57
|
05-26-2009 08:34
Hi all!  I'm trying to use a basic dataserver script that I saw on the LSL Wiki (I believe). While the script works great, there's only one thing I can't seem to make it do that I would like it to do (and seems practical to have it do -- at least for my purposes, for now). Basically, I have a main script and a config notecard. What I want to happen is that everytime the notecard is changed, the script reloads and updates the values in the script with the changed values in the notecard. Here is the main script: // 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; } } } } // This is where your actual code would go state run_object { state_entry() { if( TRUE == iShowHoverText ) llSetText( sHoverTextValue, vColor, 1.0 ); else llSetText( "", <0,0,0>, 0.0 ); } } And here is the config notecard: ShowHoverText=True HoverTextValue=put somethin here Color=<1.0,1.0,1.0> The script works great! But it will only reload the notecard if I save or reset the script, not the notecard. In order to get the notecard to be re-read, I need to reset the script (Right Click > Edit > Tools > Reset Scripts in Selection). I'd prefer to have it reload the notecard once the change is made and the notecard is saved. Any help would be appreciated! - R
|
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
05-26-2009 09:13
you need the changed event in both states 'default' and 'run_object' and you need to check for CHANGED_INVENTORY then call a reset.
_____________________
| | . "Cat-Like Typing Detected" | . This post may contain errors in logic, spelling, and | . grammar known to the SL populace to cause confusion | | - Please Use PHP tags when posting scripts/code, Thanks. | - Can't See PHP or URL Tags Correctly? Check Out This Link... | - 
|
|
Ryker Beck
Photographer & Designer
Join date: 23 Feb 2007
Posts: 57
|
05-26-2009 10:14
That worked beautifully.  Thank you!
|
|
Ryker Beck
Photographer & Designer
Join date: 23 Feb 2007
Posts: 57
|
05-26-2009 10:16
The working script: // 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>; string notecard_name = "configuration";
// 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(); }
changed(integer change) { // We want to reload channel notecard if it changed if (change & CHANGED_INVENTORY){ 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; } } } }
// This is where your actual code would go state run_object { changed(integer change) { // We want to reload channel notecard if it changed if (change & CHANGED_INVENTORY){ llResetScript(); } } state_entry() { if( TRUE == iShowHoverText ) llSetText( sHoverTextValue, vColor, 1.0 ); else llSetText( "", <0,0,0>, 0.0 ); } }
and notecard: ShowHoverText=True HoverTextValue=It has worked! Color=<1.0,1.0,1.0>
|
|
Meade Paravane
Hedgehog
Join date: 21 Nov 2006
Posts: 4,845
|
05-26-2009 10:32
If you're also planning on having anything else in the objects inventory, a good trick is to save off the notecards key (llGetInventoryKey) then check it again in the changed event. If the notecard was updated, the key will be different. If something else changed in the objects inventory, it will be the same and you don't need to reset or reload the config..
_____________________
Tired of shouting clubs and lucky chairs? Vote for llParcelSay!!! - Go here: http://jira.secondlife.com/browse/SVC-1224- If you see "if you were logged in.." on the left, click it and log in - Click the "Vote for it" link on the left
|
|
Ryker Beck
Photographer & Designer
Join date: 23 Feb 2007
Posts: 57
|
05-26-2009 12:07
Okay, good point!... I tried that out, but it still seems to reset the script both when the notecard has changed and when the inventory of the object has changed. Any thoughts? // 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>; string notecard_name = "configuration"; //config notecard name here
// Globals integer iNotecardIndex; integer iNotecardCount; integer iNoteCardLine; key kCurrentDataRequest; string sSettingsNotecard; key notecarduuid;
// if the id has changed, reset the script (function) init() { notecarduuid = llGetInventoryKey(notecard_name); llResetScript(); }
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(); }
changed(integer change) { // Check to see if notecard has updated/changed if (change & CHANGED_INVENTORY) if(notecarduuid != llGetInventoryKey(notecard_name)) init(); }
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; } } } }
// This is where your actual code would go state run_object { // First, check to see if inventory has changed... changed(integer change) { // Check to see if notecard has updated/changed if (change & CHANGED_INVENTORY) if(notecarduuid != llGetInventoryKey(notecard_name)) init(); } // Place script to-dos here state_entry() { if( TRUE == iShowHoverText ) llSetText( sHoverTextValue, vColor, 1.0 ); else llSetText( "", <0,0,0>, 0.0 ); } }
|
|
Meade Paravane
Hedgehog
Join date: 21 Nov 2006
Posts: 4,845
|
05-26-2009 12:26
A script reset tosses all your global variables.. init() { notecarduuid = llGetInventoryKey(notecard_name); llResetScript(); }
Try saving off the UUID in state_entry...
_____________________
Tired of shouting clubs and lucky chairs? Vote for llParcelSay!!! - Go here: http://jira.secondlife.com/browse/SVC-1224- If you see "if you were logged in.." on the left, click it and log in - Click the "Vote for it" link on the left
|
|
Ryker Beck
Photographer & Designer
Join date: 23 Feb 2007
Posts: 57
|
05-26-2009 12:42
Okay this seems to have worked... really this is just me piecing together bits of other scripts and trying to make one that does what I want. LOL! This one will reset the script only if the notecard has changed. Let me know if you spot any problems or have suggestions on how I could make this better, anyone! // 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>; string notecard_name = "configuration"; //config notecard name here key notecarduuid; key queryhandler;
// Globals integer iNotecardIndex; integer iNotecardCount; integer iNoteCardLine; key kCurrentDataRequest; string sSettingsNotecard;
init() { queryhandler = llGetNotecardLine(sSettingsNotecard, iNoteCardLine); notecarduuid = llGetInventoryKey(notecard_name); llResetScript(); return; }
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(); }
changed(integer change) { // Check to see if notecard has updated/changed if (change & CHANGED_INVENTORY) if(notecarduuid != llGetInventoryKey(notecard_name)) init(); }
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; } } } }
// This is where your actual code would go state run_object { // check for notecard changes changed(integer change) { if (change & CHANGED_INVENTORY) if(notecarduuid != llGetInventoryKey(notecard_name)) init(); } // Place script to-dos here state_entry() { // save off notecard ID key notecarduuid = llGetInventoryKey(notecard_name); //then perform script work if( TRUE == iShowHoverText ) llSetText( sHoverTextValue, vColor, 1.0 ); else llSetText( "", <0,0,0>, 0.0 ); } }
|
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
05-26-2009 13:01
I think checking the key might be overkill in this situation, since that reader goes through every notecard in it's inventory, so you'd have to store keys for all of them to check...
now if it only read one, (better would be s specific one,) then you store the key in the first 'state_entry' and check it 'changed', and reset if it's new
I like to build my notecard readers to look for llGetScriptName +" - config"; to avoid collisions/searching (plus that nice alphabetical grouping).
_____________________
| | . "Cat-Like Typing Detected" | . This post may contain errors in logic, spelling, and | . grammar known to the SL populace to cause confusion | | - Please Use PHP tags when posting scripts/code, Thanks. | - Can't See PHP or URL Tags Correctly? Check Out This Link... | - 
|