Jump to content

What am I doing wrong?


xQUAKEx
 Share

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

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

Recommended Posts

Hello All,

I am the type or person that cuts up other scripts and mashes them together from the lack of scripting skills.

I have a current issue with this mod that I can'y figure out.

It is an easter egg money giver, for group members and the user needs to be within range.

However i can't squeeze a llDie() into it to kill the objece once the money is collected.

If any one would be so kind to help it would be greatly appreciated.

Here is what I have.

 

// Minimum Distance Touch

integer limit = 4; //in meters
key id;
integer amount = 1; // amount to give
default
{
    on_rez( integer param )
    {
        llResetScript();
    }
    
    state_entry()
    {
    llRequestPermissions(llGetOwner(), PERMISSION_DEBIT);
    }
    touch_start(integer total_number)
    {
        id = llDetectedKey(0);
        integer number = 0;
        vector mypos = llGetPos();
        vector yourpos = llList2Vector(llGetObjectDetails(llDetectedKey(0), [OBJECT_POS]), 0);
        if ((llAbs((integer)(yourpos.x-mypos.x)) > limit) || (llAbs((integer)(yourpos.y-mypos.y)) > limit) || (llAbs((integer)(yourpos.z-mypos.z)) > limit))
        {
            //avatar is too far away
            llInstantMessage(llDetectedKey(0), "You are too far away.  Move closer and touch again.");
        }
        else
        {
            if (llDetectedGroup(number))
            llGiveMoney(id, amount);
            else
            llSay(0, "Wrong active group!");
         }
    }
}

Link to comment
Share on other sites

You can replace:

  if ((llAbs((integer)(yourpos.x-mypos.x)) > limit) || (llAbs((integer)(yourpos.y-mypos.y)) > limit) || (llAbs((integer)(yourpos.z-mypos.z)) > limit))

by

if (llVecDist(mypos,yourpos)>(float)limit)

Now your problem : you want to kill the object once the money is given.

You should check the wiki about LSL syntax, then you see that you can group a couple of lines by enclosing them into {}

writing:

            if (llDetectedGroup(number))
            llGiveMoney(id, amount);
            else
            llSay(0, "Wrong active group!");

without using {} and not even indentation will bring noobs into trouble sooner or later

if (llDetectedGroup(number)){          llGiveMoney(id, amount);}else{          llSay(0, "Wrong active group!");}

this looks alot easier and you see now where to put the llDie()

if (llDetectedGroup(number)){          llGiveMoney(id, amount);          llDie();}else{          llSay(0, "Wrong active group!");}

If the llDie is faster than the money giving command the avatar gets no money :) (I don't know if that happens but expect everything in SL) try it out. If that happens you add a line with:   llSleep(1.0);    before the llDie

 

 

Link to comment
Share on other sites

I want to thank you so much for your help, Works perfectly!

I  have so many issues at times with opening and closing and then the elese statement sometimes throws me .. i know, such a noob.

Have a great day / night

Link to comment
Share on other sites

We were all noobs once and we're all still learning (I certainly am, anyway -- I've been writing LSL for 8 years now, and am still discovering new mistakes I can make).

Curly brackets (braces) following an if statement can be confusing.

	touch_start(integer total_number)	{		if(llDetectedKey(0)==llGetOwner())			llOwnerSay("You are my owner");	}

is the same as 

	touch_start(integer total_number)	{		if(llDetectedKey(0)==llGetOwner()){			llOwnerSay("You are my owner");		}	}

That is, the llOwnerSay will fire only if the toucher is the prim's owner.

However, if you then add a second line, 

	touch_start(integer total_number)	{		if(llDetectedKey(0)==llGetOwner())			llOwnerSay("You are my owner");			llSetColor(<1.0,0.0,0.0>,ALL_SIDES);			}

the prim will say "You are my owner" only if the owner touches it, but will then change colour no matter who the toucher is.

If you want to have the prim execute the two commands -- lllOwnerSay and llSetColor -- only if the toucher is the owner, then you have to use braces:

	touch_start(integer total_number)	{		if(llDetectedKey(0)==llGetOwner()){			llOwnerSay("You are my owner");			llSetColor(<1.0,0.0,0.0>,ALL_SIDES);		}			}

tl;dr: It's never wrong to use braces after an if statement.  

Sometimes not using them can give you unexpected results, particularly if (like me) your first reaction when a script doesn't work properly is to stick in lots of llOwnerSay statements to debug it.

Link to comment
Share on other sites

You can rarely go wrong by putting the scope of an if test in curly brackets, but you can easily go wrong by omitting them.  So the basic rule is ALWAYS use the curly brackets.  Then you'll never go wrong.  ( At least not with that problem. )

  • Like 1
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 2741 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...