Jump to content

Help With Texture Change and Anim Script


RefugeStore
 Share

You are about to reply to a thread that has been inactive for 2408 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Hi guys, I'm having trouble, and I hope someone can help.  I'm not at all a scripter, I know virtually nothing about it, but I really need a script for an item I'm making, and finding one that does the specific thing I need proved hard, so I thought I could make it.  I'm making an item that has lights that I want to be able to turn a blinking effect on and off.  By lights, I don't mean actual lit prims, but the mesh item has a certain face that when a texture I've made is set and animated using SetTextureAnim, it appears to blink the lights.

I have no issue with the blinking lights without an on and off function.  I've used a simple SetTextureAnim call in the past with no issue whatsoever.  It's when I want to add the on,off function plus it calling a new texture to act as tho the lights are no longer blinking but still on.  Here's a gyazo of what I want to achieve through a touch on/off script. - https://gyazo.com/7c0f4e0c7052089924199d9ac4b5b2ee

So, it should be simple enough, but the things I've tried aren't working.  If possible, I'd like to be able to use UUIDs instead of putting the textures into the mesh's inventory.  What I tried to do and thought would work, didn't work, and I will paste below.  Any help would be appreciated.  I basically mashed the information I could find together, but obviously I either didn't use the correct type of functions, or I just don't understand how to put it all together and make it work.  Thank you in advance.

integer textureIsBeingAnimated;

string texture1 = "89811b99-fc0e-ced7-53b7-3a925b3f46d5";
string texture2 = "3b126c86-079c-7856-d48d-ef4b358bf785";
 
default
{
    touch_start(integer num_detected)
    {
        if (textureIsBeingAnimated)
            llSetTexture(texture1,1);
                llSetTextureAnim(ANIM_ON | SMOOTH | LOOP, 1,1,1,1.0, 1,1.0);
        else
            llSetTexture(texture2,1);
                llSetTextureAnim(ANIM_ON | SMOOTH | LOOP, 1,1,1,1.0, 1,0.0);
 

        textureIsBeingAnimated = !textureIsBeingAnimated;
    }
}

 

Edited by RefugeStore
Link to comment
Share on other sites

That's because in both if tests, you have omitted the {curly brackets}.   You can get away with that if you are doing only ONE thing after you write the if, but it's not smart.  Put brackets around everything in a test's scope to be sure that it's done.    As it is, your else is floating, leaving the compiler to ask "Else what?".

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

Argh!  Rolig got there just before me!

I think part of your problem is that you're not using braces properly in your if ... else statements.

If you don't use braces, then the script sees the if condition as applying only to the first line following the " if".  That's causing logic errors in your script, quite apart from the compiler not knowing what the "else" is doing.

Try

integer textureIsBeingAnimated;

string texture1 = "89811b99-fc0e-ced7-53b7-3a925b3f46d5";
string texture2 = "3b126c86-079c-7856-d48d-ef4b358bf785";

default
{
	touch_start(integer num_detected){

		if (textureIsBeingAnimated){
			llSetTexture(texture1,1);
			llSetTextureAnim(ANIM_ON | SMOOTH | LOOP, 1,1,1,1.0, 1,1.0);
		}
		else{
			llSetTexture(texture2,1);
			llSetTextureAnim(FALSE | SMOOTH | LOOP, 1,1,1,1.0, 1,0.0);
		}


		textureIsBeingAnimated = !textureIsBeingAnimated;
	}
}

 

Edited by Innula Zenovka
  • Like 1
  • Thanks 1
Link to comment
Share on other sites

Thank you guys!  I didn't realize I needed even more braces for it to work obviously.  Scripting sure does have a lot of rules to remember!  So confusing.

The suggestions worked perfectly though, and the FALSE call on the SetTextureAnim was much needed as well, so every comment here was very helpful.  I can't thank you guys enough!

Link to comment
Share on other sites

40 minutes ago, RefugeStore said:

Scripting sure does have a lot of rules to remember!

True, but the basic rule is to use logic.  In any programming/scripting language (and in human languages too, for that matter), we have to put boundaries around things that we want to have considered as a group.  It's the only way to tell where the group begins and ends.  So, in LSL we use {curly brackets} to place limits on the scope of interest .. whether the scope is the set of statements that are to be executed if some test succeeds or while it's ongoing, or the set of actions that are to be considered within a single event, or the set of events that comprise a state.  Other scripting languages have similar methods.  And in most written human languages, we define scopes with punctuation and capitalization.  In spoken languages, we use pauses and changes of tonal level.  In all of these settings, we can occasionally ignore the markers that define the scope if the scope is really small or really obvious, but it's a bad habit to get into.  That's why English teachers make such a big deal about run-on sentences. 9_9

Edited by Rolig Loon
  • Like 1
Link to comment
Share on other sites

2 hours ago, RefugeStore said:

 I didn't realize I needed even more braces for it to work obviously.  Scripting sure does have a lot of rules to remember!  So confusing.

This is why I tell people always to use braces in conditional statements, even when they're not necessary,  and why I always use them myself even when I know I don't need them.   You will never go wrong using braces this way, and you don't have to worry about remembering any rules other than "if you want this to happen after an if statement, always enclose it in braces".

Quite apart from anything else, it makes life so much simpler when you're tired and trying to debug a script by adding llOwnerSay statements to see where things are going wrong.   

if(x == y)
	llSetColor(<1.0,0.0,0.0>,ALL_SIDES);
	llOwnerSay("x == y");
	
and 

(if x == y){
	llSetColor(<1.0,0.0,0.0>,ALL_SIDES);
	llOwnerSay("x == y");
	}

behave very differently, and the first example is likely to have you scratching your head and saying "Why is the bloody thing not turning red when it thinks x == y, for heaven's sake?".

Trust me on this -- I learned it the hard way.

Edited by Innula Zenovka
Link to comment
Share on other sites

Always use braces. Notice, below could be made without braces.

if (bOn)
{
   llOwnerSay( "You are clever");
}
else
{
   llOwnerSay( "You are ehmm not so clever");
}

This safes your from potential logic program errors, which are the hardest to find as the program will compile and run - but does not do, what is intended. Further, the source code is easier to read and understand - important when you want to change something long time after it was original written.

 

  • Like 1
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 2408 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...