Jump to content

Script Practice


NikosTheWizard
 Share

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

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

Recommended Posts

Greetings! I'm a rather new SL Player and wanting to, well make Lindens, i decided to take on scripting! I have very little experience with scripting laungages, but i wanna guess that so far i've managed to understand how LSL works. My request to you, the community. I want some ideas, random ones, of a script. Not very complex nor very easy, i wanna see if i can make them happen.
Thank ya :)

Link to comment
Share on other sites

The universe is full of ideas.  I'm sure that your head is too.  The trick is to find a few that are comfortably simple, so you can practice.  I suggest perhaps starting with some of the simpler examples in the LSL wiki function pages.  Those are all guaranteed to work, so the learning challenge is to fiddle with them to make them do something a bit different.  Or maybe to write a script that does the same thing but in a different way. 

Link to comment
Share on other sites

Have you already read up on the basics of LSL? Do you know what types, global and local variables, states, and events are?
You should read up on those before you try to script, otherwise you'll be in an even bigger world of confusion. If you have though..

A "light" that you can turn on/off with a single touch
Learning how to toggle things is very useful in a very wide variety of ways.
It doesn't have to be actual light, you could just use llOwnerSay to say either 1/0, or on/off.

A cube that changes its color randomly (touch or timer)
It'll teach you a little bit about vectors, random values, and primitive parameters.

A link set where each prim changes their color randomly -- different color for each prim
This builds on the previous task by needing a loop and having to figure out a proper structure for your code.

An object that repeats what is said in local chat.
llListen is something very commonly used in scripts as well. Knowing how to use it is essential.

An object that reads a notecard and says each line in chat.
This can seem very complicated at first, and it's fine to skip, but notecards enable you to process a lot of information and since script memory is reset with the script, notecards can be used to keep things persistently in memory -- although scripts can't write into a notecard.

Edited by Wulfie Reanimator
  • Like 2
Link to comment
Share on other sites

Wulfie, thanks a lot for your suggestions, i did try them all. So i managed to get them all rather easily, and i did learn about the "listen" event, which by the way is AMAZING, thx!
One question though, the one i didn't manage to do, nor find a sollution is to change the color of linked prims!
I was able to change the main prim (root i believe its called) and the 2nd prim (the child) but if i wanted to add a 3rd child, i was not able to change the 2nd and 3rd's color independantly from one another.

 

Link to comment
Share on other sites

Few more useful things, a little more complicated:

A HUD with 3 buttons on it -- each button should send a different message on a non-zero channel
Then make an object that is listening for the messages from your HUD, and do something based on them.

Many things come with HUDs to control them, knowing how to make one is about as essential as understanding llListen.

A cube that follows you around by floating above your avatar's head
Bonus points if you can tell the cube which avatar to follow via chat commands.

This'll teach you to search for avatars and get information about other objects in general, and you'll have to keep position offsets in mind or you'll end up pushing the avatar.

Item giver/vendor
Put any items you want (like colored prims) into an object, then use a script to give one (any) of the items to anyone who touches the object.
As a bonus task you could let the user select which item they want, without having to look into the object.

  • Like 1
Link to comment
Share on other sites

7 hours ago, Ivanova Shostakovich said:

and then jump suddenly into the air.

... and then spin around and throw out a cloud of sparkly bling particles.  Oh, yes, and make a sound. 

Well, heck, once you start down the road, you might as well keep going. xD

  • Like 1
Link to comment
Share on other sites

2 hours ago, Rolig Loon said:

Well, heck, once you start down the road, you might as well keep going.

OK, too much all at once.  Here's a script for the hopping prim.  Figure out how to write a script for the triggering prim.  It must (1) generate a random color, (2) apply the color to itself, (3) send the color information to the hopping prim.

vector vHere;   // Initial position

