[1.0.2] Type Conversion - ntoxin66/Dynamic GitHub Wiki

Dynamic supports full type conversion for Bool, Float, Int, String and partial type conversion for Vector and Dynamic.

A members type is based on the type used in the first setter to that member. Once a member has it's type set, the type of that member CAN NOT be changed. If a member is accessed using the wrong type, Dynamic will attempt to convert it's value based on the members actual type.

If two types cant be converted by Dynamic a native error is throw with: "Unsupported member datatype"

Int to Bool

  • If the Int value equals 0 the result is false
  • For all other Int values the result is true

Float to Bool

  • If the Float value equals 0.0 the result is false
  • For all other Float values the result is true

String to Bool

  • If the String value equals "false" or "0" the result is false
  • For all other String values the result is true

Bool to Int

  • The Bool value is cast to an Int

Float to Int

  • The Float value is rounded to the closest whole number

String to Int

  • The String value is converted to an Int using Sourcepawn's stock StringToInt() method

Bool to Float

  • The Bool value is converted to Float using float()

Int to Float

  • The Int value is converted to Float using float()

String to Float

  • The String value is converted to an Float using Sourcepawn's stock StringToFloat() method

Bool to String

  • If the Bool value equals true the result will be "True"
  • If the Bool value equals false the result will be "False"

Int to String

  • The Int value is converted to String using Sourcepawn's stock IntToString() method

Float to String

  • The Float value is converted to String using Sourcepawn's stock FloatToString() method

Next: Dynamic Strings