Jump to content

If, ElseIf, Else conditions not counting correctly


antstubell

Recommended Posts

This function has a flaw and I need help please. I have noted what each part of the condition does. Problem is that the variable isn't always incremented.

 

Function EastShrine()
Float CurrentAngleZ = TranslateRef.GetAngleZ(); get rotation angle
; ------------------------------------- Quarter Turn ------------------------------------
If (CurrentAngleZ == IsNorth) || (CurrentAngleZ == IsSouth)
SFXplayTime = InputMovementTimeQuarterTurn
SMTgv_ShrineTempValHolder.SetValue(2)
; ------------------------------- Opposite Facing Half Turn ---------------------------
ElseIf (CurrentAngleZ == IsWest)
SFXplayTime = InputMovementTimeHalfTurn
SMTgv_ShrineTempValHolder.SetValue(2)
; -------------------------------- Already This Way -------------------------------------
Else
SFXplayTime = 0.0
SMTgv_ShrineTempValHolder.SetValue(2)
EndIf
SMTgv_ShrineActCount.Mod(1)
EndFunction

 

; ------------------------------------- Quarter Turn ------------------------------------

This works and the variable SMTgv_ShrineActCount is incremented by 1

; ------------------------------- Opposite Facing Half Turn ---------------------------

This works and the variable SMTgv_ShrineActCount is incremented by 1

; -------------------------------- Already This Way -------------------------------------

This Else statement does not increment the variable by 1

 

I hope this is enough to explain the issue. Thanks for looking.

Link to comment
Share on other sites

I would highly recommend indenting your code, otherwise it's really hard to read.

 

You have "SMTgv_ShrineActCount.Mod(1)" outside of the if/else check, so it will always fire after anything inside the check.

Function EastShrine()
	Float CurrentAngleZ = TranslateRef.GetAngleZ(); get rotation angle
	if (CurrentAngleZ == IsNorth) || (CurrentAngleZ == IsSouth) ; 1/4 turn
		SFXplayTime = InputMovementTimeQuarterTurn
		SMTgv_ShrineTempValHolder.SetValue(2)
	elseIf (CurrentAngleZ == IsWest) ; Opposite facing half turn
		SFXplayTime = InputMovementTimeHalfTurn
		SMTgv_ShrineTempValHolder.SetValue(2)
	else ; Already this way
		SFXplayTime = 0.0
		SMTgv_ShrineTempValHolder.SetValue(2)
	endIf
	
	SMTgv_ShrineActCount.Mod(1)
EndFunction

So you're saying the "else" part of the check just isn't doing anything? That's potentially because one of the previous statements is passing as true.

Edited by Pickysaurus
Read the GVs wrong
Link to comment
Share on other sites

Do IsNorth, IsSouth, IsEast, and IsWest detect ANY angle within +-45 degrees of "true North, South, East or West" as being true?

In my game I can stand at 271 degrees, or 7 degrees, or any angle possible using my mouse and movement controls. Presuming 0 degrees is North (because tbh, I have no idea if 0 is north) , what does 7 degrees evaluate to?

 

-----

btw, FWIW, based on your code, the statement

SMTgv_ShrineTempValHolder.SetValue(2) 

can simply be put below the if-then processing, since it's fired no matter what happens.

so

Function EastShrine()
	Float CurrentAngleZ = TranslateRef.GetAngleZ(); get rotation angle
	if (CurrentAngleZ == IsNorth) || (CurrentAngleZ == IsSouth) ; 1/4 turn
		SFXplayTime = InputMovementTimeQuarterTurn
		SMTgv_ShrineTempValHolder.SetValue(2)     <<<<<
	elseIf (CurrentAngleZ == IsWest) ; Opposite facing half turn
		SFXplayTime = InputMovementTimeHalfTurn
		SMTgv_ShrineTempValHolder.SetValue(2)     <<<<<
	else ; Already this way
		SFXplayTime = 0.0
		SMTgv_ShrineTempValHolder.SetValue(2)     <<<<<
	endIf
	
	SMTgv_ShrineActCount.Mod(1)
EndFunction

becomes

Function EastShrine()
	Float CurrentAngleZ = TranslateRef.GetAngleZ(); get rotation angle
	if (CurrentAngleZ == IsNorth) || (CurrentAngleZ == IsSouth) ; 1/4 turn
		SFXplayTime = InputMovementTimeQuarterTurn
	elseIf (CurrentAngleZ == IsWest) ; Opposite facing half turn
		SFXplayTime = InputMovementTimeHalfTurn
	else ; Already this way
		SFXplayTime = 0.0
	endIf
	SMTgv_ShrineTempValHolder.SetValue(2)
	SMTgv_ShrineActCount.Mod(1)
