VE Hit Formula - Need help creating a formula please

So I'm using VE Hit Formula and I input the formula 'result = $gameVariables.setValue(491, Math.randomInt(20) + 1); if (v[491] >= b.def){sethit (1.0)} else {sethit (0.0)} '

Essentially this is suppose to recreate the DnD way of handling hits/misses where a d20 is rolled and if the roll is higher than the defending creature, the attack hits.

As you can see, every time the player attacks, the d20 is rolled for Variable 491. Using the debug menu, I can see that yes, Variable 491 'rolls' between 1 - 20, however, when the attacks should hit, they always miss. I'm stumped for now. Any help would be greatly appreciated.

Edit: "result = $gameVariables.setValue(491, Math.randomInt(20) + 1); if (v[491] >= b.def) {result = 100} else { result = 0}" does not work either. The Variable changes every time anyone attacks according to the Console, but for some reason Hit Rate doesn't change :/
where a d20 is rolled and if the roll is higher than the defending creature, the attack hits.
What did the defending creature roll?

Edit: Just noticed your facoring in the enemy creatures deffense. does that have something to do with it?

Edit edit: Ah. You have it set so that lower numbers hit, and higher numbers miss. Switch the > to a < and see if it works as nintended
I
What did the defending creature roll?

Edit: Just noticed your facoring in the enemy creatures deffense. does that have something to do with it?

Edit edit: Ah. You have it set so that lower numbers hit, and higher numbers miss. Switch the > to a < and see if it works as nintended
I have it set so that if the roll is higher than their Defense, then the hit becomes 100%, else it’s 0%, right? That’s how it should be.

anyway, even if I put it lower the hits still always miss. No idea why. :/
Is the enemies deffense higher than the range?
Is the enemies deffense higher than the range?

Nope. However...

After HOURS testing all the different ways you can get it to work, I finally figured it out.

The only correct way of accomplishing it is with this line.

Spoiler: Code
result = Math.randomInt(20)+ 1 >= b.def ? 100 : 0

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/ve-hit-formula-need-help-creating-a-formula-please.123156/