Jump to content

Rez random object On Touch (is that even possible?)


Six Igaly
 Share

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

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

Recommended Posts

Somehow I can't find what I need, as mentioned above, a script that will rez a random object 'On Touch'. I have similar scripts but they work on a timer. So finally, after searching a while, I've decided to try to create my own. I'm not a scripter and never will be, but through the years I've learned my share and I became pretty good in messing existing scripts up. :matte-motes-tongue:

So I was proud on myself when the script did not show any error when I saved it! And it works! But not as I want it. I placed 3 objects in a prim and the script. It does rez on touch, for sure. But! LOL, it only rezzez the 2nd object. I double checked by changing the object names a couple of times. This is the script (/me ducks):

default
{
touch_start(integer rand)
{


integer number = llGetInventoryNumber(INVENTORY_OBJECT);
integer choice = (integer)rand;
if (choice == number)
choice = 0;

string name = llGetInventoryName(INVENTORY_OBJECT, choice);

if (name != "")
llRezObject(name, llGetPos() + < 0, 0, 0 >, ZERO_VECTOR,
ZERO_ROTATION, 0);
}
}

I'm curious about how bad it really is LOL.

Link to comment
Share on other sites

What you do is just to declare interger number, compare them for no reason.  The "choice" will be always 1. That why it is the 2nd item in your list of the content. But you need a command to make a random number.  The LSL wiki could have helped your there:)

http://wiki.secondlife.com/wiki/LSL_Portal in your case:

http://wiki.secondlife.com/wiki/LlFrand


What you want is this:

default
{
    touch_start(integer rand) // the interger doesn't matter at all, you can call it whatever you want, it's not used here
    {
        float number = (float) llFrand(llGetInventoryNumber(INVENTORY_OBJECT)); // determine the amount of the content and make a random float
        string name = llGetInventoryName(INVENTORY_OBJECT,(integer) number); //getting the name. the float number becomes integer for that
        llRezObject(name, llGetPos() + < 0, 0, 1 >, ZERO_VECTOR,ZERO_ROTATION, 0); //rezz the object, I just let it rezz 1m above the object
    }
}

 

The best is really to understand what you are doing, you could also cause some lag with some scripts if you only fiddle around till it does what you want.


(I edited it now to what I want, I'm a bit of the track today;))

Link to comment
Share on other sites

Or, since you will only be using the random number one time and do not need to store it, you could write the whole thing more simply as

default{    touch_start(integer num)    {        llGiveInventory(llDetectedKey(0),llGetInventoryName(INVENTORY_OBJECT,            (integer)llFrand(llGetInventoryNumber(INVENTORY_OBJECT))));    }}

 

 

  • Like 1
Link to comment
Share on other sites


The best is really to understand what you are doing, you could also cause some lag with some scripts if you only fiddle around till it does what you want.

That is the point lol, I don't really understand, just a tiny bit, except for the lag, totally understand that. That is why I usually buy my scripts from actual scripters. :matte-motes-big-grin:

I tried the wiki's too, but because I did not exactly knew what to look for it was hard to find the right answer. 

Thank you for your input sven, I will not only try this out, I will also try to get to understand it better.

 

Link to comment
Share on other sites

Sorry.  :smileyembarrassed:  My point was that you don't need to carry the extra baggage of variables that you will not be reusing, regardless of what you are doing with them.  To be consistent with your example, I should have written

default{    touch_start(integer num)    {        llRezAtRoot(llGetInventoryName(INVENTORY_OBJECT,            (integer)llFrand(llGetInventoryNumber(INVENTORY_OBJECT))),            llGetPos() + <0.0,0.0,1.0>,ZERO_VECTOR,ZERO_ROTATION,0);    }}

 So much for typing before breakfast.

 

  • Like 2
Link to comment
Share on other sites

No sorry needed! I mean, what for? It just illustrates the importance of having breakfast :matte-motes-wink:

Besides that, it was good for my SLego to notice it hehee. I also get your point Rolig, I think. I will compare the various scripts as I have them. That will give me some more understanding (eventually).

Thanks again..

Link to comment
Share on other sites

  • 2 months later...
You are about to reply to a thread that has been inactive for 3636 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...