Need help with this texture script..
|
|
Wasabi Juran
Registered User
Join date: 25 May 2009
Posts: 10
|
06-05-2009 16:25
Hey, im trying to get this texture script to work. What it does, is on recieving the message screen it changes the texture. What its supposed to do, is add 1 to the variable num, so that i can have a limited amount of textures it can cycle through. But whats going wrong is that its going through both if statements and changing the texture twice because of this, with the one click.. But the thing is, it cant be both of the textures at the same time as num only gets changed once, from 0 to 1. so it shouldnt display the second texture. Also, once its run once, it doesnt change the texture again. Its also set to running. Can anyone help? thanks  edit: forgot to post the code.. lol integer num = 0;
numbercounter() { num = ++num; if (num == 1) { llSetPrimitiveParams([PRIM_TEXTURE, 0, "screens", <0.375,0.230,0>, <-0.310,-0.385,0>, 0]); } if (num == 2) { llSetPrimitiveParams([PRIM_TEXTURE, 0, "screens", <0.375,0.230,0>, <0.190,-0.085,0>, 0]); } if (num > 2) { num == 1; } }
default { link_message(integer sender, integer number, string message, key id) { if (message == "screen") numbercounter(); } }
|
|
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
|
06-05-2009 16:36
Try this ..... integer num = 0; numbercounter() { num = ((num+1)%2) +1; if (num == 1) { llSetPrimitiveParams([PRIM_TEXTURE, 0, "screens", <0.375,0.230,0>, <-0.310,-0.385,0>, 0]); } else if (num == 2) { llSetPrimitiveParams([PRIM_TEXTURE, 0, "screens", <0.375,0.230,0>, <0.190,-0.085,0>, 0]); } } default { link_message(integer sender, integer number, string message, key id) { if (message == "screen") numbercounter(); } }
It compiles OK, and it ought to do what you want. 
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask....  Look for my work in XStreetSL at 
|
|
Wasabi Juran
Registered User
Join date: 25 May 2009
Posts: 10
|
06-05-2009 16:45
It shows the first texture, but not the second. The num = ((num+1)%2) +1; bit, is that supposed to be num = ((num+1)/2) +1; ? thanks
|
|
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
|
06-05-2009 16:51
From: Wasabi Juran It shows the first texture, but not the second. The num = ((num+1)%2) +1; bit, is that supposed to be num = ((num+1)/2) +1; ? thanks Nope. That's num = ((num+1) modulo 2) + 1, so it should yield num = 2 if the old value of num was 1 and num = 1 if the old value was 2. I can't pop in world right now to see why it doesn't work as it should. Try putting llOwnerSay("num = " + (string)num); right after that line and see what vlaue it spits out when you test the script.
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask....  Look for my work in XStreetSL at 
|
|
Wasabi Juran
Registered User
Join date: 25 May 2009
Posts: 10
|
06-05-2009 16:55
From: Rolig Loon Nope. That's num = ((num+1) modulo 2) + 1, so it should yield num = 2 if the old value of num was 1 and num = 1 if the old value was 2. I can't pop in world right now to see why it doesn't work as it should. Try putting llOwnerSay("num = " + (string)num); right after that line and see what vlaue it spits out when you test the script. cool, sounds good. i'll add that line and keep at it, cheers :3
|
|
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
|
06-05-2009 16:59
This is a silly question, but I assume that you have tried using those repeat and offset parameters in Edit to see whether the two textures are where you think they are, right?
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask....  Look for my work in XStreetSL at 
|
|
Wasabi Juran
Registered User
Join date: 25 May 2009
Posts: 10
|
06-05-2009 17:03
From: Rolig Loon This is a silly question, but I assume that you have tried using those repeat and offset parameters in Edit to see whether the two textures are where you think they are, right? yeah, i did. I just found out the problem On the trigger switch, i had it as touch instead of touch_start. So a single click was giving 3 messages out. Switching it to touch_start and putting in the if statement to limit the num made it work. thanks for the help 
|
|
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
|
06-05-2009 17:06
Fantastic! Yeah, always use touch_start to avoid the double bounce. Congratulations.
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask....  Look for my work in XStreetSL at 
|
|
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
|
06-05-2009 17:11
From: Wasabi Juran ..... putting in the if statement to limit the num made it work. thanks for the help  You shouldn't need an if statement to limit the value of num. The way I wrote that line, num should always equal either 1 or 2. If it used to be num = 1, then num+1%2 = 0, so ((num+1)%2)+1 = 1. If it used to be num=2, then (num+1)%2 = 1, so ((num+1)%2)+1 = 2. It should just keep flipping back and forth between them on successive clicks.
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask....  Look for my work in XStreetSL at 
|
|
Wasabi Juran
Registered User
Join date: 25 May 2009
Posts: 10
|
06-05-2009 17:17
From: Rolig Loon You shouldn't need an if statement to limit the value of num. The way I wrote that line, num should always equal either 1 or 2. If it used to be num = 1, then num+1%2 = 0, so ((num+1)%2)+1 = 1. If it used to be num=2, then (num+1)%2 = 1, so ((num+1)%2)+1 = 2. It should just keep flipping back and forth between them on successive clicks. cool, sounds good 
|
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
06-05-2009 18:06
little complicated there... only 2 textures?
num = !num; //-- switch between 0 and 1 (reversed boolean) num = ++num % 2; //-- switch between 0 and 1 (odd / even detection) num = ++num & 1; //-- faster version of odd even detection
the benefit of using 0 based counting is that you can store and reference your offsets (or textures or both) in a list, and have NO if statements.
such as... num = !num; llSetPrimitiveParams( llDeleteSubList( [PRIM_TEXTURE, 0, "screens", <0.375,0.230,0>, <-0.310,-0.385,0>, <0.190,-0.085,0>, 0], num + 4, num + 4 ) );
or really since you are only changing offsets... num = !num; llOffsetTexture( 0, num * .5 - 0.310, num * .3 - 0.385 );
PS if there are only two cels in that image you may want to tweak the repeats, because that gives some seriously overcomplicated math.
_____________________
| | . "Cat-Like Typing Detected" | . This post may contain errors in logic, spelling, and | . grammar known to the SL populace to cause confusion | | - Please Use PHP tags when posting scripts/code, Thanks. | - Can't See PHP or URL Tags Correctly? Check Out This Link... | - 
|
|
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
|
06-05-2009 22:41
I always learn something new. Thanks, Void. 
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask....  Look for my work in XStreetSL at 
|
|
Paladin Pinion
The other one of 10
Join date: 3 Aug 2007
Posts: 191
|
06-06-2009 20:50
From: Rolig Loon num = ((num+1)%2) +1;
I think that will always just return the same number it starts with. I.e., if num == 1, the function will return 1. If num == 2, the function returns 2. To get a numeric rotation, shouldn't it be: num = (num%2)+1;
_____________________
Mote Particle Script Generator - easier and faster than any HUD Also: Paladin's Sunbeam. Up at dawn, gone by dusk, day and night sounds, fully configurable See more at: www.paladinpinion.com
|
|
Osgeld Barmy
Registered User
Join date: 22 Mar 2005
Posts: 3,336
|
06-06-2009 21:10
your correct
|
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
06-07-2009 03:35
nice catch.
_____________________
| | . "Cat-Like Typing Detected" | . This post may contain errors in logic, spelling, and | . grammar known to the SL populace to cause confusion | | - Please Use PHP tags when posting scripts/code, Thanks. | - Can't See PHP or URL Tags Correctly? Check Out This Link... | - 
|
|
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
|
06-07-2009 07:24
Yes. Thanks. /me goes back to her corner.
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask....  Look for my work in XStreetSL at 
|
|
Paladin Pinion
The other one of 10
Join date: 3 Aug 2007
Posts: 191
|
06-07-2009 10:54
From: Rolig Loon Yes. Thanks. /me goes back to her corner. I hope you don't stay there too long, you still know more than me and I'm pretty sure I'm going to need you some day. 
_____________________
Mote Particle Script Generator - easier and faster than any HUD Also: Paladin's Sunbeam. Up at dawn, gone by dusk, day and night sounds, fully configurable See more at: www.paladinpinion.com
|
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
06-07-2009 17:49
I missed it, and it looks like even Osgeld thought it looked right on first blush  (which is probably the only reason I don't feel goofy for missing it, so neither should you)
_____________________
| | . "Cat-Like Typing Detected" | . This post may contain errors in logic, spelling, and | . grammar known to the SL populace to cause confusion | | - Please Use PHP tags when posting scripts/code, Thanks. | - Can't See PHP or URL Tags Correctly? Check Out This Link... | - 
|