Scripting question (again)

Post » Sat Feb 19, 2011 9:59 am

I have a script that makes an actor stagger when the PC gets to a certain distance from the player. But I have a problem. With the help of another forumer, I determined that that the call to play the animation is being set every frame.
I'm using GetCrosshairRef to determine the reference. Being that the call is being made every frame, the actor gets stuck and freezes, until the PC moves away from the actor and the actor is no longer being returned as a reference by GetCrossHair.

How can I make it so that the reference only plays it's animation once for, lets say, 2 seconds? How can I make it so that the reference doesn't freeze because of repeated calls to play the animation 60 times a second?

I tired a do once variable, but that didn't work. And if that didn't work, a timer won't work either.

Any ideas.
User avatar
ImmaTakeYour
 
Posts: 3383
Joined: Mon Sep 03, 2007 12:45 pm

Post » Sat Feb 19, 2011 11:38 am

Maybe you could try "rActor.IsAnimGroupPlaying Stagger" to check if it's already staggered.
User avatar
Suzy Santana
 
Posts: 3572
Joined: Fri Aug 10, 2007 12:02 am

Post » Sat Feb 19, 2011 2:34 am

(Double Response)

Will do. Thanks.
User avatar
Amber Ably
 
Posts: 3372
Joined: Wed Aug 29, 2007 4:39 pm

Post » Sat Feb 19, 2011 3:06 am

Nope. This is what I have:

ScriptName FnActorStaggerHandlerref rActorref rPlayerfloat fDistanceBegin Function {rActor, rPlayer}                Set rPlayer to Player.GetSelf        Set rActor to GetCrosshairRef        Set fDistance to rActor.GetDistance Player                If rActor.IsActor                If fDistance <= 100                        rActor.PlayGroup Stagger 1                        If rActor.IsAnimGroupPlaying Stagger                                Set rActor to Apple                        EndIf                EndIf        EndIfEnd




I still get the freeze until I move away from the actor.
User avatar
dell
 
Posts: 3452
Joined: Sat Mar 24, 2007 2:58 am

Post » Sat Feb 19, 2011 8:33 am

Of course. Look at what this script does now:
Is the actor an actor? -> go on
Is the distance to the actor <= 100? -> go on
Force the actor to play the stagger -> every time!
Check if the actor is playing the stagger... well, now it is of course playing what it was told to play the line before. -> set actor to apple -> doesn't have any effect as the script ends after this, the temporary "function object" (let's just call it this for now) vanishes and every variable gets deleted.

You need to do the check "before" forcing the stagger.
...if 0 == rActor.IsAnimGroupPlaying Stagger    rActor.PlayGroup Stagger 1endif...

I hope I'm making sense.
User avatar
Oceavision
 
Posts: 3414
Joined: Thu May 03, 2007 10:52 am

Post » Sat Feb 19, 2011 5:53 am

Force the actor to play the stagger -> every time!

Very well explained. I fear I would have been more sarcastic. :lmao:

Logic dictates that the computer look and react to one line of code at a time, from top to bottom. It cannot 'look ahead' and guess what you really want. ;)
User avatar
David Chambers
 
Posts: 3333
Joined: Fri May 18, 2007 4:30 am

Post » Sat Feb 19, 2011 7:07 am

Of course. Look at what this script does now:
Is the actor an actor? -> go on
Is the distance to the actor <= 100? -> go on
Force the actor to play the stagger -> every time!
Check if the actor is playing the stagger... well, now it is of course playing what it was told to play the line before. -> set actor to apple -> doesn't have any effect as the script ends after this, the temporary "function object" (let's just call it this for now) vanishes and every variable gets deleted.

You need to do the check "before" forcing the stagger.
...if 0 == rActor.IsAnimGroupPlaying Stagger    rActor.PlayGroup Stagger 1endif...

I hope I'm making sense.


You make perfect sense. And thanks for the well explained, clear explanation. I'll add your suggestions and see if it helps.

Very well explained. I fear I would have been more sarcastic. :lmao:

Logic dictates that the computer look and react to one line of code at a time, from top to bottom. It cannot 'look ahead' and guess what you really want. ;)


I have no programming experience. I messed around with AutoHotkey once, but what I accomplished was solely the result of forum help, like I get here. Other than that, never done anything. Oblivion is the first scripting language I've ever began really playing with on my own. Not too long ago, I asked for a (something even I know) very simple script. You responded. Now I'm experimenting more, and am learning.

Scripting is a lot like mathematics. The logic and such. So, I'm still learning the logic. I'll get there eventually (if I continue to script stuff, of course).
User avatar
pinar
 
Posts: 3453
Joined: Thu Apr 19, 2007 1:35 pm

Post » Fri Feb 18, 2011 11:11 pm

Uh, I hope I didn't come across as being sarcastic or anything. I'm never intending to hurt someone. It's just sometimes you're that deep into your own code that you can't see the most obvious flaws anymore. I know it, I was through this myself often enough.
:angel:
And I tend to explain things on a very basic level, as I never know how much the one I'm telling it knows already. It's not schooling or some such, just my own insecurity about how I should best explain it.
User avatar
Mariaa EM.
 
Posts: 3347
Joined: Fri Aug 10, 2007 3:28 am

Post » Sat Feb 19, 2011 10:45 am

You did well Drake, I think it was me. :cryvaultboy:

I have been a programmer for 29 years now and I sometimes forget its a difficult subject to learn. ;)

What I meant is you should look at scripting from the top to the bottom. The computer only knows one line of code at a time. It does not know what came before or after that line of code. Its just one way to look at it that I found helpful.
User avatar
Genocidal Cry
 
Posts: 3357
Joined: Fri Jun 22, 2007 10:02 pm

Post » Sat Feb 19, 2011 12:08 pm

Uh, I hope I didn't come across as being sarcastic or anything. I'm never intending to hurt someone. It's just sometimes you're that deep into your own code that you can't see the most obvious flaws anymore. I know it, I was through this myself often enough.
:angel:
And I tend to explain things on a very basic level, as I never know how much the one I'm telling it knows already. It's not schooling or some such, just my own insecurity about how I should best explain it.


Oh, no. Not at all. You are just breaking things down for me. I didn't take any offense to it.

By the way, I was helping my family for the remainder of the day, up until now, so I haven't had a chance to test your suggestion, but I will now. I'll post back with the results. Thanks again.

EDIT

Works like a charm, Drake the Dragon, works like a charm. You da man.

You did well Drake, I think it was me. :cryvaultboy:

I have been a programmer for 29 years now and I sometimes forget its a difficult subject to learn. ;)

What I meant is you should look at scripting from the top to the bottom. The computer only knows one line of code at a time. It does not know what came before or after that line of code. Its just one way to look at it that I found helpful.


Yes, it was directed at you, WillieSea.

Once again, I didn't really take offense to it, I just felt that your statement required a response from me.

In every post I make asking for help, I make it clear that I am a scripting noob. Just a a little preface for people like you and Drake the Dragon to maybe go an extra step with the help you provide.

And that is helpful. Thanks.
User avatar
Chloe Yarnall
 
Posts: 3461
Joined: Sun Oct 08, 2006 3:26 am


Return to IV - Oblivion