Clickable texture changer for Primary and Children prims
|
|
Satai Diaz
Humble Bounty Hunter
Join date: 9 Aug 2003
Posts: 133
|
06-24-2005 12:09
I am using the following script to do texture changing by touch: default { touch_start(integer total_number) { integer number = llGetInventoryNumber(INVENTORY_TEXTURE); float rand = llFrand(number); integer choice = (integer)rand; string name = llGetInventoryName(INVENTORY_TEXTURE, choice); if (name != "") llSetTexture(name, ALL_SIDES); } }
Problem is it only changes the texture on one object and not the whole linked set. I thought about trying: llSetTexture(LINK_SET,name, ALL_SIDES);
But it comes back with a function call mismatch error. Also is there anyway instead of (integer)rand I can put something else so it will go to the next texture in order then restart with the first one instead of picking a random texture? Any thoughts?
_____________________
Satai Diaz Owner of SD Designs DJ for Crystal Blue @ Cafe Hailey Producer of Digital Paradise Studios & Cinema Admiral of Kazenojin Owner of SLRA
|
|
Ushuaia Tokugawa
Nobody of Consequence
Join date: 22 Mar 2005
Posts: 268
|
06-24-2005 12:30
Christopher was more thorough with his explanation below so use his!  One thing I might add is that his script that goes in each child prim also needs to be in the root prim if you want the root prim's texture changed as well 
|
|
Christopher Omega
Oxymoron
Join date: 28 Mar 2003
Posts: 1,828
|
06-24-2005 12:36
In order to change the texture on the link set, you need to put a script in each prim of the link set. There is currently no way to set a texture on a prim that the script is not in, even if its within the same linked set. (See this to vote for a way to.) The script to have in each child prim is something like this: default { link_message(integer sender, integer side, string textureKey, key methodName) { if (methodName == "setTexture") { llSetTexture(textureKey, side); } } }
Then in the prim that's going to change the colors (that you touch), use this code: setLinkTexture(integer linkNumber, string textureKey, integer side) { llMessageLinked(linkNumber, side, textureKey, "setTexture"); }
integer currentTexture; default { touch_start(integer totalNum) { string textureName = llGetInventoryName(INVENTORY_TEXTURE, currentTexture); if (textureName != "") setLinkTexture(LINK_SET, textureName, ALL_SIDES); integer numTextures = llGetInventoryNumber(INVENTORY_TEXTURE); if (curTexture < numTextures) { // If we have more textures. ++curTexture; // Go to the next one. } else { curTexture = 0; // Go to the beginning of the list. } } }
|
|
Kage Seraph
I Dig Giant Mecha
Join date: 3 Nov 2004
Posts: 513
|
06-24-2005 12:40
Hello, you can get around the lack of llSetLinkTexture() calls by having a receiver script in each prim to be retextured. This is practical on a scale of vehicles (i.e., 30 prims or less) but cumbersome above that. Briefly,
the broadcaster llMessageLinks to LINK_ALL some message like "texture FOO" and the receiver, within the link_message() event, parses "texture FOO" into a list (or does a substring query, I suppose, never tried it that way) and recognizes the command "texture" then accepts "FOO" as the argument. From there, the receiver script matches the argument to a given texture key and does llSetTexture(given_texture_key,ALL_SIDES) or whatever the syntax is. Doing so causes a hit on performance as, in the case of a vehicle, 30 prims get a full update data slug pushed to the client all at once. Still, giving your users the ability to texture dynamically is good times.
As far as selecting sequential textures, you could kludge it by having a state for each texture set, and using touch_start to cycle through the states sequentially. Or, more compactly, you could store a list of texture keys, with an index variable to hold one's place in the list. Use a trigger like touch_start to increment to the next texture and the placeholder variable. When you reach the end of the list, set the index variable back to 0 and cycle through the list again.
|
|
Satai Diaz
Humble Bounty Hunter
Join date: 9 Aug 2003
Posts: 133
|
06-24-2005 12:40
Thanks Ushuaia,
Works great. Now how would I make that code so it's not a random texture and it's just the next texture in the inventory?
_____________________
Satai Diaz Owner of SD Designs DJ for Crystal Blue @ Cafe Hailey Producer of Digital Paradise Studios & Cinema Admiral of Kazenojin Owner of SLRA
|
|
Kage Seraph
I Dig Giant Mecha
Join date: 3 Nov 2004
Posts: 513
|
06-24-2005 12:42
From: Christopher Omega In order to change the texture on the link set, you need to put a script in each prim of the link set. There is currently no way to set a texture on a prim that the script is not in, even if its within the same linked set. (See this to vote for a way to.) The script to have in each child prim is something like this: default { link_message(integer sender, integer side, string textureKey, key methodName) { if (methodName == "setTexture") { llSetTexture(textureKey, side); } } }
Then in the prim that's going to change the colors (that you touch), use this code: setLinkTexture(integer linkNumber, string textureKey, integer side) { llMessageLinked(linkNumber, side, textureKey, "setTexture"); }
integer currentTexture; default { touch_start(integer totalNum) { string textureName = llGetInventoryName(INVENTORY_TEXTURE, currentTexture); if (textureName != "") setLinkTexture(LINK_SET, textureName, ALL_SIDES); integer numTextures = llGetInventoryNumber(INVENTORY_TEXTURE); if (curTexture < numTextures) { // If we have more textures. ++curTexture; // Go to the next one. } else { curTexture = 0; // Go to the beginning of the list. } } }
DANG IT. This is way more elegant than how I've been doing it. =) That Christopher Omega. Whatta guy! Kage Seraph <---- Still learning.
|
|
Satai Diaz
Humble Bounty Hunter
Join date: 9 Aug 2003
Posts: 133
|
06-24-2005 12:44
Chris in your code that I would put in the primary object I got a Syntax error on the line: setLinkTexture(integer linkNumber, string textureKey, integer side) {
Anyway around that? NM, I fixed that now I got an error in the line if (curTexture < numTextures) { // If we have more textures.
The cursor is right before the < and it says "ERROR: Name not defined within scope"
_____________________
Satai Diaz Owner of SD Designs DJ for Crystal Blue @ Cafe Hailey Producer of Digital Paradise Studios & Cinema Admiral of Kazenojin Owner of SLRA
|
|
Satai Diaz
Humble Bounty Hunter
Join date: 9 Aug 2003
Posts: 133
|
06-24-2005 12:49
Ok, I got the script working but now it only changes the texture on the child but not the original prim. Am I doing something wrong?
_____________________
Satai Diaz Owner of SD Designs DJ for Crystal Blue @ Cafe Hailey Producer of Digital Paradise Studios & Cinema Admiral of Kazenojin Owner of SLRA
|
|
Satai Diaz
Humble Bounty Hunter
Join date: 9 Aug 2003
Posts: 133
|
06-24-2005 13:04
Ok all I finally got it working. Thank you everyone for your help!
_____________________
Satai Diaz Owner of SD Designs DJ for Crystal Blue @ Cafe Hailey Producer of Digital Paradise Studios & Cinema Admiral of Kazenojin Owner of SLRA
|
|
Anzo Seifert
Registered User
Join date: 3 Oct 2005
Posts: 4
|
10-26-2005 12:03
I can't seem to get it to work at all I get an error on
if (curTexture < numTextures) { // If we have more textures.
and I can't get past that, no textures change. can anyone tell me what I have to change to fix that and what I have to do to get it to work?.
|
|
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
|
10-26-2005 12:10
Replace this line: integer currentTexture; with: integer curTexture;
|
|
Anzo Seifert
Registered User
Join date: 3 Oct 2005
Posts: 4
|
10-26-2005 12:20
Ok, I renamed the 2 currentTexture to curTexture and its saved, but clicking doesn't change the texture. Do I need to rename the textures to anything?..
|
|
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
|
10-26-2005 12:27
How many prims does your object have? The script that says "should go in every child prim" also needs to be in the main prim if you want that to change texture as well. So if you only have a 1-prim object, both scripts need to be in that prim. Unless 1.7 has changed something, this should work.
And if you have a 1 prim object, you don't need to use link messages, you can set the texture directly. This script is for setting textures on a multi-prim object.
|
|
Anzo Seifert
Registered User
Join date: 3 Oct 2005
Posts: 4
|
10-26-2005 12:30
Oh, ok ^^ thanks. I thought you only needed both if it were multiple Prims. I added both scripts and its working now, Thanks.
|
|
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
|
10-26-2005 12:33
If you have only one prim, you can do it with one script. Use the main script, replace the function at the top with: setLinkTexture(integer linkNumber, string textureKey, integer side) { llSetTexture(textureKey, side); }
Now instead of sending a message to other scripts in the object, it'll just set the texture on its own prim. Then you won't need the second script.
|
|
Denrael Leandros
90 Degrees From Everythin
Join date: 21 May 2005
Posts: 103
|
Follow on Texture Question
11-11-2005 10:27
If I have a link set, is it possible to pull the textures from a different object? For example, if I have all the textures in "master", and a second prim called "slave", and I have a listener set up in slave, can I have slave display a texture not in his content, but rather in "master"?
|
|
Leyah Renegade
Live Musician
Join date: 2 Nov 2006
Posts: 125
|
04-16-2007 08:52
OK, I have tried this and it only seems to work if all the textures are copied into both the root and child prims. Is this supposed to be the case?
|
|
Senuka Harbinger
A-Life, one bit at a time
Join date: 24 Oct 2005
Posts: 491
|
04-16-2007 13:16
There is a new function that's been introduced since this script tidbit was written called llSetLinkPrimitiveParams where you can specify the texture of any primitive in a link set by calling the child prim number, face number on the child prim, and texture key (no need to have the actual texture loaded anywhere in the linkset. It's a very extensive function like llSetPrimitiveParams for what you can do with it so I reccomend playing around with it.
_____________________
My SLExchange shopTypos are forgiven; desecrating the english language with reckless abandon and necrophilic acts is not. The function is working perfectly fine. It's just not working the way you wanted it to work.
|
|
Leyah Renegade
Live Musician
Join date: 2 Nov 2006
Posts: 125
|
04-16-2007 13:30
Oh excellent! Will have a look at that.
But is there an easy way to find a prim's link number? I have some objects that have a lot of prims linked together by mass selection and it seems to be a pain to find the link number.
|
|
Senuka Harbinger
A-Life, one bit at a time
Join date: 24 Oct 2005
Posts: 491
|
04-16-2007 14:33
From: Leyah Renegade Oh excellent! Will have a look at that.
But is there an easy way to find a prim's link number? I have some objects that have a lot of prims linked together by mass selection and it seems to be a pain to find the link number. I have not found an easy way, but I suppose one could use llSetLinkPrimitiveParams with a numbered texture to have it retexture the prims so that the number on the texture shows the link number. you might also be able to use the changed() event to have the root prim determine which child prim was touched.
_____________________
My SLExchange shopTypos are forgiven; desecrating the english language with reckless abandon and necrophilic acts is not. The function is working perfectly fine. It's just not working the way you wanted it to work.
|