DX script help! Or why is 2 not smaller than 15?

OK, somebody explains this to me please...
Say I have this code:

Sub Object_OnScriptEnter
  Object.SetTimer 9882, 5000
  Object.PersistStorage("current") = 0
  Object.PersistStorage("WPNum") = 15
End Sub

Sub Object_OnTimer9882
  If Object.PersistStorage("current") < Object.PersistStorage("WPNum") Then
    msgbox Object.PersistStorage("current") & " is smaller than " & Object.PersistStorage("WPNum")
  Else
    msgbox Object.PersistStorage("current") & " is not smaller than " & Object.PersistStorage("WPNum")
  End If
  Object.PersistStorage("current") = Object.PersistStorage("current") + 1
End Sub

Now, the output of this would be msgboxes like this:
0 is smaller than 15
1 is smaller than 15
2 is not smaller than 15
3 is not smaller than 15
etc.

Now, how is that? There is something I don't understand.  I've already checked that the returned values were numeric with the IsNumeric function, and they are.
I really need help on this please.

2,333 views 3 replies
Reply #1 Top
You may need to convert to an integer or other numeric data format before performing calculations on it:

If CInt(Object.PersistStorage("current")) < CInt(Object.PersistStorage("WPNum")) Then
Reply #2 Top
All right. I still don't understand why bit it seems the values are not considered Integers. I used CInt to convert the Persistent Storage variables and it works now.
Reply #3 Top
Hehehe!  Thanks Martin. We figured it out at the same time.