I’m trying to create a character generator, and I’m currently stuck on an issue. I’m trying to assign s to a single value picked from the list of possible species, so I can then use that value later for the species displayed and for some species-specific traits. I feel like this should be possible, but I’m also not super knowledgeable in perchance

  • perchance@lemmy.worldM
    link
    fedilink
    English
    arrow-up
    3
    ·
    edit-2
    9 hours ago

    The issue is this line in your lists editor:

    s = [mob.selectOne]
    

    This means that every time you use s it’ll select a new random item from mob. The reason for that is because you’ve made s equal to [mob.selectOne] instead of mob.selectOne. The square brackets around it effectively make it “dynamically fetched” each time you access s.

    You need to add [s = mob.selectOne, ""] in a place where it’ll get “executed” with every “generate” button click, so a new s is generated with each click, but it stays the same when executing all of the other square blocks that come after it.

    So you could add this line before [output] in your HTML editor:

    [s = mob.selectOne, ""]
    

    Each time your “Generate” button is clicked, the update() function is called, and that causes all the square blocks in the HTML code to be executed from top to bottom. So it ensures that we’ve randomly selected a mob item and put it in the s variable before the output list is executed (which uses the s variable).

    Here’s a fixed example: https://perchance.org/ylx7fmwpql#edit

    (This issue has unfortunately been the source of a lot of problems for newbies learning Perchance, so you’re not alone in being confused by this!)

    • BluePower@sh.itjust.works
      link
      fedilink
      English
      arrow-up
      1
      ·
      7 hours ago

      That’s a great answer! I’ve never thought of these solutions in a while, maybe even add a warning for that so other newbies could know easily.