I have a infinite loop and I don't know why.

Post » Mon Aug 11, 2014 3:38 am

Spoiler
Actor property PlayerRef autoBool bStopLoop = falseEvent OnEffectStart(Actor akTarget, Actor akCaster);Float CurrentPercent = PlayerRef.GetActorValuePercentage("Magikca")Float BaseMag = PlayerRef.GetBaseActorValue("Magicka")Float CurrentMag = PlayerRef.GetActorValue("Magicka")    If akCaster == PlayerRef        While bStopLoop == false            debug.notification("While loop has started.")            If CurrentMag == BaseMag                akCaster.InterruptCast()                bStopLoop = true            Endif        EndWhile    EndifEndEvent

Notification keeps playing regardless. The loop is supposed to stop when the magicka reaches maximum. I've already tried changing the loop to 'PlayerRef.GetActorValuePercentage("Magicka") < 1.0'

As an additional side effect, it keeps playing even when the effect is gone(the casting stopped.)

The second statement works as intended at least for interruptCast.

I made a Convert Stamina to Magicka type spell, but the stamina keeps draining even when the magicka is full, so I'm trying to stop the effect when the magicka is full.

User avatar
Chloe :)
 
Posts: 3386
Joined: Tue Jun 13, 2006 10:00 am

Post » Mon Aug 11, 2014 5:11 pm

The variable CurrentMag is only obtained once at EffectStart, it is never updated during the While Loop. Therefore CurrentMag will never equal BaseMag. Moving the position of CurrentMag, would obtain the new value each loop, but would this have performance issues

Spoiler
Actor property PlayerRef autoBool bStopLoop = falseEvent OnEffectStart(Actor akTarget, Actor akCaster);Float CurrentPercent = PlayerRef.GetActorValuePercentage("Magikca")Float BaseMag = PlayerRef.GetBaseActorValue("Magicka")    If akCaster == PlayerRef        While bStopLoop == false           Float CurrentMag = PlayerRef.GetActorValue("Magicka")            debug.notification("While loop has started.")            If CurrentMag == BaseMag                akCaster.InterruptCast()                bStopLoop = true            Endif        EndWhile    EndifEndEvent
User avatar
Causon-Chambers
 
Posts: 3503
Joined: Sun Oct 15, 2006 11:47 pm

Post » Mon Aug 11, 2014 11:49 am

I was about to post the same as heilghast. However, I am a bit puzzled by the statement that InterrupCast is being called nonetheless. Perhaps the script instance is being reset frequently and causing bStopLoop to reset to false before it is evaluated? I've encountered issues caused by variables being reset in the middle of running a function and the cause was the script instance being reset. You could try moving the bStopLoop declaration into the event or use a variable that is stored outside of this script (global variable or another script).

User avatar
NEGRO
 
Posts: 3398
Joined: Sat Sep 01, 2007 12:14 am

Post » Mon Aug 11, 2014 4:30 am

Is this a Fire and Forget or a concentration spell?

As i have a fire and forget spell which converts health to magicka for a duration of 1 minute, but when magicka is full, i use a condition on the spell to stop the effect. However it does restart, if magicka drops below maximum.

User avatar
Darren
 
Posts: 3354
Joined: Wed Jun 06, 2007 2:33 pm

Post » Mon Aug 11, 2014 8:00 am

It's concentration, I was also trying to emulate the concentration healing spell, ya know, a heal spell for health and a heal spell for magicka.

Learned something new.. the position of declarations matter in an event o_o. I thought as long as it's declared it doesn't matter where its placed.

Performance issues.. How do I avoid that?

@MrJack - further testing shows interruptCast is not calling as I thought it was. IIRC it should stop the casting animation(it doesn't). But the effects that play on the character end when magicka is full. Well, that's part of what I want.

User avatar
SHAWNNA-KAY
 
Posts: 3444
Joined: Mon Dec 18, 2006 1:22 pm

Post » Mon Aug 11, 2014 10:11 am

It's not where the variable is declared that matters so much as where the value gets assigned to it. For instance...

Actor property PlayerRef autoBool bStopLoop = falseEvent OnEffectStart(Actor akTarget, Actor akCaster);Float CurrentPercent = PlayerRef.GetActorValuePercentage("Magikca")Float BaseMag = PlayerRef.GetBaseActorValue("Magicka")Float CurrentMag    If akCaster == PlayerRef        While bStopLoop == false            CurrentMag = PlayerRef.GetActorValue("Magicka")            debug.notification("While loop has started.")            If CurrentMag == BaseMag                akCaster.InterruptCast()                bStopLoop = true            Endif        EndWhile    EndifEndEvent

...has the declaration of CurrentMag outside the loop, but the assignment in the loop.

Personally I prefer to put all declarations at the top of the code for readability, and in many languages that's a requirement, but my understanding, like yours, is that they can be declared pretty much anywhere.

User avatar
Mylizards Dot com
 
Posts: 3379
Joined: Fri May 04, 2007 1:59 pm


Return to V - Skyrim