Page 1 of 1

Divide by Zero

PostPosted: Tue Feb 15, 2011 1:06 am
by scorpion972
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

Divide by Zero

PostPosted: Tue Feb 15, 2011 9:47 am
by Trevi
I'm fairly certain that the script runner catches integer overflows - I recall seeing some code indicating it.

Divide by Zero

PostPosted: Tue Feb 15, 2011 12:16 pm
by Jennifer Munroe
The scrips stopped DEAD until I checked and corrected for the divide by Zero issue.

Give it a try yourself!

Divide by Zero

PostPosted: Tue Feb 15, 2011 1:55 am
by Arrogant SId
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.

Divide by Zero

PostPosted: Tue Feb 15, 2011 1:34 pm
by brandon frier
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.

Divide by Zero

PostPosted: Tue Feb 15, 2011 7:10 am
by KiiSsez jdgaf Benzler
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)