antstubell Posted September 8, 2021 Share Posted September 8, 2021 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 = InputMovementTimeQuarterTurnSMTgv_ShrineTempValHolder.SetValue(2); ------------------------------- Opposite Facing Half Turn ---------------------------ElseIf (CurrentAngleZ == IsWest)SFXplayTime = InputMovementTimeHalfTurnSMTgv_ShrineTempValHolder.SetValue(2); -------------------------------- Already This Way -------------------------------------ElseSFXplayTime = 0.0SMTgv_ShrineTempValHolder.SetValue(2)EndIfSMTgv_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 More sharing options...
Pickysaurus Posted September 8, 2021 Share Posted September 8, 2021 (edited) 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 September 8, 2021 by Pickysaurus Read the GVs wrong Link to comment Share on other sites More sharing options...
anjenthedog Posted September 8, 2021 Share Posted September 8, 2021 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 More sharing options...
antstubell Posted September 9, 2021 Author Share Posted September 9, 2021 (edited) 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 southInt Property IsNorth =0 AutoFloat Property IsSouth =180.0 AutoFloat Property IsEast =90.0 AutoFloat Property IsWest =270.0 AutoFloat Property IsWestAlt =-90.0 Auto; alternative rotationFloat Property IsEastAlt =-270.0 Auto; alternative rotationFloat 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 September 9, 2021 by antstubell Link to comment Share on other sites More sharing options...
antstubell Posted September 9, 2021 Author Share Posted September 9, 2021 (edited) 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.0Function 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 -------------------------------------ElseSFXplayTime = 0.0EndIfSMTgv_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 September 9, 2021 by antstubell Link to comment Share on other sites More sharing options...
IsharaMeradin Posted September 9, 2021 Share Posted September 9, 2021 Perhaps if you shared either the whole script or just the sections that contain the troublesome SMTgv_ShrineActCount variable, we might be able to see something. As it stands now, all I can do is shrug my shoulders and say "no idea". Link to comment Share on other sites More sharing options...
antstubell Posted September 10, 2021 Author Share Posted September 10, 2021 (edited) Hope this is helpful. Please don't ask me to completely rewrite the script. ; statue starts facing southInt Property IsNorth =0 AutoFloat Property IsSouth =180.0 AutoFloat Property IsEast =90.0 AutoFloat Property IsWest =270.0 AutoFloat Property IsWestAlt =-90.0 Auto; alternative rotationFloat Property IsEastAlt =-270.0 Auto; alternative rotationFloat Property IsSouthAlt =-180.0 Auto; alternative rotationFloat Property PosX1 AutoFloat Property PosY1 AutoFloat Property PosZ1 AutoFloat Property RotX1 AutoFloat Property RotY1 AutoFloat Property RotZ1 AutoGlobalVariable Property SMTgv_ShrineActCount AutoGlobalVariable Property SMTgv_ShrineActivated01 AutoGlobalVariable Property SMTgv_ShrineActivated02 AutoGlobalVariable Property SMTgv_ShrineActivated03 AutoGlobalVariable Property SMTgv_ShrineNorth AutoGlobalVariable Property SMTgv_ShrineEast AutoGlobalVariable Property SMTgv_ShrineSouth AutoGlobalVariable Property SMTgv_ShrineWest AutoFloat Property Adelay AutoFloat Property RotationVal AutoFloat Property SpeedVal AutoFloat Property SFXplayTime =0.0 AutoGlobalVariable Property SMTgv_ShrineRaiseBeam AutoGlobalVariable Property MyGlobal AutoGlobalVariable Property SMTgv_ShrineTempValHolder AutoInt Property Val AutoInt Property InputRotZVal Auto; RotZ statue angle when facing this shrineInt Property InputMovementTimeQuarterTurn AutoInt Property InputMovementTimeHalfTurn AutoObjectReference Property TranslateRef AutoObjectReference Property SndMarker1 AutoObjectReference Property SndMarker2 AutoObjectReference Property SndMarker3 AutoObjectReference Property PreDisObj01 AutoObjectReference Property LSource AutoObjectReference Property BeamRaise AutoSound Property SFX1 AutoSound Property SFX2 AutoSound Property SFX3 AutoString Property Text AutoString Property Text2 AutoEvent OnActivate(ObjectReference akActionRef)debug.notification(Text); check statue is not already in the place where we are activating it fromFloat CurrentAngleZ = TranslateRef.GetAngleZ(); get rotation angleif (InputRotZVal != CurrentAngleZ)Self.Disable(); get sfx play timesIf ((InputRotZVal) == IsNorth)NorthShrine()ElseIf ((InputRotZVal) == IsEast)EastShrine()ElseIf ((InputRotZVal) == IsSouth)SouthShrine()Else; ((InputRotZVal) == IsWest)WestShrine()EndIfPreDisObj01.Disable(); light shrineLSource.Enable(); shrine light sourceSFX1.Play(SndMarker1); candle ignite soundUtility.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.0MyGlobal.SetValue(Val); set global value for this shrinedebug.notification(Text2)Utility.Wait(1)SFX3.Play(SndMarker3)ActObj(); go to check digits functionElse; this won’t show until the activator is re-enabledPreDisObj01.Disable(); light shrineLSource.Enable(); shrine light sourceSFX1.Play(SndMarker1); candle ignite sounddebug.notification("Already Facing This Way")SFX3.Play(SndMarker3)Self.Disable()EndIfEndEvent; --------------------------------- 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 -------------------------------------ElseSFXplayTime = 0.0EndIfSMTgv_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 -------------------------------------ElseSFXplayTime = 0.0EndIfSMTgv_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 -------------------------------------ElseSFXplayTime = 0.0EndIfSMTgv_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 -------------------------------------ElseSFXplayTime = 0.0EndIfSMTgv_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 valueSMTgv_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())EndIfUtility.Wait(0.5)SMTgv_ShrineTempValHolder.SetValue(0); resets temp holderEndFunction; -----------------------------------------------------------------------------------Function ActObj()If SMTgv_ShrineActCount.GetValue() == 3SMTgv_ShrineActCount.SetValue(0); reset shrine activated countEndIfdebug.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)EndIfEndFunction Shrines.mp4 - OneDrive (live.com) Edited September 10, 2021 by antstubell Link to comment Share on other sites More sharing options...
Myst42 Posted September 10, 2021 Share Posted September 10, 2021 (edited) 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: DebugJust 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 onNo 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 September 10, 2021 by Myst42 Link to comment Share on other sites More sharing options...
IsharaMeradin Posted September 10, 2021 Share Posted September 10, 2021 #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 More sharing options...
antstubell Posted September 12, 2021 Author Share Posted September 12, 2021 It happens on every shrine when the shrine is already facing the way of the shrine activated.Debugging - Yes it looks tedious but at this point I'll give it a go. I don't have access to CK right now but how do I enable logging and tracing and where will the report be? Link to comment Share on other sites More sharing options...
Recommended Posts