1. The space forums use a separate registration system from the main virtual world. To comment on these forums, you need to create a separate forum account.
    Dismiss Notice
  2. Hey there, we have two Skype groups for space early users - if you're creating content, or need help, feel free to join in either the the beginners or advanced users groups.
    Dismiss Notice

lua enhancement request - casting string to vector and rotation

Discussion in 'General' started by Torgon Woodget, Sep 14, 2017.

  1. Torgon Woodget

    Torgon Woodget New Member

    i would like to see typecasting functions from string to types like vector and rotation, duck-typing sadly doesn't handle it yet.
  2. Adam

    Adam Developer Staff Member Moderator

    Yep - noted, and we'll add some static functions for this purpose. Just be aware, we'd "prefer" people didn't store things this way if possible, but from network/etc it can be unavoidable.

    We'll add array casts as well.
  3. Torgon Woodget

    Torgon Woodget New Member

    I'm using it for broadcast / network, so I need it as string.
    Until there is a function, here are some lua helpers, expecting the format [x,y,z] or [x,y,z,a]

    local string2vector = function(value)
    value = string.gsub(value, " ", "")
    local x,y,z = string.match(value, "%[([%d%.-]*),([%d%.-]*),([%d%.-]*)%]")
    return Vector.New(x + 0.0,y + 0.0,z + 0.0)

    local string2rot = function(value)
    value = string.gsub(value, " ", "")
    local x,y,z,a = string.match(value, "%[([%d%.-]*),([%d%.-]*),([%d%.-]*),([%d%.-]*)%]")
    return Quaternion.New(x + 0.0,y + 0.0,z + 0.0,a + 0.0)

Share This Page