Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Help with a Global Variable

Mitzpatrick Fitzsimmons
Neurotican Mage
Join date: 20 Sep 2004
Posts: 62
09-14-2005 13:45
Could someone explain why this does not work?

CODE

key gTX_0 = "7b08ac48-d7a7-2050-071e-09f7845cc18d";
key gTX_1 = "9beba3c0-f7f4-9261-808e-d51a031697ad";

default
{
state_entry()
{
llListen(0, "", llGetOwner(), "");
}

listen(integer chan, string name, key id, string mess)
{
if( llToLower( llGetSubString( mess, 0, 3) ) == "scr ")
{
string SCR = llToLower( llGetSubString(message, 4, -1) ) ;

llSetTexture("gTX_"+SCR ,5);
}
}
}


The way I see it, the Global is there...but when I type scr 0 or scr 1, I get errror could not find texture gTX_0 (or gTX_1 respectively)...??? It is like the script expects the Object to have the Texture in its Inventory...rather than using the Global key that is provided. Am I doing something wrong (obviously I am) or do I just not "get-it" (most probable too)?
_____________________
:rolleyes: I dont know it all...just enough to be "Dangerous!"
Ushuaia Tokugawa
Nobody of Consequence
Join date: 22 Mar 2005
Posts: 268
09-14-2005 13:56
From: Mitzpatrick Fitzsimmons

llSetTexture("gTX_"+SCR ,5);


It's looking for a texture with a name like "gTX_0" in the inventory of the object. It looks like maybe you're trying to do something similar to an eval() to which LSL has no equivalent.

Two alternatives to what you are doing:

    Instead of separate variables for each key, put your keys in a list.
    [code]
    list textures = ["7b08ac48-d7a7-2050-071e-09f7845cc18d", "9beba3c0-f7f4-9261-808e-d51a031697ad"];

    default
    {

    state_entry()
    {
    llListen(0, "", llGetOwner(), "";);
    }

    listen(integer chan, string name, key id, string mess)
    {
    if( llToLower( llGetSubString( mess, 0, 3) ) == "scr ";)
    {
    string SCR = llToLower( llGetSubString(message, 4, -1) ) ;

    llSetTexture(llList2Key(textures, (integer)SCR), 5);
    }
    }
    }
    [/code]


    Or, get rid of those global keys altogether and place the texture assets in the contents of the object and name them gTX_0 and gTX_1.
_____________________
Mitzpatrick Fitzsimmons
Neurotican Mage
Join date: 20 Sep 2004
Posts: 62
Gotcha
09-14-2005 14:13
Thank you for pointing that out.

I was originally consdidering a list of keys too, but stuffing prims gets tiring lol. Ill go with the list :)
_____________________
:rolleyes: I dont know it all...just enough to be "Dangerous!"
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
09-14-2005 14:29
Are these linked prims in a single object? If so, you could use a notecard for a slower running but easier to maintain solution, especially if the number of textures or the keys can change. Then you just update the notecard, and all the prims pick up the new textures.

I haven't checked this for syntax, so consider this psuedocode :)

In the main reader script, use the number extracted from the listen string to read a line in a notecard. The notecard contains one texture key per line. Then send the texture to the other prims in a link message:

CODE


...

key notecardQuery;

listen(...)
{
...
string SCR = llToLower( llGetSubString(message, 4, -1) ) ;

notecardQuery = llReadNotecardLine("notecard name", (integer)SCR));
}

dataserver(key query_id, string data)
{
if (query_id == notecardQuery)
{
if (data != EOF)
{ // We got a valid key from the notecard
llMessageLinked(LINK_SET, 0, "", (key)data);
}
}
}


And the receiver script, which goes into every prim including the one which has the reader script:

CODE

...

link_message(integer sender, integer num, string str, key id)
{
llSetTexture(id, 5);
}


Like I said, the code probably won't compile, but that's the idea :)
Zindorf Yossarian
Master of Disaster
Join date: 9 Mar 2004
Posts: 160
09-16-2005 10:57
It looks like you were trying to construct a variable name, which you cannot do.
_____________________
Badass Ninja Penguin: Killing stuff it doesn't like since sometime in May 2004.