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.

Share This Page

  1. Torgon Woodget

    By:Torgon WoodgetSep 14, 2017
    Member

    Joined:
    Jun 17, 2017
    Messages:
    83
    Likes Received:
    2
    Hi,
    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

    By:AdamSep 14, 2017
    Developer
    Staff Member Moderator

    Joined:
    Aug 21, 2014
    Messages:
    630
    Likes Received:
    113
    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

    By:Torgon WoodgetSep 14, 2017
    Member

    Joined:
    Jun 17, 2017
    Messages:
    83
    Likes Received:
    2
    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)
    end

    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)
    end