Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Texture switching script has me stumped

Korneilius Worthington
Registered User
Join date: 7 Oct 2006
Posts: 6
12-02-2006 08:07
default
{
touch_start(integer total_number)
{
llSetTexture("isle08", ALL_SIDES);
}


touch_start(integer total_number)
{
llSetTexture("isle01", ALL_SIDES);
}

touch_start(integer total_number)
{
llSetTexture("isle08", ALL_SIDES);

}

}

okay so obviously this script isn't working out. And it's my first script and I'm stumped. What should I be doing with this script? What mistakes did I make?

Please don't make a script for me and post it on here. I'm a very strong believer in "Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime."

Any help and advice is definately appreciated...Thanks!
Tyken Hightower
Automagical
Join date: 15 Feb 2006
Posts: 472
12-02-2006 08:22
From: Korneilius Worthington
default
{
touch_start(integer total_number)
{
llSetTexture("isle08", ALL_SIDES);
}


touch_start(integer total_number)
{
llSetTexture("isle01", ALL_SIDES);
}

touch_start(integer total_number)
{
llSetTexture("isle08", ALL_SIDES);

}

}

okay so obviously this script isn't working out. And it's my first script and I'm stumped. What should I be doing with this script? What mistakes did I make?

Please don't make a script for me and post it on here. I'm a very strong believer in "Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime."

Any help and advice is definately appreciated...Thanks!

Putting multiple copies of the same event in one script will cause the rest to be ignored. Seems like what you want to do is switch back and forth between two textures, so you could do something like keep track of whether the texture has been switched by using an integer.

EDIT: Sigh, good job me at not really reading the post. I made a script, but removed it now. :p
_____________________
Logan Park
Registered User
Join date: 23 Sep 2006
Posts: 10
12-02-2006 08:39
CODE

default
{
touch_start(integer total_number)
{
llSetTexture("isle08", ALL_SIDES);
}


touch_start(integer total_number)
{
llSetTexture("isle01", ALL_SIDES);
}

touch_start(integer total_number)
{
llSetTexture("isle08", ALL_SIDES);
}

}


Hi, Korneilius,

I've enclosed your script in [ php ] tags to make it easier for us to read. The script engine only deals with one instance of each event handler (e.g., touch_start) within each state (e.g., default). So I would guess that the task of having three of the same event handler to switch among three textures needs to be handled in just one.

I hope this helps. Alternately, if I've misinterpreted where you're confused, I'm happy to help further with a little correction. =)
Korneilius Worthington
Registered User
Join date: 7 Oct 2006
Posts: 6
12-02-2006 08:43
From: Tyken Hightower

EDIT: Sigh, good job me at not really reading the post. I made a script, but removed it now. :p


It's okay. How would you suggest I go about it? Not sure how I would use an integer. I'm very wet behind the ears when it comes to scripting but I'm doing me best =D
Tyken Hightower
Automagical
Join date: 15 Feb 2006
Posts: 472
12-02-2006 08:48
From: Korneilius Worthington
It's okay. How would you suggest I go about it? Not sure how I would use an integer. I'm very wet behind the ears when it comes to scripting but I'm doing me best =D

When I say keep track of it with an integer, I mean you test whether the integer is true or false, and if it's true, do something, if it's false, do something else, and in either case, set the integer to the opposite.
_____________________
Korneilius Worthington
Registered User
Join date: 7 Oct 2006
Posts: 6
12-02-2006 08:53
From: Tyken Hightower
When I say keep track of it with an integer, I mean you test whether the integer is true or false, and if it's true, do something, if it's false, do something else, and in either case, set the integer to the opposite.


Oooh why didn't I think of that?? Thanks! *goes to tinker*

hmmm not sure how I would go about that...I would just use any random number? Bleh this simple script is starting to get annoying >_> Sorry I'm sooo...erm...what's the right word....green?

Anyway could you explain in more detail by what you mean?
Korneilius Worthington
Registered User
Join date: 7 Oct 2006
Posts: 6
12-02-2006 09:06
Oooh wait If then statements?? o.O
Cooper Conover
Registered User
Join date: 28 Jun 2006
Posts: 10
12-02-2006 09:14
It would help if you put all of the textures you want to be displayed in a list, something like:

list textures = ["texture1", "texture2", "texture3"];

You only need to have one touch_start event. Inside the touch_start event, you can either use the llFrand function to pick out a random texture from your list, or declare an integer variable that can cycle through the list. If this sounds a little confusing, look at the wiki section on lists, specifically look at how indicies work with lists and also the llList2String function. This will let you access each texture in the list as a string to use in llSetTexture.

Something like this:

llSetTexture(llList2String(textures, counter), ALL_SIDES);



Sorry if all of this sounds a little confusing, if you want any clarification let me know, here or in world.
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
12-02-2006 09:30
Here you go :)
CODE

