ThePix / QuestJS

A major re-write of Quest that is written in JavaScript and will run in the browser.
MIT License
66 stars 12 forks source link

RPG Library Problems #79

Closed GoldenEagle75 closed 1 year ago

GoldenEagle75 commented 1 year ago

Hello again,

I am currently having some trouble with the RPG Library, specifically the armour attribute of the player.

I am following the tutorial and I find that for some reason, once the enemy attacks and hits the player, it says that "the attack does NaN hits, your health is now NaN". The damage roll of the goblin appears to work fine, but the problem comes once it reaches the target's armour. It states, "Target's armour is NaN".

Attacking the goblin appears to work fine.

GoldenEagle75

ThePix commented 1 year ago

Just to first check the obvious, does the player object use the RPG_PLAYER template, rather than PLAYER?

Also, check all the items the player is wearing. For each item, it should either have no "armour" attribute, or it should be a number (with no quotes).

Failing that, if you go into the console, and type:

player.getArmour()

What happens?

GoldenEagle75 commented 1 year ago

It uses RPG_PLAYER. The player wears no armour (or anything for that matter).

After typing player.getArmour() in the console, I get "NaN".

ThePix commented 1 year ago

That is weird. What happens if you type player.getArmour (no brackets) in the console? You should see this:

ƒ () {
    const garments = scopeHeldBy(this).filter(el => el.worn)
    let armour = 0
    for (let el of garments) armour += el.getArmour()
    return armour / settings.armourScaling
  }

If you do not, can you do a search of the entire QuestJS folder to see where the function is defined? You should see it in rpg/npc_templates lines 113 and 172, and in lib/_templates line 433, and I guess somewhere else as well, and that extra definition is getting used.

GoldenEagle75 commented 1 year ago

That is exactly what I get, word for word.

ƒ () {
    const garments = scopeHeldBy(this).filter(el => el.worn)
    let armour = 0
    for (let el of garments) armour += el.getArmour()
    return armour / settings.armourScaling
   }

It appears to get this function from the file npc_templates.js, lines 172-177.

ThePix commented 1 year ago

Ah, looks like settings.armourScaling is not set. Towards the top of rpg/rpg.js, say at line 3, add this line:

settings.armourScaling = 10

I will likewise update the code on GitHub at some point, but that should sort you out.

GoldenEagle75 commented 1 year ago

Thank you! This entirely fixed the problem.