I’m trying to use the probability evaluation to look for a value in an array and only select that item if the value is found. I’m running into an issue creating the variable of the array.

['airport','train station','bus stop'].indexOf('airport') 

returns a positive 1 but

travelarray = ['airport','train station','bus stop']
travelarray.indexOf('airport') 

returns -1

Ultimately, I’d have a list like this:

situation 
  generic situation
  something that applies to airport location^[travelarray.indexOf(location) >= 0 ? 100 : 0]
  something that applies to bus station location^[travelarray.indexOf(location) >= 0 ? 100 : 0]

So, first, how do I create a variable array in perchance?

Second, is my if statement for the probability evaluation correct? There will be multiple items that fit each location, and I want generic situations to also be eligible regardless of location.

Thanks!

  • @shantismurfOP
    link
    English
    4
    edit-2
    9 months ago

    Resolved!

    From Discord:

    BluePower — Today at 11:49 AM

    If you were to put the code in the list panel, try this:

    travelarray = [['airport','train station','bus stop']]
    

    It is basically an array inside of the square brackets, if you wrap any value (including functions) with them it’ll be directly assigned into that variable

  • BluePower
    link
    fedilink
    39 months ago

    @shantismurf Try wrapping up the brackets of the array values with another set of brackets, like this:

    travelarray = [[‘airport’,‘train station’,‘bus stop’]]

    Also, you can use location.evaluateItem to get a direct string of the value, so it’ll be a valid filter.