Jump to content

my balls aren't working correctly


Recommended Posts

I tried to make two scripts that measured the distance between the two and then announced it local chat after you touched it. I did try global variables.  Now I get Red Ball not found in inventory despite the scripts being named properly.

Green Ball

// Green Ball Script

// Constants
integer CHANNEL = -12345; // Channel for communication
string REQUEST_MESSAGE = "MeasureDistance"; // Message sent to red ball to request distance measurement

// Variables
vector redBallPos; // Position of the red ball

default
{
    state_entry()
    {
        // Set hover text
        llSetText("Touch me to measure the distance to the red ball", <0, 1, 0>, 1.0);
    }

    touch_start(integer total_number)
    {
        // Find red ball
        key redBall = llGetInventoryKey("RedBall");
        if(redBall != NULL_KEY)
        {
            // Request distance measurement from red ball
            llRegionSayTo(redBall, CHANNEL, REQUEST_MESSAGE);
        }
        else
        {
            // Announce error if red ball not found
            llOwnerSay("Error: Red ball not found in inventory.");
        }
    }

    // Listen for responses from the red ball
    listen(integer channel, string name, key id, string message)
    {
        // Parse distance from message
        integer distance;
        if (llStringLength(message) > 0)
        {
            distance = llRound((float)message);
            // Announce distance in nearby chat
            llSay(0, "Distance to red ball: " + (string)distance + " meters.");
        }
        else
        {
            // Announce error if message is empty
            llOwnerSay("Error: Received empty message from red ball.");
        }
    }
}

 Then the second ball is
 

// Red Ball Script

// Constants
integer CHANNEL = -12345; // Channel for communication

// Variables
vector greenBallPos; // Position of the green ball

default
{
    state_entry()
    {
        // Initialize listen event
        llListen(CHANNEL, "", NULL_KEY, "");
    }

    // Listen for messages from green ball
    listen(integer channel, string name, key id, string message)
    {
        // Get the position of the green ball
        greenBallPos = llGetPos();

        // Calculate distance
        integer distance = llRound(llVecDist(greenBallPos, llGetPos()));

        // Send distance to green ball
        llRegionSay(channel, (string)distance);
    }
}

I don't know why my balls aren't working.

  • Haha 2
Link to comment
Share on other sites

Seriously, though .... An object in inventory does not have a UUID.  UUID is assigned when an object is rezzed, and each new rezzed object has a new, unique UUID.  Therefore, a sequence like this

        // Find red ball
        key redBall = llGetInventoryKey("RedBall");

isn't going to work.  If you want to find the red ball, you have to get the UUID of the rezzed instance.  The easiest way is to use a sensor, but of course using a sensor will automatically give you the ball's position too, so you don't need the rest of the script except to subtract the detected position from your own.

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

3 minutes ago, HorizontalEight said:

We see all the radars that pick up plugins. Not sure how they do it.

Well, as I said, the easy way is to just do a sensor sweep that looks for the object by name.  There are limitations, of course.  The object has to be within sensor range and a sensor can only detect up to 16 items at a time, and it won't detect attachments. 

Link to comment
Share on other sites

14 minutes ago, Love Zhaoying said:

IIRC, only the 16 closest items which meet the sensor criteria, is that still right (if it ever was)?

That's not the way I interpret the wiki: 

  • Only 16 objects will be scanned each time.

Frankly, though, I don't remember.  The question is whether it only scans for things with a specific name and stops counting when it gets to 16 or whether it scans for 16 things and asks what their names are.  The way to find out is to do a quick test in world, but I'm too lazy/busy/grumpy to do that at the moment.

  • Thanks 1
Link to comment
Share on other sites

23 minutes ago, Love Zhaoying said:

IIRC, only the 16 closest items which meet the sensor criteria, is that still right (if it ever was)?

Sensors do give you the results ordered by distance, so it would stand to reason so, but I don't know if it's reliable.

  • Thanks 1