Poof() 
{
   vector   START_SCALE = < 0.1,0.1,0.1 >;
    vector     END_SCALE = <0.1,0.1,0.1>; 
    vector   START_COLOR = < 1,1,1 > ;
    vector     END_COLOR = < 1,1,1 >;
    float   START_GLOW = 0.05; 
    float   END_GLOW = 0.03;
    float    START_ALPHA = 0.8; 
    float      END_ALPHA = 0.3;
    integer INTERP_COLOR = TRUE;
    integer INTERP_SCALE = TRUE; 
    integer     EMISSIVE = TRUE;
    string       TEXTURE = "e98a2df3-428c-fa0e-ebce-643a737b60fe"; 
    
    float     AGE = 4.0; 
    float    RATE = .1; 
    integer COUNT = 40;    
    float    LIFE = 0.0; 
    
    integer   PATTERN = PSYS_SRC_PATTERN_EXPLODE; 
    float      RADIUS = 0; 
    float ANGLE_BEGIN = .1; 
    float   ANGLE_END = .5; 
    vector      OMEGA = < 0.00, 0.00, 0.00 >; 
    
    integer      FOLLOW_SRC = TRUE; 
    integer FOLLOW_VELOCITY = FALSE;
    integer            WIND = FALSE; 
    integer          BOUNCE = FALSE; 
    float         SPEED_MIN = 0.1;
    float         SPEED_MAX = 0.5; 
    vector            ACCEL = < 0.00, 0.00, 0.0 >; 
    integer      TARGET_POS = FALSE; 
    key              TARGET = llGetKey(); 
    
    list particle_parameters = [
            PSYS_PART_FLAGS,( 
                ( EMISSIVE * PSYS_PART_EMISSIVE_MASK ) | 
                ( BOUNCE * PSYS_PART_BOUNCE_MASK ) | 
                ( INTERP_COLOR * PSYS_PART_INTERP_COLOR_MASK ) | 
                ( INTERP_SCALE * PSYS_PART_INTERP_SCALE_MASK ) | 
                ( WIND * PSYS_PART_WIND_MASK ) | 
                ( FOLLOW_SRC * PSYS_PART_FOLLOW_SRC_MASK ) | 
                ( FOLLOW_VELOCITY * PSYS_PART_FOLLOW_VELOCITY_MASK ) | 
                ( TARGET_POS * PSYS_PART_TARGET_POS_MASK ) ),
            PSYS_PART_START_GLOW,0.03,
            PSYS_PART_END_GLOW,0.02,
            PSYS_PART_START_COLOR, START_COLOR,
            PSYS_PART_END_COLOR, END_COLOR,
            PSYS_PART_START_GLOW,START_GLOW,
            PSYS_PART_END_GLOW, END_GLOW,
            PSYS_PART_START_ALPHA, START_ALPHA,
            PSYS_PART_END_ALPHA, END_ALPHA,
            PSYS_PART_START_SCALE, START_SCALE,
            PSYS_PART_END_SCALE, END_SCALE, 
            PSYS_SRC_PATTERN, PATTERN,
            PSYS_SRC_BURST_PART_COUNT, COUNT,
            PSYS_SRC_BURST_RATE, RATE,
            PSYS_PART_MAX_AGE, AGE,
            PSYS_SRC_ACCEL, ACCEL,
            PSYS_SRC_BURST_RADIUS, RADIUS,
            PSYS_SRC_BURST_SPEED_MIN, SPEED_MIN,
            PSYS_SRC_BURST_SPEED_MAX, SPEED_MAX,
            PSYS_SRC_TARGET_KEY, TARGET,
            PSYS_SRC_ANGLE_BEGIN, ANGLE_BEGIN, 
            PSYS_SRC_ANGLE_END, ANGLE_END,
            PSYS_SRC_OMEGA, OMEGA,
            PSYS_SRC_MAX_AGE, LIFE,
            PSYS_SRC_TEXTURE, TEXTURE
        ];
    llTriggerSound("4409e77c-7fc0-2ee6-08e8-550ebd84b11f",1.0);    
    llParticleSystem( particle_parameters );  
    
}  

default
{
    state_entry()
    {
        vHere = llGetPos();     // Save "home" position
        llListen(-25118759,"","","");   // Listen for the trigger signal
    }
    
    on_rez(integer startup)
    {
        llResetScript();    // Initialize
    }

    listen(integer channel, string name, key id, string message)
    {
        llSetColor((vector)message,ALL_SIDES);          // Match color to the trigger
        llSetStatus(STATUS_PHYSICS,TRUE);               // Become physical
        llSetBuoyancy(0.9);                             // Make heavier than air
        llApplyImpulse(<0.0,0.0,2.0>,FALSE);            // Hop up
        llApplyRotationalImpulse(<0.0,0.0,1.0>,FALSE);  // Spin
        Poof();                                         // Start particles
    }
    
    collision_start(integer num)
    {
        llParticleSystem([]);                           // Turn off particles
        llSetStatus(STATUS_PHYSICS,FALSE);              // Become non-physical
        llSetRot(ZERO_ROTATION);                        // Set upright, facing east
        llSetRegionPos(vHere);                          // Go "home"
    }
}

 

  • Like 1
Link to comment
Share on other sites

11 hours ago, Wulfie Reanimator said:

Few more useful things, a little more complicated:

A HUD with 3 buttons on it -- each button should send a different message on a non-zero channel
Then make an object that is listening for the messages from your HUD, and do something based on them.

Many things come with HUDs to control them, knowing how to make one is about as essential as understanding llListen.

A cube that follows you around by floating above your avatar's head
Bonus points if you can tell the cube which avatar to follow via chat commands.

This'll teach you to search for avatars and get information about other objects in general, and you'll have to keep position offsets in mind or you'll end up pushing the avatar.

