Jump to content

I am a newbie at scripting and need a script to make an object go up or down when it is clicked on.


Bedlam Ansome
 Share

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

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

Recommended Posts

I am a newbie at scripting and need a script to make an object go up or down when it is clicked on.

I have an object that I want to go up when it is down when it is clicked on, and vice versa down when the object is up.

I have no real experience of creating scripts, I can see the logic behind this movement, but I have no idea how to script it.

Can anyone help please?

Link to comment
Share on other sites

You have several options, depending on how far you want it to go up and down, how smoothly, how regularly, and (sometimes very importantly) what sort of object it is.

The simplest thing to do is use llSetRegionPos.  The first time it's called, set a position above the current one.  Then reverse the direction so that the next call makes the object go down.  Rinse and repeat.  It's basically a light switch that reverses a direction instead of changing the color of a light bulb.  You can write the whole script in eight lines (four of which are { curly brackets } ).

It becomes more complicated if the object is linked to something else, has to rise and fall very slowly, or has to keep oscillating on its own.

Link to comment
Share on other sites

In that case, you have a couple of choices.  

One choice is to use the touch_start event to trigger a timer that fires every 0.1 or 0.2 seconds until your object has reached its destination. Each time the timer event fires, move the object upward (or downward) a small amount.  The smaller your steps, the smoother the motion will appear, but the more steps it will need to take to get where it's going.  Increment a global integer in the timer event to keep track of how many steps it has taken, and to stop the timer when it reaches the goal.  Then change the direction and be ready for the next time someone touches your object.

The other choice is to use llKeyFramedMotion, which you can do with a single call in the touch_start event. It's a nice, clean method but it does have some limitations.  Your object must be non-physical, for example, it must have physics shape type CONVEX_HULL, and you have to move the entire thing (not just one link in a linkset).

Link to comment
Share on other sites

vector oldpos;integer raised;default{    state_entry()    { oldpos = llList2Vector(llGetLinkPrimitiveParams(LINK_THIS, [PRIM_POS_LOCAL]), 0);    }    touch_start(integer total_number)    {        raised = raised^1;      llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_POS_LOCAL, oldpos + <0, 0, 0.5*(float)raised>]);    }}

 this gets the position where the prim is rezzed and moves up and down from there. if you move the prim to place

it, just reset the script. you can use a link number instead of LINK_THIS to move a child prim.

the  raised = raised^1  part is a kind of toggle. (bitwise XOR )

 

Link to comment
Share on other sites

As Rolig suggests, llSetKeyframedMotion may be what you're looking for.    If you read the wiki article on llSetKeyframedMotion, you will the see the second example shows how to move an object up and down by 10 metres, but  you should be able to work out how to change the distance to 0.5.

Bear in mine that the snippet of code in the wiki needs to be part of a full script  -- it won't work on its own.   Since you say you are a complete beginner, you might want to take a look at some of the introductory tutorials in the wiki to get an idea of how to write simple scripts (and more complex ones, of course).

You will need to give a bit of thought to exactly how you want the object to behave.   Does it go up and down constantly or move either up or down and then stop?   If it starts and stops, what makes it move (do you have to touch it, or sit on it or give it a chat command or what?).

Link to comment
Share on other sites

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