Link to comment
Share on other sites

7 minutes ago, Rolig Loon said:

That's not the way I interpret the wiki: 

  • Only 16 objects will be scanned each time.

Frankly, though, I don't remember.  The question is whether it only scans for things with a specific name and stops counting when it gets to 16 or whether it scans for 16 things and asks what their names are.  The way to find out is to do a quick test in world, but I'm too lazy/busy/grumpy to do that at the moment.

One of my points of reference is, ROFL ball places where people pile closest to the ball because only those 16 closest people's name get called. The fix of course, would be to have multiple sensors spread out, and swap between people detected by each sensor (not just a single central one).

 

  • Like 1
Link to comment
Share on other sites

This is for like small pve combat so I think the 16 items will be not enough. XD
I have seen this done in objects in the game. They just did it when you dropped the items from your inventory.
It is frustrating as I can't find them sold or mentioned. 

Link to comment
Share on other sites

6 hours ago, HorizontalEight said:

This is for like small pve combat so I think the 16 items will be not enough. XD
I have seen this done in objects in the game. They just did it when you dropped the items from your inventory.
It is frustrating as I can't find them sold or mentioned. 

One think you might consider to is on the on_rez event to have the object announce itself on a/the control channel with it's UUID key. The greenBall can then store this for later use.  You could do it both ways even, if the redBall is already in world, when the greenBall is rezzed it can broadcast out "hey I'm here, redBall report in", and capture any replies.   Expand from there for however many objects you need to have communicating back and forth.

Link to comment
Share on other sites

9 hours ago, Love Zhaoying said:

Have you tried making your balls bigger?

 

 

9 hours ago, Kathlen Onyx said:

I like big balls and I cannot lie...whoops wrong song.

Just "put your balls to the wall, man."

<ponders> whoops, still the wrong song....

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

I think i will just have the item say to the avatar how far you are from them.
What i have got the balls to do is simple. I touch one and it sends the second ball it's object details. Then the second ball announces it's  details and the first ball's details.
I am working on getting the ball to turn the string to a vector then do the math and round it to the nearest meter then say it.

Green Ball script named 'transmitter'
 

// Transmitter.lsl

// Channel for communication
integer CHANNEL = 42;

default
{
    touch_start(integer total_number)
    {
        // Get details of the transmitter object
        string objectName = llGetObjectName();
        key objectKey = llGetKey();
        vector objectPosition = llGetPos();
        rotation objectRotation = llGetRot();
        
        // Convert the details into a string
        string details = "Object Name: " + objectName + "\n"
                        + "Object Key: " + (string)objectKey + "\n"
                        + "Object Position: " + (string)objectPosition + "\n"
                        + "Object Rotation: " + (string)objectRotation;
        
        // Send the details to the receiver
        llRegionSay(CHANNEL, details);
    }
}


Red ball labeled - receiver

 

// Receiver.lsl

// Channel for communication
integer CHANNEL = 42;

default
{
    state_entry()
    {
        // Listen for messages on the channel
        llListen(CHANNEL, "", NULL_KEY, "");
    }
    
    listen(integer channel, string name, key id, string message)
    {
        // Get details of the receiver object
        string objectName = llGetObjectName();
        key objectKey = llGetKey();
        vector objectPosition = llGetPos();
        rotation objectRotation = llGetRot();
        
        // Convert the details into a string
        string details = "Receiver Object Name: " + objectName + "\n"
                        + "Receiver Object Key: " + (string)objectKey + "\n"
                        + "Receiver Object Position: " + (string)objectPosition + "\n"
                        + "Receiver Object Rotation: " + (string)objectRotation + "\n"
                        + "Transmitter Object Details:\n" + message;
        
        // Say both the details in chat
        llSay(0, details);
    }
}


 

Link to comment
Share on other sites

16 hours ago, HorizontalEight said:

I think i will just have the item say to the avatar how far you are from them.