integer num = 0;

default {
touch_start(integer n) {
if(num == 1){
llSetTexture("isle08", ALL_SIDES);
num = 2;
}
else if(num == 2){
llSetTexture("isle01", ALL_SIDES);
num = 0;
}
else{
llSetTexture("isle08", ALL_SIDES);
num = 1;
}
}
}

EDIT: You can not have mutiple touch events in the same state. So I added a counter (num), each time you touch it the (num) changes and if/else checks to see which (num) it is and then does just that condition.
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
LeVey Palou
Registered User
Join date: 31 Aug 2006
Posts: 131
12-02-2006 09:43
"Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime."

"give a man a fish and you feed him for a day. Beat him severely with a fishing pole and you scar him for life."

: P

(hi Jesse!)
Tyken Hightower
Automagical
Join date: 15 Feb 2006
Posts: 472
12-02-2006 09:45
From: Jesse Barnett
Here you go :)
CODE

integer num = 0;

default {
touch_start(integer n) {
if(num == 1){
llSetTexture("isle08", ALL_SIDES);
num = 2;
}
else if(num == 2){
llSetTexture("isle01", ALL_SIDES);
num = 0;
}
else{
llSetTexture("isle08", ALL_SIDES);
num = 1;
}
}
}

EDIT: You can not have mutiple touch events in the same state. So I added a counter (num), each time you touch it the (num) changes and if/else checks to see which (num) it is and then does just that condition.



Or, you could do this, since they're already posting stuff anyhow..
CODE

integer switched = 0;

switch() {
if (switched) llSetTexture("isle08", ALL_SIDES);
else llSetTexture("isle01", ALL_SIDES);
switched = !switched;
}

default
{
touch_start(integer number) {
switch();
}
}

Also, out of boredom, an example of how to go through everything in the object's inventory (sigh):
CODE

integer number = 0;

switch() {
integer max = llGetInventoryNumber(INVENTORY_TEXTURE);
if (max) {
if (number >= max) number = 0;
llSetTexture(llGetInventoryName(INVENTORY_TEXTURE, number), ALL_SIDES);
++number;
}
}

default
{
touch_start(integer number) {
switch();
}
}
_____________________
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
12-02-2006 09:49
From: LeVey Palou
"Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime."

"give a man a fish and you feed him for a day. Beat him severely with a fishing pole and you scar him for life."

: P

(hi Jesse!)

OMG Sorry I did not read all of the OPs original post. Sorry for scarring you Kornelius. But in this case, the wiki doesn't have a good example and it is extremely difficult to explain. So a different saying should be appropriate "A picture is worth a thousand words" ;)
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
Korneilius Worthington
Registered User
Join date: 7 Oct 2006
Posts: 6
12-02-2006 09:57
lol interesting...

Well the scripts that were posted have helped get me a general idea. the switch thing is pretty interesting too. Thanks!
Escort DeFarge
Together
Join date: 18 Nov 2004
Posts: 681
12-02-2006 10:46
Another view on it...
CODE

integer number_of_textures = 0;
integer current_texture = 0;

default {
state_entry() {
number_of_textures = llGetInventoryNumber(INVENTORY_TEXTURE);
}

touch_start(integer number) {
llSetTexture(llGetInventoryName(INVENTORY_TEXTURE, current_texture), ALL_SIDES);
current_texture = (current_texture + 1) % number_of_textures;
}

changed(integer change) {
if (change & CHANGED_INVENTORY) {
llResetScript();
}
}
}
_____________________
http://slurl.com/secondlife/Together
Osgeld Barmy
Registered User
Join date: 22 Mar 2005
Posts: 3,336
12-02-2006 14:52
CODE

integer total_texture_count;
integer next_texture;

default
{
state_entry()
{
total_texture_count = (llGetInventoryNumber(0) - 1);
}

touch_start(integer total_number)
{
llSetTexture(llGetInventoryName(0,next_texture), ALL_SIDES);

if (next_texture < total_texture_count) ++next_texture;
else next_texture = 0;
}
}
Nynthan Folsom
Registered User
Join date: 29 Aug 2006
Posts: 70
12-03-2006 00:06
Just as a matter of interest you could also use states. Perhaps overkill for what you're doing, but an introduction to state switching.

CODE
default {
touch_start(integer iDummy) {
llSetTexture("texture1", ALL_SIDES);
state State1;
}
}

state State1 {
touch_start(integer iDummy) {
llSetTexture("texture1", ALL_SIDES);
state State2;
}
}

state State2 {
touch_start(integer iDummy) {
llSetTexture("texture2", ALL_SIDES);
state State3;
}
}

state State3 {
touch_start(integer iDummy) {
llSetTexture("texture3", ALL_SIDES);
state default;
}
}