Jump to content
SparkyDaSparks

Multi requirements when it comes to if and else if

Recommended Posts

Posted (edited)

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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites
Posted (edited)
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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Okay, Thank you so much!! I really appreciate the advice, I like to think I've got a good grip on lsl but every time I do I find another obstacle and I can't get over all of them without help. Thanks again

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites
Posted (edited)

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

Share this post


Link to post
Share on other sites

hp = hp - 1;

can be written as 

--hp;

They mean the same thing. If you want to keep counting until there's no hp left, then test 

if (hp == 0)
{
     // Break the window 
}

instead of testing the way I wrote it before.

  • Thanks 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...