Divide by Zero

Post » Tue Feb 15, 2011 1:06 am

Ok I know this is going be obvious to most of you, but this slipped by me and when some modders tried to help me (good modders far better than I am ) they missed this as well.

I had a few mods that would mysteriously stop dead. The script would just stop working. Sometimes this took a few weeks to happen sometimes only a few days.
I discovered that a calculation I was doing was trying to (on rare occasions) divide by zero.

SIMPLE example of what I am talking about:

set Numb to ( 10 + player.getav encumbrance ) / player.getav strength

Seems ok but under some circumstances the players strength CAN be brought down to ZERO.
So the lesson to me was Dividing by Zero is the silent killer but sometimes it is not obvious.

To solve this I did this sort of thing:

set Numb to player.getav strength
if Numb > 0
set Numb to ( 10 + player.getav encumbrance ) / Numb
else
set Numb to 0
endif

I will do this from now on with ANY calculation that divides unless I am absolutely positive no Divide by zero can occur.

Is this issue talked about in the Wiki? I did a search here on the Bethesda CS forums and did not find it
User avatar
scorpion972
 
Posts: 3515
Joined: Fri Mar 16, 2007 11:20 am

Post » Tue Feb 15, 2011 9:47 am

I'm fairly certain that the script runner catches integer overflows - I recall seeing some code indicating it.
User avatar
Trevi
 
Posts: 3404
Joined: Fri Apr 06, 2007 8:26 pm

Post » Tue Feb 15, 2011 12:16 pm

The scrips stopped DEAD until I checked and corrected for the divide by Zero issue.

Give it a try yourself!
User avatar
Jennifer Munroe
 
Posts: 3411
Joined: Sun Aug 26, 2007 12:57 am

Post » Tue Feb 15, 2011 1:55 am

I believe all the runtime catch does is to kill the faulty script to avoid the whole game crashing. At best you'd get a faulty result that would give you other errors.

So it's well worth preventing if you need the script to continue.
User avatar
Arrogant SId
 
Posts: 3366
Joined: Sat May 19, 2007 11:39 am

Post » Tue Feb 15, 2011 1:34 pm

The scrips stopped DEAD until I checked and corrected for the divide by Zero issue.

Give it a try yourself!
My post was incorrectly formed; I apologize. I didn't mean to say that you were wrong.

Like ghastly suggested, the game probably halts the delinquent script. You should ask scruggsy - He (or the other devs) might be able to confirm.
User avatar
brandon frier
 
Posts: 3422
Joined: Wed Oct 17, 2007 8:47 pm

Post » Tue Feb 15, 2011 7:10 am

Yeppers -- This is also why many systems have the Bow Reach crash when equipping a high level bow --- Beth left some of the higher level bows with a reach = 0 and then they used the reach in the divisor in some scripts ---- some systems crash due to this while others somehow do not (not sure exactly why)
User avatar
KiiSsez jdgaf Benzler
 
Posts: 3546
Joined: Fri Mar 16, 2007 7:10 am


Return to IV - Oblivion