touch_start(integer n)
{   key toucher = llDetectedKey(0);
    vector posToucher = llList2Vector(llGetObjectDetails(toucher,[OBJECT_POS]),0);
    integer distance = llRound( llVecMag(posToucher-llGetPos()) );
    
    llRegionSayTo(toucher,0,(string)distance);
}

 

Edited by Quistess Alpha
  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...
On 4/18/2024 at 11:52 AM, Quistess Alpha said:
touch_start(integer n)
{   key toucher = llDetectedKey(0);
    vector posToucher = llList2Vector(llGetObjectDetails(toucher,[OBJECT_POS]),0);
    integer distance = llRound( llVecMag(posToucher-llGetPos()) );
    
    llRegionSayTo(toucher,0,(string)distance);
}

 

I ended up going with that.

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

Question was already solved but it is boring friyay so I wrote my own solution:

Sender:

// Some channel to send messages between objects
integer CHANNEL = 80085;

default
{
    state_entry()
    {
        llSetText( "Please, touch me!", <1.0, 1.0, 0.0>, 1.0 );
    }

    touch_start(integer total_number)
    {
        llSay( 0, llDetectedName( 0 ) + " touched me. Sending message to channel " + (string) CHANNEL );
        // Message could be anything... but let's be bit fancy and send message with detecked key
        llRegionSay( CHANNEL,  "TOUCH|" + (string) llDetectedKey( 0 ) );        
    }
}

and receiver:

// Some channel to send messages between objects
integer CHANNEL = 80085;

default
{
    state_entry()
    {
        llSay( 0, "Listening channel: " + (string) CHANNEL );
        llListen( CHANNEL, "", NULL_KEY, "" );
    }
    
    listen(integer channel, string name, key id, string message)
    {
        // Getting senders information
        list details = llGetObjectDetails( id, [ OBJECT_POS ] );        
        vector pos = llList2Vector( details, 0 );        
        float distance = llVecDist( llGetPos(), pos );
        llSay( 0, "Distance to \"" + name + "\" is " + (string) distance + " m, position is " + (string) pos );
        
        // Being bit extra fancy with message - getting toucher's iD from message
        // Message should be TOUCH|<deterced key>
        list payload = llParseString2List( message, ["|"], [] );
        if( llList2String( payload, 0 ) != "TOUCH" )
        {
            // First part of message was not "TOUCH"
            llSay( 0, "Unknown message: " + message );
            return;
        }

        // Reusiong id and details variables - we can discard old values
        id = llList2Key( payload, 1 );
        if( id == "" )
        {
            llSay( 0, "Message didn't have toucher's id value." );
            return;
        }
        details = llGetObjectDetails( id, [ OBJECT_POS, OBJECT_GROUP_TAG, OBJECT_RENDER_WEIGHT, OBJECT_BODY_SHAPE_TYPE, OBJECT_SCRIPT_TIME, OBJECT_ACCOUNT_LEVEL ] );
        // Using viewer URI space to show link to agent - https://wiki.secondlife.com/wiki/Viewer_URI_Name_Space and other then dumping other information
        llSay( 0, name + " was touched by secondlife:///app/agent/" + (string)id + "/inspect\n" + 
            "\tPosition " + (string) llList2Vector( details, 0 ) + "\n" +
            "\tGroup tag \"" +  llList2String( details, 1 ) + "\"\n"+ 
            "\tRender weight " + (string) llList2Integer( details, 2 ) + "\n" +
            "\tBody shape " + (string) llList2Float( details, 3 ) + " (0.0 = female, 1.0 = male)\n" +
            "\tScript time " + (string) llList2Float( details, 4 ) + " ms\n" + 
            "\tAccount level " + (string) llList2Integer( details, 5 ) + " (0 = basic, 1 = premium, 5 = plus, 10 = premium plus)");
    }
}

 

Edited by Imaze Rhiano
  • Like 1
Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...