We have two scripts running on our stocks full screens, both intending to do the same thing, but written by two different people. As we know, everyone has their own style of writing code, but going through these, they should both work fine.
However, Version A will return a false 0 when the number is extremely close to zero (-0.24 through 0.24), and it incorrectly changes the visibility of one of our scenes to 0.
Version B works correctly.
My questions is not which one is "right," but rather why Version A is not working correctly, as it should be just fine (and in my opinion, is a cleaner code)
Version A
dim change as xpTextObject
dim arrow as xpBaseObject
dim redmat as xpMaterial
dim gremat as xpMaterial
dim changeval as double
dim i as integer
Engine.GetMaterialByName("Arrow - Red", redmat)
Engine.GetMaterialByName("Arrow - Green", gremat)
for i = 1 to 3
Self.GetObjectByName("Change " & i, change)
Self.GetObjectByName("Arrow " & i, arrow)
changeval=Cint(change.Text)
if changeval (is less than) 0 then
arrow.Visible = True
arrow.SetMaterial(0, redmat)
arrow.SetMaterial(1, redmat)
arrow.ScaleY = -(arrow.ScaleY)
elseif changeval (is greater than) 0 then
arrow.Visible = True
arrow.SetMaterial(0, gremat)
arrow.SetMaterial(1, gremat)
arrow.ScaleY = Math.Abs(Arrow.ScaleY)
elseif changeval = 0 then
arrow.visible = False
end if
next i
Version B
dim CHNG as xpTextObject
dim Arrow as xpBaseObject
dim RedMat as xpMaterial
dim GreMat as xpMaterial
dim CHNGVAL as Double
dim i as Integer
Engine.GetMaterialByName("Arrow - Red", RedMat)
Engine.GetMaterialByName("Arrow - Green", GreMat)
for i = 1 to 4
Self.GetObjectByName("Change " & i, CHNG)
Self.GetObjectByName("Arrow " & i, Arrow)
CHNGVAL = CHNG.Text
If CHNGVAL (is less than) 0 then
Arrow.SetMaterial(0, RedMat)
Arrow.SetMaterial(1, RedMat)
Arrow.ScaleY = -(Arrow.ScaleY)
End If
If CHNGVAL (is greater than) 0 then
Arrow.SetMaterial(0, GreMat)
Arrow.SetMaterial(1, GreMat)
Arrow.ScaleY = Math.Abs(Arrow.ScaleY)
End If
If CHNGVAL = 0 then
Arrow.Alpha = 0
End If
next i
EDIT: replaced the actual greater than and less than symbols with (is greater/less than) in order to not confuse the forum.