Jump to content

Multi requirements when it comes to if and else if


SparkyDaSparks
 Share

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

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

Recommended Posts

I'm working on a script but seem to be running into issues when it comes to having multiple requirements without having a specific order to which they are completed or confirmed as met to getting the script to work. For example, I am trying to design a breakable window, but I don't want anything under "x" amount of velocity to be allowed to damage the hit points. 

(this is only part of the script)

collision(integer num)

{

if(vel < llVecMag(llDetectedVel(0)) && hp > 0)

{

llSetTexture("Broken",ALL_SIDES);

}

}

If any of you can help I would greatly appreciate it, if you need more to help I'll be happy to give it and if you see that I'm doing anything wrong PLEASE let me know.. I'm getting frustrated with it.

Edited by SparkyDaSparks
Link to comment
Share on other sites

This is the fun part of scripting, the logic.  What you seem to be trying to say is "If you get hit by something going faster than X speed, and if hp (whatever that is) is positive, look broken."

So write that:

if ( llVecMag( llDetectedVel(0) ) > SpeedX && hp > 0 )
{
    // break the window
}

Just be sure that SpeedX and hp are both defined within the scope of your event, or are global.  Oh, and don't use a collision event.  Use collision_start.

Link to comment
Share on other sites

8 minutes ago, Rolig Loon said:

This is the fun part of scripting, the logic.  What you seem to be trying to say is "If you get hit by something going faster than X speed, and if hp (whatever that is) is positive, look broken."

So write that:


if ( llVecMag( llDetectedVel(0) ) > SpeedX && hp > 0 )
{
    // break the window
}

Just be sure that SpeedX and hp are both defined within the scope of your event, or are global.  Oh, and don't use a collision event.  Use collision_start.

Well I'm trying to allow for multiple hits before actually breaking. Growing up I shot out old windows with a .22 that we got from demo jobs and I know that a projectile unless large enough will not completely destroy a window with one shot, which is what I'm trying to achieve; I have the hit points  set right but the second I add a velocity regulation everything seems to go crazy, will this cover that?

Edited by SparkyDaSparks
Link to comment
Share on other sites

That's fine, but each collision is a separate occurrence, so you want to have your action triggered by that specific instance.  Hence a collision_start event.  Otherwise, you are writing an event that is only valid as long as a collision is continuing, which is a different matter.

So, you want to count how many time the window gets hit and only break it if it has been hit more than four or five times by things going at least SpeedX m/sec?  Write that:

collision_start(integer num)
{
     if (llVecMag( llDetectedVel(0) ) > SpeedX )
     {
         ++hp;
     }
     if ( hp > 5 )
     {
          //Break the window
     }
}

Then be sure to make hp a global integer so that the script keeps track of it as it increments each time a collision meeting your speed requirement  is detected.

  • Like 1
Link to comment
Share on other sites

You're welcome.  Good luck.  I think you'll find that it often helps to think through logic in terms of what you want to occur if a trigger does happen than if you start focusing on what happens if it doesn't.  Also, personally, I find that it helps to say the condition out loud as an English sentence, as if I were trying to explain it to my non-scripting grandmother (who has not been around since 1952, but that's a different matter).  Nice, clear, straightforward words.  Somehow, hearing myself say it helps.

Link to comment
Share on other sites

So I have it set to 100 hit points and for each shot to reduce it by one(was set to 10hp and 1 hp per hit but it started jumping straight down to 0 or -1 so I increased it 10x) It still can only take one hit for some reason.

 

*EDIT* Never mind I think I fixed it. Thanks again for your help

 

 

Edited by SparkyDaSparks
Link to comment
Share on other sites

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

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...