I decided to totally rewrite the code to see if I could escape this weird bug, but still no luck. Button object (this script belongs to Button) is contained by object named ButtonBack. I need all 3 states to be in same picture, so I designed it so picture moves up or down to proper state. The problem is that when it moves up to proper pressed state, it moves ButtonBack up by same amount! Very, very annoying.
To recreate this problem, just create a solid magic pink picture of any size, use this for ButtonBack. Create a object named Button and make it a contained child of ButtonBack. Add this entire script to Button. If you want button to be square, make sure picture assigned to Button is 3 times as tall as it is wide.
When it's done and script is running, mouse over it. It should change (if you made Button picture solid single color you can't see it change.) to hover mode. It doesn't move parent up however. Now, press left button and hold. It changes to clicked mode, and somehow moves parent object up too. Let mouse button go and it stays there but it changes to normal mode.
Things I have tried:
Another object on front accepting clicks and sending messages to change state. No luck.
Timer that checks for a var that changes to 1 then changes to pressed state. No luck.
'Called when the script is executed
Dim Thirdsize
Sub Object_OnScriptEnter
Thirdsize=object.Height/3
Desktopx.Object("ButtonBack").width=object.width
DesktopX.Object("ButtonBack").Height=Thirdsize
End Sub
Sub Object_OnStateChange(state)
If state = "Mouse down" Then
Controlmode 1
ElseIf state = "Mouse up" Then
Controlmode 0
ElseIf state = "Mouse over" Then
Controlmode 2
ElseIf state = "Mouse away" Then
Controlmode 0
End If
End Sub
Sub Controlmode(Mode)
' Mode 0: normal; Mode 1: Click; Mode 2: Hover
If Mode=0 Then
Object.top=0
ElseIf Mode=1 Then
object.top=-Thirdsize
ElseIf Mode=2 Then
object.top=-Thirdsize * 2
End If
End Sub