GetAngle not detecting wrong angle on reload.

Post » Fri Sep 26, 2014 7:10 pm

So, I decided to try to improve a dice script http://download.fliggerty.com/download--1047 that lets you roll random numbers when the dice is dropped. The only bug is the SetAngle one where complicated angle combinations get messed up after reload. However, I've run across a huge hurdle: GetAngle is returning the correct angle, even though the dice are sitting on their corners and other crap on reload. Here's the script:

Spoiler
Begin ST_Dice_Script

;Randomly generates dice rolls whenever you drop the die in menumode.
Short OnPCDrop
Short Rand
Short RandAngle ;Misaligns die to make it look naturally dropped.
Float myX
Float myY
Float myZ
If ( OnActivate )
Set OnPCDrop to 0
Activate
Endif
If ( OnPCDrop == 0 )
Return
Elseif ( OnPCDrop == -1 )
If ( Rand > 1 ) ;Conditions where the die might randomly flip on reload.
If ( GetAngle X != myX ) ;these aren't triggering
SetAngle X myX
SetAngle Y myY
SetAngle Z myZ
Elseif ( GetAngle Y != myY ) ;these aren't triggering
SetAngle X myX
SetAngle Y myY
SetAngle Z myZ
Elseif ( GetAngle Z != myZ ) ;these aren't triggering
SetAngle X myX
SetAngle Y myY
SetAngle Z myZ
Endif
Endif
Return
Endif
;OnPCDrop == 1
Set Rand to Random 6
Set RandAngle to Random 180
If ( Rand == 0 ) ;6 on the upward die face. The rest correspond to rand number.
SetAngle X 0
SetAngle Y 0
SetAngle Z RandAngle
Elseif ( Rand == 1 )
SetAngle X 180
SetAngle Y 0
SetAngle Z RandAngle
Elseif ( Rand == 2 )
SetAngle X RandAngle
SetAngle Y 270
SetAngle Z 90
Elseif ( Rand == 3 )
SetAngle X 90
SetAngle Y 180
SetAngle Z RandAngle
Elseif ( Rand == 4 )
SetAngle X 270
SetAngle Y 180
SetAngle Z RandAngle
Elseif ( Rand == 5 )
SetAngle X RandAngle
SetAngle Y 90
SetAngle Z 180
Endif
Set myX to GetAngle X
Set myY to GetAngle Y
Set myZ to GetAngle Z
Set OnPCDrop to -1
End
Typing sv and checking variables against angle show that GetAngle is returning the correct angles. Altering any one angle sets the dice straight. So, for example, if I have a die sitting at an odd angle and type "SetAngle X 1" the script executes to correct it.
So, my problem is GetAngle detection. Why is it not returning properly? And why would setting the angle back to the angle GetAngle already says it's sitting at correct it? This is [censored] up.
Edit: an example of the last question.
- I reload and notice the die is sitting at the wrong angle. I go into the console and type sv.
- The die is 5, so it returns the angle myX 123 (random), myY 90, and myZ 180.
- I type GetAngle for each into the console and it returns X 123, Y 90, and Z 180.
- I type SetAngle X 123, Y 90, and Z 180 into the console.
- I exit the console and the dice flips back to the correct orientation (5 up).
- I pull my hair out because seriously WTF?
Edit2: Changing this part of the script causes the dice to sometimes flip to the correct orientation, but mostly not. Which is only slightly better than the big nothing the other script does on reload:
Spoiler

If ( Rand == 0 ) ;6 on the upward die face. The rest correspond to rand number.
SetAngle X 0
SetAngle Y 0
SetAngle Z RandAngle
Elseif ( Rand == 1 )
SetAngle X 180
SetAngle Y 0
SetAngle Z RandAngle
Elseif ( Rand == 2 )
SetAngle X RandAngle
SetAngle Y 270
SetAngle Z 90
Set myX to RandAngle
Set myY to 270
Set myZ to 90
Elseif ( Rand == 3 )
SetAngle X 90
SetAngle Y 180
SetAngle Z RandAngle
Set myX to 90
Set myY to 180
Set myZ to RandAngle
Elseif ( Rand == 4 )
SetAngle X 270
SetAngle Y 180
SetAngle Z RandAngle
Set myX to 270
Set myY to 180
Set myZ to RandAngle
Elseif ( Rand == 5 )
SetAngle X RandAngle
SetAngle Y 90
SetAngle Z 180
Set myX to RandAngle
Set myY to 90
Set myZ to 180
Endif
User avatar
Marine x
 
Posts: 3327
Joined: Thu Mar 29, 2007 4:54 am

Return to III - Morrowind