Results 1 to 8 of 8

Thread: getSnapPoints Error

  1. #1
    Join Date
    May 2020
    Location
    on the earth
    Posts
    112

    getSnapPoints Error

    if you call getSnapPoints() to an object, which has no snap points an error is thrown. this wasnt the case before the update.

    I also dont get it, why setSnapPoints() is now scale independent. it wasnt the case before.
    It is very inconsistent and makes programming more difficult if some functions depend on the scaling of the object and then others do not.

    From my point of view no Set Funktion with its dependend on an object should be effected by the scale value. After the set call, its makes sense, that for example a button is scaled with the object, but not at the point of creation (set call).

  2. #2
    Join Date
    Sep 2017
    Posts
    397
    getSnapPoints had a bug which has been corrected. you should expect no further changes to the scaling issue. As to the error on a getSnapPoints() call on an object without snapPoints, I agree this is a bug;
    I would expect this to return an empty table.

    For the devs, here is an example:
    Code:
    function onLoad(statstr)
        log(getObjectFromGUID("72e9cf"))
        log(getObjectFromGUID("72e9cf").getSnapPoints())
    end
    produces
    Code:
    <Custom_Tile>〔72e9cf〕turnButton
    Error in Script (Global) function <onLoad>: Object reference not set to an instance of an object

  3. #3
    Anyone know a workaround for dealing with the error?
    I've created a tool that generates an array of snap points on an object (or Global), but in order to preserve any snap points that may already exist, I need to call getSnapPoints in my script. If there aren't any snap points, then I get the error and the tool doesn't work. (A workaround is to just place a temporary snap point on the object, and then delete it manually later, but that's annoying.)

  4. #4
    Join Date
    Sep 2017
    Posts
    397
    Your suggestion won't work if there are already snap points, they will be lost. What you can do for non-global is objInfo = object.getData() this will return a table with everything about the object, so you can then check #objInfo.snapPoints to see how many are there. Should probably log(objInfo) to be sure I have the right name for the table of snapPoints on it.

    getData is a recent addition to TTS API, would have had to look at getJSON before and parse the string result. Note that setSnapPoints replaces the snapPoint list, so you need to table.insert any new snapPoints into the result of getSnapPoints or objInfo.snapPoints.

  5. #5
    Yeah. table.insert is exactly what I used, so the tool works fine provided a snap point already exists.

    object.getData() gave me the workaround I needed for objects. Thanks! Snap points are stored under the key AttachedSnapPoints. I can avoid the error by not calling getSnapPoints when objInfo.AttachedSnapPoints is nil. Do you know of a similar workaround I can use to determine whether or not snap points exist on Global?

  6. #6
    Join Date
    Sep 2017
    Posts
    397
    Only way I can think of is to know whether there are snap points at initial load. If you control the mod, you just make a snap point somewhere, so there will always be at least one. (test this!) If the snap point you made is not detected, then you know that at onLoad() there will be none, and can operate accordingly.

  7. #7

    Unhappy

    Somewhat related -- am I just wrong in expecting this to have similar behavior as VectorLines with rotation? Rotation doesn't seem to do anything with snap points, resulting in a bunch of overlayed points. If there's a solid method of rotating about the y-axis, like you might do to procedurally generate the seat snaps, thanks in advanced.
    Code:
    function onLoad()
        --[[ print('onLoad!') --]]
        snappoints = {}
        snappoints[#snappoints+1] = {position = {3,1,3},
            rotation = {0,45,0},}
        snappoints[#snappoints+1] = {position = {3,1,3},
            rotation = {0,45,0},}
        snappoints[#snappoints+1] = {position = {3,1,3},
            rotation = {0,180,0},}
        snappoints[#snappoints+1] = {position = {3,1,3},
            rotation = {45,0,0},}
        snappoints[#snappoints+1] = {position = {3,1,3},
            rotation = {180,0,0},}
        snappoints[#snappoints+1] = {position = {3,1,3},
            rotation = {0,0,45},}
        snappoints[#snappoints+1] = {position = {3,1,3},
            rotation = Vector(0,0,180),}
        for i,v in next, snappoints do
            print(i,' ',v.position,' ', v.rotation)
        end
        self.setSnapPoints(snappoints)
        ret_snappoints = self.getSnapPoints()
        for i,v in next, ret_snappoints do
            print(i,' ',v.position,' ', v.rotation)
        end
        --[[ results - all snappoints are identical in both GUI and data
    2       Vector: { 3, 1, 3 }	 	Vector: { 0, 0, 0 }
    1	 	Vector: { 3, 1, 3 }	 	Vector: { 0, 0, 0 }
    5	 	Vector: { 3, 1, 3 }	 	Vector: { 0, 0, 0 }
    3	 	Vector: { 3, 1, 3 }	 	Vector: { 0, 0, 0 }
    4	 	Vector: { 3, 1, 3 }	 	Vector: { 0, 0, 0 }
    6	 	Vector: { 3, 1, 3 }	 	Vector: { 0, 0, 0 }
    7              Vector: { 3, 1, 3 }	 	Vector: { 0, 0, 0 }
    --]]
    end

  8. #8
    Join Date
    Sep 2017
    Posts
    397
    Try adding rotation_snap = true to each of the setSnapPoints entries: I am guessing that the rotation is ignored unless rotation_snap is true.

    - - - Updated - - -

    Also, I would guess that only the y entry in the rotation is meaningful.

Similar Threads

  1. [SUPPORT] WWW Image Error: Unknown Error <2>. Happens even with no firewall or antivirus
    By TrippinJim in forum Technical Support
    Replies: 5
    Last Post: 06-21-2020, 09:07 PM
  2. getSnapPoints returns wrong coordinates
    By Blackclaws in forum Scripting Bug Reports
    Replies: 3
    Last Post: 05-18-2020, 02:52 PM
  3. Replies: 1
    Last Post: 05-15-2020, 05:52 PM
  4. [CRASHES] WWW TXT Error, WWW Image Erro, Error Steam read from Workshop
    By M1ndFr3ak in forum Technical Support
    Replies: 0
    Last Post: 04-10-2020, 01:53 PM
  5. Replies: 3
    Last Post: 04-18-2017, 01:58 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •