Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Getting the PREVIOUS texture

Thorne Kaiser
Nice Guy
Join date: 29 Nov 2005
Posts: 132
02-09-2006 05:14
How do I get this script to move to the PREVIOUS texture?

CODE
setLinkTexture(integer linkNumber, string textureKey, integer side) {
llMessageLinked(linkNumber, side, textureKey, "setTexture");
}

integer currTexture;
default {
touch_start(integer totalNum) {
string textureName = llGetInventoryName(INVENTORY_TEXTURE, currTexture);
if (textureName != "")
setLinkTexture(LINK_SET, textureName, ALL_SIDES);
integer numTextures = llGetInventoryNumber(INVENTORY_TEXTURE);
if (currTexture < numTextures) { // If we have more textures.
++currTexture; // Go to the next one.
} else {
currTexture = 0; // Go to the beginning of the list.
}
}
}


I see that this line:
CODE
            ++currTexture; // Go to the next one.


should probably read like this

CODE
            --currTexture; // Go to the previous one.


But nothing happens. The texture remains the same in all linked prims.
Thorne Kaiser
Nice Guy
Join date: 29 Nov 2005
Posts: 132
02-09-2006 09:13
Tried currTexture - 1

still won't budge :( :(
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
02-09-2006 09:27
That's because it starts out at 0, so if you go 1 below 0, you end up with -1, and -1 isn't a valid index for finding a texture. Try this:

CODE

setLinkTexture(integer linkNumber, string textureKey, integer side) {
llMessageLinked(linkNumber, side, textureKey, "setTexture");
}

integer currTexture;
default {
touch_start(integer totalNum) {
string textureName = llGetInventoryName(INVENTORY_TEXTURE, currTexture);
if (textureName != "")
setLinkTexture(LINK_SET, textureName, ALL_SIDES);
integer numTextures = llGetInventoryNumber(INVENTORY_TEXTURE);
if (currTexture > 0) { // If we have more textures.
--currTexture; // Go to the previous one.
} else {
currTexture = numTextures - 1; // Go to the end of the list.
}
}
}


I think that should work.
paulie Femto
Into the dark
Join date: 13 Sep 2003
Posts: 1,098
hmm
02-09-2006 09:40
Does the code work at all? It looks like you're switching the STRING and KEY variables in your llMessageLinked() statement.

You have:
llMessageLinked(linkNumber, side, textureKey, "setTexture";);

Shouldnt it be:
llMessageLinked(linkNumber, side, "setTexture", textureKey);

according to the docs:
llMessageLinked(integer linknum, integer num, string str, key id);

We cant see the link child's code, so we don't know what the children are doing with the Link Message, but I would think the compiler would throw an error with those variable types in the wrong place.

edit: the code apparently compiles ok. I guess because a key is really just a long string. But the statement is still mixing up the places of the key and string, I think. Perhaps your linkset is getting confused by that error.

Also, here's a tidbit on linknumbers from the wiki:
"In objects with only one prim, linknum is 0. In objects with multiple prims, the linknum count starts at 1. (So in a two-prim object, llGetLinkNumber would return 1 in the parent and 2 in the child."
_____________________
REUTERS on SL: "Thirty-five thousand people wearing their psyches on the outside and all the attendant unfettered freakishness that brings."
Thorne Kaiser
Nice Guy
Join date: 29 Nov 2005
Posts: 132
02-09-2006 10:35
Yes, there is a child scripts as well. Don't have it on me at the moment...I'll post it when I get back. Thanks!
Folco Boffin
Mad Moo Cow Cultist
Join date: 27 Feb 2005
Posts: 66
02-09-2006 11:39
In response to paulie, yes, the llLinkMessage is mixed up, and the listening script is probabally not getting the right message.

As for link numbers, it doesn't make a differance if this is a single prim or multi-prim object since LINK_SET is being used.

Corrected code (hopefully):
CODE

setLinkTexture(integer linkNumber, string textureKey, integer side) {
llMessageLinked(linkNumber, side, "setTexture", textureKey);
}

integer currTexture;

default {
touch_start(integer totalNum) {
string textureName = llGetInventoryName(INVENTORY_TEXTURE, currTexture);
if (textureName != "")
setLinkTexture(LINK_SET, textureName, ALL_SIDES);
integer numTextures = llGetInventoryNumber(INVENTORY_TEXTURE);
if (currTexture > 0) { // If we have more textures.
--currTexture; // Go to the previous one.
} else {
currTexture = numTextures - 1; // Go to the end of the list.
}
}
}


Hopefully that will clear your script up.
_____________________
^-^

