I’m making a random generator that takes a bunch of customizable info, runs some random numbers, and then tosses out some random scenarios based on those. “What percent of the population is affected?” “What are they affected by?” Those things. I’ve learned how to make textboxes (I haven’t learned how to make info not temporary and I just live in constant errors, now, because it shows an error every time there’s an “undefined” box) and I’ve learned how to make multiple dropdown lists. However, when I try to attach outputs to them, it doesn’t work. Attaching a button to it will randomize the output. I want to add a description, so when someone chooses “Option One” they get a short dialogue beside it to give them a feel of what it may be like. Currently, if I have “Option One” chosen and I press the button, the dialogue for Option Eight could appear or Option Three or Option Five just as easily as Option One.

Here’s what the code itself looks like (BTW this is my first generator. I’ve used very basic HTML like embedding links and formatting for years and I’m getting into game design and learning how to use minor C++/Unreal Engine, but I’ve never used JS before)

  • BluePower@sh.itjust.works
    link
    fedilink
    English
    arrow-up
    2
    ·
    edit-2
    10 days ago
    <br>Death Chance: <select oninput="aListName.Death_Chance = this.value">
      <option value="Moral Blow">Moral Blow</option>
      <option value="Tragedy">Tragedy</option>
      <option value="Destruction">Destruction</option>
      <option value="Devastation">Devastation</option>
      <option value="Calamaty">Calamaty</option>
      <option value="Plague">Plague</option>
      <option value="Eradication">Eradiction</option>
      <option value="Extinction">Extinction (WARNING: DON'T) </option>
    </select>
    <p id="out1">[warningList]</p>
    <button onclick="update(out1)">Show</button>
    <br>Illness type: <select oninput="aListName.Illness_type = this.value">
      <option value="Whitecough">Whitecough</option>
      <option value="Carrionplace Disease">Carrionplace Disease</option>
      <option value="Tainted prey">Tainted prey</option>
    </select>
    

    Here is a modified code for the dropdown menus so that they assign the values to the variables properly (since Death_Chance and Illness_type are apparently stored into some sort of parent list, so you can rename aListName to the name of that list). Also, if the dropdown menu doesn’t work, try changing oninput to onchange.

    You’ll also need to associate the variables written in dynamic odd notations in lists to reference the parent list as well (e.g., [Death_Chance == "Moral Blow"] to [aListName.Death_Chance == "Moral Blow"]).

    • VenomQuill@lemmy.worldOP
      link
      fedilink
      English
      arrow-up
      2
      ·
      9 days ago

      Thank you very much for taking the time to help me! I tried this, and it still didn’t work, changing the “false” after the dialogue to “(syntax error)”/ Which, I’m not sure why there’s a false there to begin with. I did the changes you suggested as well as replaced spaces with underscores. The error I’m getting is the same one, but on lines 28 (The Clan will feel this for a long time. [aListName.Death_Chance == “Devastation”] //41-50%) and 35 (Cold weather chest infection, could turn to greencough. [aListName.Illness_type == “Whitecough”]).

      An error has occurred near line number 28: There’s a problem with the syntax of this expression: ‘[aListName.Death_Chance == “Devastation”]’. Here’s the message that was returned when execution failed: Cannot read properties of undefined (reading ‘Death_Chance’). Here are some common mistakes: *you tried to reference a variable/list that you haven’t created *list names are case-sensitive: “[animal]” is different to [Animal], and you should use underscores in list names instead of spaces

      An error has occurred near line number 35: There’s a problem with the syntax of this expression: ‘[aListName.Illness_type == “Whitecough”]’. Here’s the message that was returned when execution failed: Cannot read properties of undefined (reading ‘Illness_type’). Here are some common mistakes: *you tried to reference a variable/list that you haven’t created *list names are case-sensitive: “[animal]” is different to [Animal], and you should use underscores in list names instead of spaces

      • BluePower@sh.itjust.works
        link
        fedilink
        English
        arrow-up
        1
        ·
        edit-2
        9 days ago

        Did you put the Death_Chance and Illness_type variables into a parent list like this?

        someListName
          Death_Chance = Moral Blow
          Illness type = Whitecough
        

        If so, you’d need to change the aListName part of the syntax to reference the name of the sublist:

        <br>Death Chance: <select oninput="someListName.Death_Chance = this.value">
          <option value="Moral Blow">Moral Blow</option>
        ...
        <br>Illness type: <select oninput="someListName.Illness_type = this.value">
          <option value="Whitecough">Whitecough</option>
        

        [someListName.Death_Chance == "Moral Blow"]