I’m trying to make my current gen in a duplicationfriendly format so ppl can just edit the Starter lists on the left to edit the styles the gen starts with. BUT ITS HARD. I did the accessing the “Starters” list thru root and it definitely has the items as seen below when it runs. but joinitems doesn’t work on the object root gives and nor does it have a length or any way to iterate thru the entries to build an object out of the list entries. How do I get all the entries from the twotiered ‘Starters’ list in to javascript so i can access the info it contains?

  • VioneT@lemmy.worldM
    link
    fedilink
    English
    arrow-up
    0
    ·
    27 days ago

    So what you are trying to do is that after getting the ‘Starter’ from the root["Starter"] you want to combine the subsequent lists into a single sentence? e.g. if the randomly selected starter from root["Starter"] is Foxpony, then you want the lists 0 to 4 to be joined into a sentence, while randomizing between the items under the ‘number’ lists?

    You can do so with the following:

    let starter = root["Starters"].selectOne // gets either Foxpony or Spaceship list object
    let sentence = starter.selectAll // selects all lists under the object i.e. 0 to 4
      .map(list => list.selectOne) // iterates through the lists and selects a random item from them
      .joinItems(" ") // joins the randomized items into a single sentence
    Crystalline.say(sentence)
    
    • allo@lemmy.worldOP
      link
      fedilink
      English
      arrow-up
      0
      ·
      27 days ago

      nevermind. i tried and thought it would be nicer to do in perchancescript but looks like i have to do it in javascript.

      i dont know why this would output 3 instead of foxpony

      off to do it all in javascript i guess. ty for teh help tho

      • VioneT@lemmy.worldM
        link
        fedilink
        English
        arrow-up
        0
        ·
        27 days ago

        Okay, so in your a you have all items from the root["Starter"]. If you use a[0] it would indeed select Foxpony BUT it would also evaluate and select an item on that list, so it would output one of its children (0 to 4) which is why you got 3 as the result. You can get the name of the list with a[0].getName to get Foxpony then use .selectOne to get an item from it which would result to selecting, for example, 1 and it would output an item from under that.