Jump to content

If, ElseIf, Else conditions not counting correctly


Recommended Posts

Posted

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.

 

  Reveal hidden contents

 

; ------------------------------------- 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.

  • Community Manager
Posted (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 by Pickysaurus
Read the GVs wrong
Posted

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
Posted (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 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
Posted (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.0

  Reveal hidden contents

 

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
Posted

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".

Posted (edited)

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

 

  Reveal hidden contents

 

 

Shrines.mp4 - OneDrive (live.com)

Edited by antstubell
Posted (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: 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
Posted

#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.

Posted

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?

  • Recently Browsing   0 members

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