hi. nuublet here.

`let x = “PerchanceListA”

[x]`

how do i have it retrieve PerchanceListA instead of a list named x?

I bet it’s something simple like some evaluateScript thing but i don’t know because I’m a noob :)

  • allo@lemmy.worldOP
    link
    fedilink
    English
    arrow-up
    1
    ·
    edit-2
    18 days ago

    ty tho maybe i missexplained.

    let xx = "Bright"; alert(root[xx])

    in normal javascript, this would access root.Bright. (interesting about ‘root’. didnt kno that)

    The above is what I’m trying to do. I have the word for the name of the list on a variable. Hao access list from variable?

    I have the variable xx storing the string “Bright”. Hao maek alert say a list item from the list named “Bright”?

    • VioneT@lemmy.worldM
      link
      fedilink
      English
      arrow-up
      2
      ·
      18 days ago

      For example on the /minimal generator we have the list:

      listnames
        animal
        adjective
        verb
        location
      

      then on the javascript:

      let x = listnames; // you can also use listnames.selectOne, if you only want it to have a single item and you have to reload the page to randomize it again.
      // This would get a 'random' value from the `listnames`.
      alert((y = x.selectOne) + ':' + root[y]);
      // would give a random item from any of the list 
      
      • allo@lemmy.worldOP
        link
        fedilink
        English
        arrow-up
        1
        ·
        17 days ago

        Thank you! the root thing worked. turns out i had a capital letter where there shouldnt have been one and that’s why my list wasn’t being translated from the string correctly. silly and my fault and nothing about language. thanks for the help tho!