EndFunction
Link to comment
Share on other sites

The long script detects which shrine North, South, East or West is activated. When activated they return a value 1,2,3 or 4, These values are stored as globals to make a 3 digit code. E,g, 2,1,4 is East, North, West. ShrineActCount counts to 3, stores the last 3 numbers that were activated, checks if it matches any of the 3 digit codes which 'does stuff', if not it resets to zero and counts again. These are the properties for directions. I am not sure if the game only calculates an angle based on if it has been turned clockwise, so I covered both bases - clockwise and anti-clockwise. Not reflected in the portion of script I posted.

 

; statue starts facing south

Int Property IsNorth =0 Auto

Float Property IsSouth =180.0 Auto

Float Property IsEast =90.0 Auto

Float Property IsWest =270.0 Auto

Float Property IsWestAlt =-90.0 Auto; alternative rotation

Float Property IsEastAlt =-270.0 Auto; alternative rotation

Float Property IsSouthAlt =-180.0 Auto; alternative rotation

 

Thanks for your help, I'll get around to it sometime today.

 

EDIT: The statue will always take the 'shortest route' to get to where it needs to be. Meaning if it is facing North and the West Shrine is activated, it won't turn East, South then West to get there. It will go from North to West - hence my query as to whether the final degree of rotation is 270deg or -90deg.

Edited by antstubell
Link to comment
Share on other sites

So still not adding 1 if the else statement is true but the SFXPlayTime is correct i.e. the statue rotating sound doesn't play 0.0

Function EastShrine()
Float CurrentAngleZ = TranslateRef.GetAngleZ(); get rotation angle
; ------------------------------------- Quarter Turn ------------------------------------
If (CurrentAngleZ == IsNorth) || (CurrentAngleZ == IsSouth)
SFXplayTime = InputMovementTimeQuarterTurn
; ------------------------------- Opposite Facing Half Turn ---------------------------
ElseIf (CurrentAngleZ == IsWest)
SFXplayTime = InputMovementTimeHalfTurn
; -------------------------------- Already This Way -------------------------------------
Else
SFXplayTime = 0.0
EndIf
SMTgv_ShrineTempValHolder.SetValue(2)
SMTgv_ShrineActCount.Mod(1)
AssignVal()
EndFunction

 

EDIT: I placed SMTgv_ShrineActCount.Mod(1) at the beginning of the function and the else statement still won't add 1. Got to be something else in the script that I can't see.

Edited by antstubell
Link to comment
Share on other sites

Hope this is helpful. Please don't ask me to completely rewrite the script.

 

; statue starts facing south
Int Property IsNorth =0 Auto
Float Property IsSouth =180.0 Auto
Float Property IsEast =90.0 Auto
Float Property IsWest =270.0 Auto
Float Property IsWestAlt =-90.0 Auto; alternative rotation
Float Property IsEastAlt =-270.0 Auto; alternative rotation
Float Property IsSouthAlt =-180.0 Auto; alternative rotation

Float Property PosX1 Auto
Float Property PosY1 Auto
Float Property PosZ1 Auto
Float Property RotX1 Auto
Float Property RotY1 Auto
Float Property RotZ1 Auto

GlobalVariable Property SMTgv_ShrineActCount Auto

GlobalVariable Property SMTgv_ShrineActivated01 Auto
GlobalVariable Property SMTgv_ShrineActivated02 Auto
GlobalVariable Property SMTgv_ShrineActivated03 Auto

GlobalVariable Property SMTgv_ShrineNorth Auto
GlobalVariable Property SMTgv_ShrineEast Auto
GlobalVariable Property SMTgv_ShrineSouth Auto
GlobalVariable Property SMTgv_ShrineWest Auto

Float Property Adelay Auto
Float Property RotationVal Auto
Float Property SpeedVal Auto
Float Property SFXplayTime =0.0 Auto
GlobalVariable Property SMTgv_ShrineRaiseBeam Auto
GlobalVariable Property MyGlobal Auto
GlobalVariable Property SMTgv_ShrineTempValHolder Auto
Int Property Val Auto
Int Property InputRotZVal Auto; RotZ statue angle when facing this shrine
Int Property InputMovementTimeQuarterTurn Auto
Int Property InputMovementTimeHalfTurn Auto
ObjectReference Property TranslateRef Auto
ObjectReference Property SndMarker1 Auto
ObjectReference Property SndMarker2 Auto
ObjectReference Property SndMarker3 Auto
ObjectReference Property PreDisObj01 Auto
ObjectReference Property LSource Auto
ObjectReference Property BeamRaise Auto
Sound Property SFX1 Auto
Sound Property SFX2 Auto
Sound Property SFX3 Auto
String Property Text Auto
String Property Text2 Auto