Signed,
Gorgarath,
Whom in this game called Second Life,
plays the avatar Folco Boffin,
and in this game called First Life,
plays the avatar John McDonnell.
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
02-09-2006 12:09
I could be wrong, but IIRC, the receiving script is similarly reversed, so the whole thing works. If that's true, then 'correcting' the sending script by reversing the string and the key would break the overall functionality. Just something to keep in mind.
Thorne Kaiser
Nice Guy
Join date: 29 Nov 2005
Posts: 132
02-09-2006 13:12
Ok, back. Here is the child script:

CODE
 default {
link_message(integer sender, integer side, string textureKey, key methodName) {
if (methodName == "setTexture") {
llSetTexture(textureKey, side);
}
}
}
I'll go in world and give your codes a try and post back! :)
Thorne Kaiser
Nice Guy
Join date: 29 Nov 2005
Posts: 132
02-09-2006 13:36
Ok, I tried it. It goes backwards, but something funky occurs. It does not go back from the cuurent texture. And the forward does not go forward from the current texture. It picks up where it left off I believe. So if I am on Texture 4 now

Press forward > Texture 5
Press forward > Texture 6
Press back > Texture 3 (picks up from 4...not 6)
Press back > Texture 2
Press forward > Texture 7 (picks up from Texture 6...not 2)
...and so on

Strange behavior.

I am posting the code in case you guys want to give it a college try. I just can't figure out what's wrong with it.

CODE
//Back Button
default {
touch_start(integer totalNum) {
string textureName = llGetInventoryName(INVENTORY_TEXTURE, currTexture);
if (textureName != "")
setLinkTexture(LINK_SET, textureName, ALL_SIDES);
integer numTextures = llGetInventoryNumber(INVENTORY_TEXTURE);
if (currTexture > 0) { // If we have more textures.
currTexture = currTexture - 1; // Go to the previous one.
// --currTexture; // Go to the previous one.
} else {
currTexture = numTextures - 1; // Go to the end of the list.
}
}
}

CODE
//Forward Button
setLinkTexture(integer linkNumber, string textureKey, integer side) {
llMessageLinked(linkNumber, side, textureKey, "setTexture");
}

integer currTexture;
default {
touch_start(integer totalNum) {
string textureName = llGetInventoryName(INVENTORY_TEXTURE, currTexture);
if (textureName != "")
setLinkTexture(LINK_SET, textureName, ALL_SIDES);
integer numTextures = llGetInventoryNumber(INVENTORY_TEXTURE);
if (currTexture < numTextures) { // If we have more textures.
++currTexture; // Go to the next one.
} else {
currTexture = 0; // Go to the beginning of the list.
}
}
}

CODE
//Child Prim Script
default {
link_message(integer sender, integer side, string textureKey, key methodName) {
if (methodName == "setTexture") {
llSetTexture(textureKey, side);
}
}
}
Folco Boffin
Mad Moo Cow Cultist
Join date: 27 Feb 2005
Posts: 66
02-09-2006 13:53
Is your back and forward options in seperate scripts? If that's the case then yes, you're going to have this happen. You'll have to communicate currentTexture between the two scripts.
_____________________
^-^

Signed,
Gorgarath,
Whom in this game called Second Life,
plays the avatar Folco Boffin,
and in this game called First Life,
plays the avatar John McDonnell.
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
02-09-2006 13:59
I'm assuming the back and forward buttons are different prims? If so, then they each have a "current texture". If you press the forward button, it updates its current texture to be one higher than the last one it was displaying. But the back button's script doesn't do anything, so it still thinks the current texture is whatever *it* last displayed. So the next time you press the back button, it'll do the math from its own idea of the current texture.

The solution is to move all the forward/backward logic into one script, and let the buttons just tell the main script that they were clicked on. So...

CODE

//Back Button
default {
touch_start(integer totalNum) {
// Tell the main script that the back button was pressed
llMessageLinked(LINK_SET, 0, "Back", NULL_KEY);
}
}


CODE

//Forward Button
default {
touch_start(integer totalNum) {
// Tell the main script that the forward button was pressed
llMessageLinked(LINK_SET, 0, "Forward", NULL_KEY);
}
}


And then in the main script, handle the Back and Forward link messages, and do the texture stuff there

CODE

// Main Script
setLinkTexture(integer linkNumber, string textureKey, integer side) {
llMessageLinked(linkNumber, side, textureKey, "setTexture");
}

integer currTexture;

