UUID Texture Switcher
|
|
Shadow Pointe
Respect Mah Authoratah!
Join date: 13 Aug 2006
Posts: 90
|
05-25-2008 05:17
This is probably very simple but I am not a scripter at all, and don't know how to get this to work. I also searched around a bit but could not find an answer, so I'm posting. Basically, I have a script that should change a prim's texture through a typed command instead of touch, and by UUID, but it isn't working. The script is: From: someone integer i = 0; list UUID = ["key-number-one", "key_number_two", "etc"]; default { state_entry() { } listen(integer channel, string name, key id, string msg) { if (llToLower(msg) == "switch"  { integer num_textures = llGetListLength(UUID); i++; if (i > num_textures - 1) { i = 0; } key texture = llList2Key(UUID, i); llSetTexture(texture, ALL_SIDES); llSetLinkTexture(LINK_SET, texture, ALL_SIDES); } } } I replaced the "key number one" etc with the UUIDs, but no luck. What do I do to correct this, or what am I missing?
|
|
Ollj Oh
Registered User
Join date: 28 Aug 2007
Posts: 522
|
05-25-2008 08:01
use string" instead of "key". llSetTexture() demands a STRING and theres barely any difference from string to key, but strings are more flexible! cut the "-1" from your condition. list indexing/counting starts at "0", integer num_textures = llGetListLength(UUID); i++; if (i>num_textures-1) i; lets "i" never be =numtextures, = the last texture of the list, and the last texture in the list will be skipped, but your loop should still display something your way. if yor list only has 2 textures you wont see the second one and no change ever. llSetLinkTexture(LINK_SET,*) already includes llSetTexture  , so thats uneccessary called twice and just deelaying the script for a small hope of hammering the texture to the region a bit faster, nonsense in this case.
|
|
Kaylan Draken
Registered User
Join date: 2 Dec 2006
Posts: 127
|
05-25-2008 09:55
Don't know if this is the hole script but i am missing a llListen in the State_entry. You tell the script to listen but not where to listen too (witch channel, object or person) example at : http://rpgstats.com/wiki/index.php?title=Listen
|
|
Shadow Pointe
Respect Mah Authoratah!
Join date: 13 Aug 2006
Posts: 90
|
05-25-2008 13:35
Thank you for the advice; I tried to mess around with what you told me but I still can't get it to work. If it's not too much trouble, would someone be able to look at it again and post a version that works after I plug in the UUIDs? You can also just send it to me in-world. I would really appreciate it.
|
|
Pale Spectre
Registered User
Join date: 2 Sep 2005
Posts: 586
|
05-25-2008 13:41
integer i = 0; list UUID = ["key-number-one", "key_number_two", "etc"]; default { state_entry() { llListen(1, "", llGetOwner(), ""  ; // added this listen } listen(integer channel, string name, key id, string msg) { if (llToLower(msg) == "switch"  { integer num_textures = llGetListLength(UUID); i++; if (i > num_textures - 1) { i = 0; } key texture = llList2Key(UUID, i); llSetTexture(texture, ALL_SIDES); llSetLinkTexture(LINK_SET, texture, ALL_SIDES); } } } then just say: /1 switch 
|
|
Shadow Pointe
Respect Mah Authoratah!
Join date: 13 Aug 2006
Posts: 90
|
05-25-2008 13:57
That works great, thank you!! 
|
|
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
|
05-25-2008 14:22
Kaylan Draken suggested the most major problem, i.e. you can never talk to your script the way it is currently written. Ollj is also correct in his comments although llSetTexture will take a key without casting. The only other things I would change would be a) to read the list length in state entry, its not going to change unless you recompile so why reevaluate it every time? and b) to add a changed event handler for when the object gets a new owner. integer i = 0; integer CHANNEL = 99; list UUID = ["9e4ea074-c06a-a205-a619-ee2fab25f982", "e6708fa9-53a5-a655-5fc6-bf5649169de6", "caa0f5ff-6229-d4a8-14a3-0552fdc86172"]; integer num_textures = 0;
default { state_entry() { llListen(CHANNEL,"",llGetOwner(),""); // Listen only to our owner num_textures = llGetListLength(UUID); // Find out how many textures llOwnerSay("Texture switcher listening on channel " + (string)CHANNEL + " , " + (string)num_textures + " textures available"); // inform owner --num_textures;// Decremened so we can simplify the loop test } listen(integer channel, string name, key id, string msg) { if (llToLower(msg) == "switch") { key texture = llList2Key(UUID, i); // Ge the UUID llSetLinkTexture(LINK_SET, texture, ALL_SIDES); // Set every one
if (i < num_textures ) // Not reached end of textures { ++i; // increment the counter } else { i = 0; // reset to zero } } } changed(integer change) { if(change & CHANGED_OWNER) // New Owner { llResetScript(); } } }
_____________________
I'm back......
|
|
Shadow Pointe
Respect Mah Authoratah!
Join date: 13 Aug 2006
Posts: 90
|
05-25-2008 19:47
Thanks, Newgate, I forgot about having it check for a new owner.  For some reason, the first time you give the "switch" command with the posted code, nothing happens, but after that it works perfectly. 
|
|
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
|
05-26-2008 03:40
From: Shadow Pointe Thanks, Newgate, I forgot about having it check for a new owner.  For some reason, the first time you give the "switch" command with the posted code, nothing happens, but after that it works perfectly.  What you will probably find is that the texture is switching to texture 0 which was already set? move3 the increment code back before the "key texture = llList2Key(UUID,i);" should fix it.
_____________________
I'm back......
|