Graphics

 View Only
  • 1.  Script to "tear apart" a series of numbers separated by commas

    Posted 08-16-2019 18:44

    NGSS sends shot chart data like this. Does anyone have a script I can use to "tear apart" the x and y data so that I can assign them to object x and y for a graphic representation of shots on a shot chart? Thanks in advance.



  • 2.  RE: Script to "tear apart" a series of numbers separated by commas

    Posted 08-17-2019 02:51

    Pretty straightforward, you want a Split() for this since you've got the data formatted pretty nicely. This script is working off some assumptions, that both your X and Y values will have equal amounts of entries, but I imagine they will. It also assumes that commas will only ever be used to delimit your data, and there is no whitespace between a number and those commas.

    Map that datalinq source to hidden text objects in your scene. Name them XVal and YVal (or whatever you want to call them, just be sure to update the fields in the script) and then you're good to go. It just runs a loop based on the total number of indices it created while sorting through the commas. A Split isn't enough since it will return a string, so the For Loop is there to convert it to double data type. If you need to test the values it's returning, just un-comment in the loop below so you can check the debug monitor. More notes after the script.

    '========================================================================
    'Declare Text Objects that are linked to respective Datalinq entry
    '========================================================================
    dim CoordsX as xpTextObject
    Self.GetObjectByName("XVal",CoordsX)
    dim CoordsY as xpTextObject
    Self.GetObjectByName("YVal",CoordsY)

    '========================================================================
    'Take Text Objects and Split into temporary String Array
    '========================================================================


    dim tempXArray() as String = Split(CoordsX.Text,",")
    dim ArrayX(tempXArray.Length) as Double
    dim tempYArray() as String = Split(CoordsY.Text,",")
    dim ArrayY(tempYArray.Length) as Double

    '========================================================================
    'Converts String Array to Double, but could also use integer
    '========================================================================


    For index as Integer = 0 to tempXArray.Length - 1
    ArrayX(index) = CDbl(tempXArray(index))
    ArrayY(index) = CDbl(tempYArray(index))
    Engine.debugMessage("XY Coords of index " & index & ": (" & ArrayX(index) & "," & ArrayY(Index) & ")",0)
    Next

    '========================================================================
    'Clears temporary arrays (probably not necessary though)
    '========================================================================
    Array.Clear(tempXArray,0,tempXArray.Length)
    Array.Clear(tempYArray,0,tempXArray.Length)

    This is the easy part though. From here I imagine you'll need re-map your coordinates match where you want them to go,though it could be easier to just put all of those objects in a group so these are relative coordinates. You could do that all within the For Loop so after each time it converts it's assigning that value to a position.

    If you're doing simple circles, you could use an APITexture to DrawEllipse/FillEllipse. You could probably get even more in depth with a subsequent If statement that has a corresponding dataset of whether the shots were successful or not that turns the color of those.

    Good Luck!


    #XPression


  • 3.  RE: Script to "tear apart" a series of numbers separated by commas

    Posted 08-20-2019 03:41

    Thanks Martin, that's the project for tomorrow, and perhaps the rest of the week. 


    #XPression