Event OnActivate(ObjectReference akActionRef)
debug.notification(Text)
; check statue is not already in the place where we are activating it from
Float CurrentAngleZ = TranslateRef.GetAngleZ(); get rotation angle
if (InputRotZVal != CurrentAngleZ)
Self.Disable()
; get sfx play times
If ((InputRotZVal) == IsNorth)
NorthShrine()
ElseIf ((InputRotZVal) == IsEast)
EastShrine()
ElseIf ((InputRotZVal) == IsSouth)
SouthShrine()
Else
; ((InputRotZVal) == IsWest)
WestShrine()
EndIf

PreDisObj01.Disable(); light shrine
LSource.Enable(); shrine light source
SFX1.Play(SndMarker1); candle ignite sound
Utility.Wait(0.5)
Int SoundInstance = SFX2.Play(SndMarker2)
TranslateRef.TranslateTo(PosX1, PosY1, posZ1, RotX1, RotY1, RotZ1, SpeedVal, RotationVal)
Utility.Wait(SFXplayTime)
Sound.StopInstance(SoundInstance)
SFXplayTime = 0.0

MyGlobal.SetValue(Val); set global value for this shrine
debug.notification(Text2)
Utility.Wait(1)
SFX3.Play(SndMarker3)
ActObj(); go to check digits function

Else

; this won’t show until the activator is re-enabled
PreDisObj01.Disable(); light shrine
LSource.Enable(); shrine light source
SFX1.Play(SndMarker1); candle ignite sound
debug.notification("Already Facing This Way")
SFX3.Play(SndMarker3)
Self.Disable()

EndIf
EndEvent

; --------------------------------- North Shrine Activated ------------------------
Function NorthShrine()
SMTgv_ShrineActCount.Mod(1)
Float CurrentAngleZ = TranslateRef.GetAngleZ(); get rotation angle
; ------------------------------------- Quarter Turn ------------------------------------
If (CurrentAngleZ == IsEast) || (CurrentAngleZ == IsWest)
SFXplayTime = InputMovementTimeQuarterTurn
; ------------------------------------------ Opposite Facing Half Turn ---------------------------
ElseIf (CurrentAngleZ == IsSouth)
SFXplayTime = InputMovementTimeHalfTurn
; --------------------------------------- Already This Way -------------------------------------
Else
SFXplayTime = 0.0
EndIf
SMTgv_ShrineTempValHolder.SetValue(1)
AssignVal()
EndFunction
; --------------------------------- East Shrine Activated ------------------------
Function EastShrine()
SMTgv_ShrineActCount.Mod(1)
Float CurrentAngleZ = TranslateRef.GetAngleZ(); get rotation angle
; ------------------------------------- Quarter Turn ------------------------------------
If (CurrentAngleZ == IsNorth) || (CurrentAngleZ == IsSouth)
SFXplayTime = InputMovementTimeQuarterTurn
; ------------------------------- Opposite Facing Half Turn ---------------------------
ElseIf (CurrentAngleZ == IsWest)
SFXplayTime = InputMovementTimeHalfTurn
; -------------------------------- Already This Way -------------------------------------
Else
SFXplayTime = 0.0
EndIf
SMTgv_ShrineTempValHolder.SetValue(2)
AssignVal()
EndFunction
; --------------------------------- South Shrine Activated ------------------------
Function SouthShrine()
SMTgv_ShrineActCount.Mod(1)
Float CurrentAngleZ = TranslateRef.GetAngleZ(); get rotation angle
; ------------------------------------- Quarter Turn ------------------------------------
If (CurrentAngleZ == IsEast) || (CurrentAngleZ == IsWest)
SFXplayTime = InputMovementTimeQuarterTurn
; ------------------------------- Opposite Facing Half Turn ---------------------------
ElseIf (CurrentAngleZ == IsNorth)
SFXplayTime = InputMovementTimeHalfTurn
; -------------------------------- Already This Way -------------------------------------
Else
SFXplayTime = 0.0
EndIf
SMTgv_ShrineTempValHolder.SetValue(3)
AssignVal()
EndFunction
; --------------------------------- West Shrine Activated ------------------------
Function WestShrine()
SMTgv_ShrineActCount.Mod(1)
Float CurrentAngleZ = TranslateRef.GetAngleZ(); get rotation angle
; ------------------------------------- Quarter Turn ------------------------------------
If (CurrentAngleZ == IsNorth) || (CurrentAngleZ == IsSouth)
SFXplayTime = InputMovementTimeQuarterTurn
; ------------------------------- Opposite Facing Half Turn ---------------------------
ElseIf (CurrentAngleZ == IsEast)
SFXplayTime = InputMovementTimeHalfTurn
; -------------------------------- Already This Way -------------------------------------
Else
SFXplayTime = 0.0
EndIf
SMTgv_ShrineTempValHolder.SetValue(4)
AssignVal()
EndFunction
; -------------------------------- Assign a Value ---------------------------------------
Function AssignVal()
debug.notification("Assigning a Value.")

If SMTgv_ShrineActivated01.GetValue() == 0; if the first value is not set > set the first value
SMTgv_ShrineActivated01.SetValue(SMTgv_ShrineTempValHolder.GetValue())
Utility.Wait(0.5)

ElseIf (SMTgv_ShrineActivated01.GetValue() != 0) && (SMTgv_ShrineActivated02.GetValue() == 0)
SMTgv_ShrineActivated02.SetValue(SMTgv_ShrineTempValHolder.GetValue())

ElseIf (SMTgv_ShrineActivated01.GetValue() != 0) && (SMTgv_ShrineActivated02.GetValue() != 0) && (SMTgv_ShrineActivated03.GetValue() == 0)
SMTgv_ShrineActivated03.SetValue(SMTgv_ShrineTempValHolder.GetValue())
EndIf
Utility.Wait(0.5)
SMTgv_ShrineTempValHolder.SetValue(0); resets temp holder
EndFunction
; -----------------------------------------------------------------------------------
Function ActObj()
If SMTgv_ShrineActCount.GetValue() == 3
SMTgv_ShrineActCount.SetValue(0); reset shrine activated count
EndIf

debug.notification("Check 3 digits and activate?")
If (SMTgv_ShrineActivated01.GetValue() == 2) && (SMTgv_ShrineActivated02.GetValue() == 1) && (SMTgv_ShrineActivated03.GetValue() == 4) && (SMTgv_ShrineRaiseBeam.GetValue() == 0)
Utility.Wait(Adelay)
BeamRaise.Activate(Self)
EndIf
EndFunction

 

 

Shrines.mp4 - OneDrive (live.com)

Edited by antstubell
Link to comment
Share on other sites

Sorry, I'm not reading in careful detail but I can share some thoughts I got by quickly scanning though this...

First, I think it's a bold move to use GetAngle and compare it to exact variables.

It's easy for the game to use angles like 181.75 or something like that and the whole thing falls appart. But if you're certain you placed things in exact values and there's no way that changes, it should work

 

Second, and this is the part that usually helps me: Debug

Just enable papyrus logging and tracing and then put lines for every part of the process like:

Function EastShrine()
	Float CurrentAngleZ = TranslateRef.GetAngleZ(); get rotation angle
	Debug.Trace("SHRINE_SCRIPT: Current angle = "+CurrentangleZ) ; Now you know exactly that the script got as the angle
	
	if (CurrentAngleZ == IsNorth) || (CurrentAngleZ == IsSouth) ; 1/4 turn
		Debug.Trace("SHRINE_SCRIPT: Executing 1/4 turn statement")
		
		SFXplayTime = InputMovementTimeQuarterTurn ; dont know what these variables are, but if you need to debug them, you can
		
		Debug.Trace("SHRINE_SCRIPT: SMTgv_ShrineTempValHolder value == "+SMTgv_ShrineTempValHolder.GetValue())
		SMTgv_ShrineTempValHolder.SetValue(2)     <<<<<
		ebug.Trace("SHRINE_SCRIPT: SMTgv_ShrineTempValHolder  NEW value == "+SMTgv_ShrineTempValHolder.GetValue())
		
	elseIf (CurrentAngleZ == IsWest) ; Opposite facing half turn
		Debug.Trace("SHRINE_SCRIPT: opposite facing half turn statement")

And so on

No matter how ridiculous it seems, you'll probably get something useful out of it. If anything it will tell you exactly at what point of the code the script is not working as you want to.

Edited by Myst42
Link to comment
Share on other sites

#1 Does the offending variable not update during any of the shrine functions or only in the originally posted EastShrine function?

#2 Could there be any way that the ActObj function could be running and resetting the variable before you have a chance to check its value in the console?

 

 

And I agree with Myst42. Trace statements are very helpful when troubleshooting code. Yes, it does affect the overall timing. But it is worth knowing at what point the code actually fails. The trace statements can always be commented out when no longer needed.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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