Weird Behaviour with subtraction in a script

Post » Wed Jun 20, 2012 1:22 pm

I haven't posted the scripts because i don't think the issue lies with the scripts and also each weapon has its own script and im not really posting here for a fix to the script.

This is a brief overview of what they do.

I wanted to create a weapon set for dual wielding, that had individual benefits but when both swords were used had an additional bonus.

The right hand sword has a 25% chance to increase the wearers armour rating by 50% for 10 seconds with a 30 second cooldown.
This works without any issue

The left hand sword has a 10% chance to increase the weapon speed of either hand by 50%. (The chance for each hand is independant) weaponspeedmult is set to 1.5

If the weapon speed is increased, subsequent hits from the weapon that has the speed increase decreases the weapon speed by 20% of the increase. Weaponspeedmult is decreased by 0.1 should after 5 hits reduce back to 1

This in itself works most of the time, however the issue is that the script sometimes decreases it by 0.100001 or on occassions by 0.099999. Therefore the weaponspeedmult never returns back to 1.

The bonus that is given, when both swords are equipped, is that if both swords have weaponspeedmult>1 the wielder has 2% of base health restored.

I have put a fix in place to correct the subtraction issue, but was wondering if anyone could give a valid reason as to why a seemingly simple task such as (1.5 - 0.1) cannot be calculated accurately 100% of the time.
User avatar
Amie Mccubbing
 
Posts: 3497
Joined: Thu Aug 31, 2006 11:33 pm

Return to V - Skyrim