Line 45-49, I am trying to make it do math, and then go to $output. I’ll put an example here of what is currently happening, and then what I am trying to achieve.

Current:

You are trying to convince a guard to let you into a restricted area.

Difficulty: 60

Skill: Charisma

undefined + undefined = undefined

Expected example:

You are trying to convince a guard to let you into a restricted area.

Difficulty: 60

Skill: Charisma

50 + 22 = 72

On line 47 there is also a more specific issue, according to the red line highlighting it. The text ai was used to generate something like “Skill: Charisma” earlier in the code. Then on line 47, it is getting rid of the "Skill: " so all that remains is “Charisma”. There was a variable set at line 11 which shows the value of “Charisma”.

Hopefully I explained this well enough. Thank you for your assistance everyone!

(Edit: Put a line break in the output, to more closely match the output from the program)

  • VioneTM
    link
    English
    223 hours ago

    Since the ai generation is not synchronous, accessing its value before the value is generated would throw errors. You can add a onFinish on your AI generation to only run the function after all AI generation are generated. Here is a working example: https://perchance.org/029ghm63yp

    • @McnzOP
      link
      English
      121 hours ago

      Thanks, that helps a lot! It seems that the challenge “difficulty” and the dice “roll” always come out to the same number? I cant quite tell why. Do you know? I’m looking through the code, but a lot of this stuff is new to me, so I’ll try to take a look through it again tomorrow to maybe understand it better.

      Either way, this is a big leap forward for me. Thanks!

      • VioneTM
        link
        English
        1
        edit-2
        21 hours ago

        I was setting the check.roll to the difficulty that was generated. I guess it was not intended that way in which the roll is separate from the difficulty. You can change the section on the difficulty:

        difficulty
          async onFinish(data) =>
            // check.roll = Number(data.text.replace("Difficulty: ", "")) // comment this out
            outputEl.innerHTML += ai(skill)
        

        I’ve updated the code I’ve linked.

        • @McnzOP
          link
          English
          121 hours ago

          Thank you! I could have been more clear about my code lol. I was trying to get the LLM to think of how difficult a task would be. Then the player would roll a d100, and add their skill, to see if they succeed.