Item giver/vendor
Put any items you want (like colored prims) into an object, then use a script to give one (any) of the items to anyone who touches the object.
As a bonus task you could let the user select which item they want, without having to look into the object.

OOOH! That was a good one! The hud was done rather easily, and i now undertstand fully how HUDs work!
As for the second, it was tricky, took me a while, BUT! I did manage to use the GetObjectDetails and learnt how to utilize lists :)
Working on the 3rd one. Also thanks again everyone :), The one with the 2 cubes, i have tried it before, but not with that complexity xD

Link to comment
Share on other sites

   I thought Nikos wanted to learn for himself. But Rolig, you thought it sounded so fun, you couldn't resist. :)

   Nikos, you can use your imagination, as Rolig suggested. You can find great fun in imagining an idea or a scene and seeing if you can realize it. But be warned, hours can pass unnoticed.

Edited by Ivanova Shostakovich
  • Like 1
Link to comment
Share on other sites

Create a script that measures the distance between the host prim (the default cube is fine) and you. Make that measurement and set the prim height twice a second, using a timer. Make sure the prim is phantom. Walk towards/away from it to make sure it's working, then duplicate it into a 10 x10 grid with one meter spacing. Now walk through your field of prims. Don't leave this laying, it's a resource hog. This is a low effort high reward experiment.

Edited by Madelaine McMasters
Link to comment
Share on other sites

Wow i guess this time i really got stuck, yet seems so simple..
So if i understood corectly, i want to use the distance between me and a cube to increase it's size
I wrote the script bellow, but it comes up with a long ass error...
P.S. the "self" variable, i tried to use llGetPos and came up with the same error...

What is wrong?

key id = llGetOwner;
list pos;
vector player;

default
{
    state_entry()
    {
         
         pos = llGetObjectDetails(id, ([OBJECT_POS]));
         player = llList2Vector(pos, 0);
        llSetTimerEvent(0.2);
    }
    
    timer()
    {
        vector self = <31.0,203.0,33.0>;
         player = llList2Vector(pos, 0);
         float dis = llVecDist(self, player); 
         llSetScale(<1, 1, dis>);
    }
}

 

Link to comment
Share on other sites

And third,you are determining the owner's position once, in state_entry.  Since you never determine it again, the prim will stay the same size each time the timer fires.

In fact, you do not need any global declarations at all.  Everything can be defined in the timer event.

Now, two logic questions:  (1) Why are you defining self by a hardcoded vector?  Is there a more generic option?  (2) Can you figure out why half of the prim will be buried in the ground, and how to compensate for that?

  • Like 1
Link to comment
Share on other sites

Alright, lets gets things clear, 1) Yes Holy *****, its llGetOwner(); with () =_=' that might be the problem
and 2) I am aware of the issues it will have. For starters i wrote the "self" and a hand written vector to theorize on what the error was, but surely i know there is an easier way.
As for the height, i think i have an idea on how to make it taller above the ground and not bellow, i'll edit this post for the results, thx :).

 

EDIT: Success! I set everything on the timer event, now the llGetOwner works and i set its position to its original position but the z(height) is the original height + distance/2 so the bottom surface is always on the ground! Perfect :D Thanks again.

Edited by NikosTheWizard
Succcess
  • Like 2
Link to comment
Share on other sites

Write a script that will distinguish between a single click (touch) on an object, a double click, and a long click.

Write a script for a calculator or keypad of some sort. For the output display you might use simple chat, floating text, or a series of linked prims. If you go for the linked prims, use only a single texture for all the digits and characters. Or, find or make a mesh panel with, say, eight faces, side by side, or find or make one of those tortured prims that present several similar faces to the viewer (hint: Xyzzy Text). For the body and buttons use only a single prim and a single texture (hint: llDetectedTouchUV). Add a key click sound.

Send an email from one object to another, or from an in-world object to your own email address.

Make a pair of objects act as an HTTP server and a client.

Edited by KT Kingsley
Link to comment
Share on other sites

I've tried the double click, single click (even found an example that someone made), its... wierd but interesting.
As for the calculator, i know how to make one but i'll leave it for last, for now the HTTP one seems interesting, i'm having some troubl figuring it, but all in due time. Thx :)

Link to comment
Share on other sites

53 minutes ago, NikosTheWizard said:

I've tried the double click, single click (even found an example that someone made)

You might also take a look at the example I posted in the llGetTime entry in the wiki a couple of years ago. There are probably several other approaches loose in the world.  Sensing a slow click/release is another common variation.

Link to comment
Share on other sites

5 minutes ago, Rolig Loon said:

You might also take a look at the example I posted in the llGetTime entry in the wiki a couple of years ago. There are probably several other approaches loose in the world.  Sensing a slow click/release is another common variation.

Oh, thats neat! Question though, the gHoldTime float, has no starting value, yet its used before its set. Is there like a default float value it uses?

Link to comment
Share on other sites

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