Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Notecards and vaiables (again)

Innula Zenovka
Registered User
Join date: 20 Jun 2007
Posts: 1,825
03-25-2009 07:41
Apologies for asking the same question twice (/54/88/313233/1.html), but I need to finish a project for someone and I'm still really not sure if my solution is the best one.

Brief recap. I'm trying to make something that enables the end user easily to configure talking objects by notecard, so, for example, if you and most of your friends don't have English as your first language you don't have to hug/kiss them in a foreign language all the time.

If I'm dealing with variables for which I have values when I read the notecard (the owner's name, for example) that's easy; I can use placeholders in my notecard and assign values inside the dataserver event.

But what do I do with a variable for which I don't yet know the value, like the name of the avatar I'm kissing?

My tentative solution is to write a notecard line like "%FirstName% gives %Target% a %AnimName%", substitute the owner's first name (since I already know that) for %FirstName% in the dataserver event when I read the notecard.

Then, each time I come to hug or kiss someone, I grab my target's name with llDetectedName(0) and turn it into a firstname, check what I'm doing to him, and then use some sort of string replacement function to fill in the appropriate values.

This just feels wrong somehow -- as if there's a more elegant and less cumbersome way of doing it that's somehow eluding me.

In short, what do I write in a notecard to get the same results as llSay(0, strOwnerName + " gives " +strTargetName + " a big " + strAnimName), given that I don't know who/what strTargetName and strAnimName represent when I read the notecard?
Johan Laurasia
Fully Rezzed
Join date: 31 Oct 2006
Posts: 1,394
03-25-2009 09:45
You're on the right path, the only way to customize spoken text from a notecard would to be to use delimiters like you're saying. I have a bot that has a custom greeting that one can put together using <name> as the avatar's name, and when the greeting happens it replaces all occurrences of <name> with the avatar's name.
_____________________
My tutes
http://www.youtube.com/johanlaurasia
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
03-25-2009 11:20
you could use the string replace function that Haravikk wrote...
CODE

string strReplace(string str, string search, string replace) {
return llDumpList2String( llParseStringKeepNulls( ( str = "" ) + str, [search], [] ), replace );
}

//-- example call
llSay( 0, strReplace( strReplace( llList2String( gLstPhrases, 0 ), "%Target%", llDetectedName( 0 ) ), "%AnimName%", vStrAnimName ) );

as you can see that's actually clunkier for your usage than the method you already hit upon of building it on the spot, with some hardcoded portions.

a fun trick to make it all more fluid in output is to code all the phrases as "/me ..." and swap the owners name in as the object name, such as

//-- global
string gStrProduct = "product name"
//-- in the changed even to catch owner changes
string gStrOwner = llKey2Name( llGetOwner() );
//-- before the llSay call
llSetObjectDesc( gStrOwner );
//-- after the say call
llSetObjectDesc( gStrProduct );

//-- coupled with "/me gives..." yields
Void Singer gives...

regardless, I definitely wouldn't try to encode owner name as a notecard variable, and if you're only using a small amount of non-variable text, replacing variables isn't going to be as effecient
_____________________
|
| . "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...
| -