default {
link_message(integer sender, integer num, string str, key id) {
if (str == "Back") {
// Back button is telling us that someone clicked it
string textureName = llGetInventoryName(INVENTORY_TEXTURE, currTexture);
if (textureName != "")
setLinkTexture(LINK_SET, textureName, ALL_SIDES);
integer numTextures = llGetInventoryNumber(INVENTORY_TEXTURE);
if (currTexture > 0) { // If we have more textures.
currTexture = currTexture - 1; // Go to the previous one.
// --currTexture; // Go to the previous one.
} else {
currTexture = numTextures - 1; // Go to the end of the list.
}
}
else if (str == "Forward") {
// Forward button is telling us that someone clicked it
string textureName = llGetInventoryName(INVENTORY_TEXTURE, currTexture);
if (textureName != "")
setLinkTexture(LINK_SET, textureName, ALL_SIDES);
integer numTextures = llGetInventoryNumber(INVENTORY_TEXTURE);
if (currTexture < numTextures) { // If we have more textures.
++currTexture; // Go to the next one.
} else {
currTexture = 0; // Go to the beginning of the list.
}
}
}
}


Something like that... that might not compile, I did that in a hurry. But you get the idea, hopefully.
Folco Boffin
Mad Moo Cow Cultist
Join date: 27 Feb 2005
Posts: 66
02-09-2006 14:25
Amazing how often Hiro's Vendor Script gets resused. But yeah, that looks about right. I was going to go look that up and post it, but had to run to the store to get random stuff that is apparently needed for dinner and some other stuff that "I might as well get as long as I'm there."

But ya messed up. Or rather, the original one did kinda. In the main script, you'd probabally want to change currTexture before applying the change. So more like this:

CODE

// Main Script
setLinkTexture(integer linkNumber, string textureKey, integer side) {
llMessageLinked(linkNumber, side, textureKey, "setTexture");
}

integer currTexture;

default {
link_message(integer sender, integer num, string str, key id) {
if (str == "Back") {
// Back button is telling us that someone clicked it
integer numTextures = llGetInventoryNumber(INVENTORY_TEXTURE);
if (currTexture > 0) { // If we have more textures.
currTexture = currTexture - 1; // Go to the previous one.
--currTexture; // Go to the previous one.
} else {
currTexture = numTextures - 1; // Go to the end of the list.
}
string textureName = llGetInventoryName(INVENTORY_TEXTURE, currTexture);
if (textureName != "")
setLinkTexture(LINK_SET, textureName, ALL_SIDES);
}
else if (str == "Forward") {
// Forward button is telling us that someone clicked it
integer numTextures = llGetInventoryNumber(INVENTORY_TEXTURE);
if (currTexture < numTextures) { // If we have more textures.
++currTexture; // Go to the next one.
} else {
currTexture = 0; // Go to the beginning of the list.
}
string textureName = llGetInventoryName(INVENTORY_TEXTURE, currTexture);
if (textureName != "")
setLinkTexture(LINK_SET, textureName, ALL_SIDES);
}
}
}


Just how I would do it. But it will work either way. Just depending on what else you are doing, it will be kinda odd. Like if you wanted to sell currTexture or something. If you do it the other way, it will be showing a differant texture than what is stored in currTexture and you'll get some upset people complaining about not getting what they want.
_____________________
^-^

Signed,
Gorgarath,
Whom in this game called Second Life,
plays the avatar Folco Boffin,
and in this game called First Life,
plays the avatar John McDonnell.
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
02-09-2006 14:31
LOL. Good catch :)
Folco Boffin
Mad Moo Cow Cultist
Join date: 27 Feb 2005
Posts: 66
02-09-2006 15:01
I try sometimes. :D
_____________________
^-^

Signed,
Gorgarath,
Whom in this game called Second Life,
plays the avatar Folco Boffin,
and in this game called First Life,
plays the avatar John McDonnell.
Thorne Kaiser
Nice Guy
Join date: 29 Nov 2005
Posts: 132
02-09-2006 15:04
Ok, got it working guys.

Change:

currTexture = currTexture - 1; // Go to the previous one.
--currTexture; // Go to the previous one.

to

//currTexture = currTexture - 1; // Go to the previous one.
--currTexture; // Go to the previous one.

Removing that line did the trick there. It's doing it twice so it was jumping back a couple of textures instead of just one.

Many hugs to you (well the ladies anyway)
Hi 5 to you dudes (laughs)
Folco Boffin
Mad Moo Cow Cultist
Join date: 27 Feb 2005
Posts: 66
02-09-2006 15:22
lol, I was wondering why I had // at the beginning of a line when I copied that. Thought I musta cut a comment off at the wrong spot.
_____________________
^-^

Signed,
Gorgarath,
Whom in this game called Second Life,
plays the avatar Folco Boffin,
and in this game called First Life,
plays the avatar John McDonnell.