Jump to content

[LE] Global value not updating


Recommended Posts

I'm trying to set up a few conditions, however a few of them don't work. The value of temp seems to stay at 0, meaning all conditions requiring it never work. All other elseif statements work perfectly.

 

This is the global:

 

Globalvariable Property aaaFrost auto

This is how i'm trying to get the value:

 

int temp = aaaFrost.getValueInt()

 

This is the condition that doesn't work:

 

ElseIf temp == 5
InstanceID = aaaBreathVFreezing.Play(Game.GetPlayer())

Edited by pojic52523
Link to comment
Share on other sites

Have you assigned the global variable to the property itself? Does your papyrus log have any errors or warnings regarding the usage of the global variable or functions that are trying to use it?

 

You can use the papyrus log to your advantage and add Debug.Trace statements to see what the value is at different points in your code and / or what stages of the code are actually running. Comment out or remove the trace statements from your code after it is working properly as there is no need to waste the processing time to print to the log in the finished product.

Link to comment
Share on other sites

The global variable is assigned to the property, there are no typos. If I change the required value of temp to 0, the if statement works. The global value is correctly changing while the game runs. Here is the full script:

 

 

Scriptname aaaBreathSound extends activemagiceffect

Sound Property aaaBreathCold auto
Sound Property aaaBreathVCold auto
Sound Property aaaBreathFreezing auto
Sound Property aaaBreathVFreezing auto
Sound Property aaaBreathRelaxed auto
Sound Property aaaBreathRun auto
Sound Property aaaBreathTired auto
Sound Property aaaBreathVTired auto
Sound Property aaaBreathDam auto
Sound Property aaaBreathHurt auto
Sound Property aaaBreathVHurt auto
Globalvariable Property aaaFrost auto


Int InstanceID

Event OnEffectStart(Actor akTarget, Actor akCaster)

RegisterForSingleUpdate(0)

EndEvent

Event OnUpdate()

float temp = aaaFrost.getValue()

If (Game.GetPlayer().GetActorValuePercentage("health") < 0.333)
InstanceID = aaaBreathVHurt.Play(Game.GetPlayer())

ElseIf temp == 5
InstanceID = aaaBreathVFreezing.Play(Game.GetPlayer())

ElseIf (Game.GetPlayer().GetActorValuePercentage("health") < 0.666)
InstanceID = aaaBreathHurt.Play(Game.GetPlayer())

ElseIf temp == 4
InstanceID = aaaBreathFreezing.Play(Game.GetPlayer())

ElseIf (Game.GetPlayer().GetActorValuePercentage("stamina") < 0.25)
InstanceID = aaaBreathVTired.Play(Game.GetPlayer())

ElseIf temp == 3
InstanceID = aaaBreathVCold.Play(Game.GetPlayer())

ElseIf (Game.GetPlayer().GetActorValuePercentage("stamina") < 0.5)
InstanceID = aaaBreathTired.Play(Game.GetPlayer())

ElseIf (Game.GetPlayer().GetActorValuePercentage("health") < 0.999)
InstanceID = aaaBreathDam.Play(Game.GetPlayer())

ElseIf temp == 2
InstanceID = aaaBreathCold.Play(Game.GetPlayer())

ElseIf (Game.GetPlayer().GetActorValuePercentage("stamina") < 0.75)
InstanceID = aaaBreathRun.Play(Game.GetPlayer())

Else
InstanceID = aaaBreathRelaxed.Play(Game.GetPlayer())


EndIf

RegisterForSingleUpdate(5.0)

EndEvent

 

Link to comment
Share on other sites

1. The name of the script could be better like "aaaBreathSoundMGEFScript".

 

2. There is a lot of redundant code inside.

 

3. The conditions (you met) are not consistent. I cannot see a good order to get a reliable priority.

 

4. As IsharaMeradin asked: Which conditions change the value of the global?

 

aaaBreathSound

 

