Graphics

 View Only
  • 1.  Script question - parse array

    Posted 05-12-2016 14:24
    Good morning,
    I have a map of the US, and I was trying to figure out an easy way for the user to choose which states to highlight. My thought was to enter the desired state abbreviations into a text object (ie: MA, TX, SC) and have a script put those into an array that could then identify which objects to be visible. I'm open to suggestions and/or script ideas.

    Thanks!
    Brian


  • 2.  RE: Script question - parse array

    Posted 05-12-2016 21:05
    After messing around with this, and with some help I have a workable solution... using the "split" function, a for loop and naming my elements properly I came up with the following:

    dim states(49) as string
    dim hilite as xpBaseObject
    dim i as integer

    states = split(text)

    for i = 0 to UBound(states)
    if states(i) <> "" then
    scene.GetObjectByName("Hilite-" & states(i), hilite)
    hilite.visible = true
    end if
    next

    This version uses a space as a delimiter, and the script debugger won't throw an error for a space or incomplete state code. All the user needs to do is enter in the codes of the states they want to display (by default the highlights are off). When no text is entered, the highlights are also off.

    My individual highlight elements are named Hilite-AL, Hilite-CA etc.

    Please let me know if you have a better solution or can improve upon mine. Thanks!
    -Brian
    #XPression


  • 3.  RE: Script question - parse array

    Posted 05-12-2016 23:00
    Your solution is fine. As a programmer, there are a few nit-picky things I might do, but nothing major. The way you did it, I think, also is pretty clear and simple if you pass on your project to another person.

    For the record, though, you don't have to give the number of possible states....

    Dim states() As String = split(text)

    And something to remember is that GetObjectByName() method returns true or false, depending on whether or not it was successful:

    if scene.GetObjectByName("Hilite-" & states(i), hilite) then
    hilite.visible = True
    end if

    That way an error won't stop your script... but then it might be harder to detect the error, also.

    #XPression