Scriptname aaaBreathSound extends ActiveMagicEffect
; https://forums.nexusmods.com/index.php?/topic/9841818-global-value-not-updating/

  Globalvariable PROPERTY aaaFrost auto

;;; Sound[] PROPERTY SoundArray auto        ; suggestion: fill array with next sounds inside the CK, the array will be initialized

; by using array remove these properties
  Sound Property aaaBreathCold auto         ; [0]
  Sound Property aaaBreathVCold auto        ; [1]
  Sound Property aaaBreathFreezing auto     ;
  Sound Property aaaBreathVFreezing auto
  Sound Property aaaBreathRelaxed auto
  Sound Property aaaBreathRun auto
  Sound Property aaaBreathTired auto
  Sound Property aaaBreathVTired auto
  Sound Property aaaBreathDam auto
  Sound Property aaaBreathHurt auto
  Sound Property aaaBreathVHurt auto        ; [10]

  Bool bRun   ; [default = False]


; -- EVENTs --

EVENT OnEffectStart(Actor akTarget, Actor akCaster)
    bool bRun = TRUE     ; *T*
    Debug.Trace("aaaBS: OnEffectStart() - has been triggered")
    RegisterForSingleUpdate(0.0)
ENDEVENT


EVENT OnEffectFinish(Actor akTarget, Actor akCaster)
    bool bRun = False    ; ***
    Debug.Trace("aaaBS: OnEffectFinish() - has been triggered")
ENDEVENT


EVENT OnUpdate()
    actor player = Game.GetPlayer()                            ; once only

    float fH = player.GetActorValuePercentage("Health")        ; once only
    int    i = aaaFrost.GetValue() as Int

    Debug.Trace("aaaBS: OnUpdate() - gFrost = " +i+ ", percHealth = " +fH)        ; for debugging only

    sound snd
;---------    
    IF     (fH < 0.34)
        IF (i == 5)
                    snd = aaaBreathVFreezing        ; cold-5
        ELSE
                    snd = aaaBreathVHurt            ; low
        ENDIF
;---------                
    ELSEIF (fH < 0.67)
        IF (i == 4)
                    snd = aaaBreathFreezing         ; cold-4
        ELSE
                    snd = aaaBreathHurt             ; middle
        ENDIF
;---------
    ELSE       ;IF (fH < 1.00)
        float fS = player.GetActorValuePercentage("Stamina")
        
        IF     (fS < 0.25)
                            snd = aaaBreathVTired           ; low stamina
        ELSEIF (fS < 0.50)
                            snd = aaaBreathTired            ; middle stamina
        ELSEIF (fS < 0.75)
                            snd = aaaBreathRun              ; stamina lost a quarter
        ELSE
            IF     (i == 3)
                            snd = aaaBreathVCold    ; cold-3
            ELSEIF (i == 2)
                            snd = aaaBreathCold     ; cold-2
            ELSE
                            snd = aaaBreathDam      ; good
            ENDIF
        ENDIF

    ENDIF
;-----
    IF ( bRun )
        IF player.IsDead()
            ;; player R.I.P, do nothing
        ELSE
            i = snd.Play(player as ObjectReference)            ; play the pre-selected sound
        ENDIF

        RegisterForSingleUpdate(5.0)
    ENDIF
ENDEVENT

 

 

Edited by ReDragon2013
Link to comment
Share on other sites

Turns out I am completely blind, it took me multiple checks to realize that the property WAS misspelt. All the conditions work now.

 

3. The conditions (you met) are not consistent. I cannot see a good order to get a reliable priority.

 

I carried over all the changes, sadly the priority of the conditions is a bit of a pain, since the order they were in is the only one that makes sense. I've reordered them, although it isn't as efficient.

 

You wrote: ;;; Sound[] PROPERTY SoundArray auto ; suggestion: fill array with next sounds inside the CK, the array will be initialized.

I dont understand how to do this, and what it would do.

 

Thank you for so many improvements.

Edited by pojic52523
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...