OFPEC Forum

Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: Lone~Wolf on 25 Mar 2010, 22:13:38

Title: Not more Zero Divisor Errors!
Post by: Lone~Wolf on 25 Mar 2010, 22:13:38
 :weeping: :weeping: :weeping:

I am on the point of mental collapse,

I have a set of scripts that each activate one another, and each time my person dies, I get an "Error! Zero Divisor!" error.

I have done an OFPEC search and have tried every solution I have found to similar previous problems, but NONE WORK!

   Very much in dispair,
        Lone-Wolf

Code: [Select]
[a1,aresp1,cgrp0] exec "TV_IndieAmbioSymbiot_Crawler.sqs"
Code: [Select]
~1
#BEGIN
direction = preprocessfile "direction.sqf";
closesttarget = preprocessFile "closesttarget.sqf";
_c = _this select 0
_resp = _this select 1
_agrp = _this select 2
? (_agrp == nil) : goto "BEGIN"
[_c,_resp,_agrp] exec "TV_IndieAmbioSymbiot_Crawler_Health.sqs"

Code: [Select]
#START
~1
_c = _this select 0
_resp = _this select 1
_grp = _this select 2
_dcount = 0
_drand = (3+(random 3))
_c setdammage 0.7
_c addrating (-(rating _c)-10000)


#LOOP
@ ((getdammage _c > 0.85) || (getdammage _c < 0.7))
_c setdammage 0.8
_c switchmove "CivilLyingPutDownToCivilLying"
_dcount = _dcount +1
?_dcount > _drand: goto "DIE"
goto "LOOP"


#DIE
_c setdammage 1
~((random 2)+3)
"Bullet4x23" createvehicle (position _c)
deletevehicle _c
[_resp,_grp] exec "Tv_SPAWN.sqs"
exit

Code: [Select]
_obj = _this select 0
_cgroup = _this select 1
"Civilian3" createunit [(position _obj),group _cgroup,"[this] exec {TV_IndieAmBioSymbiot_Crawler.sqs}", 0.6, "corporal"];
exit

Each piece of code above corresponds to the relevant part of the next script in the sequence.

Also, if anyone sees any errors in any other part of the scripts, please let me know.
Title: Re: Not more Zero Divisor Errors!
Post by: RKurtzDmitriyev on 25 Mar 2010, 23:29:06
I can't seem to see your attachments. ???

Preliminary comment: You probably already know this, but "zero divisor" errors are often caused when the select command is used with a number greater than or equal to the number of elements in an array. E.g., the following code will probably lead to a zero divisor error:

Code: [Select]
_array = [blah1, blah2, blah3]
_thing = _array select 3
Title: Re: Not more Zero Divisor Errors!
Post by: haroon1992 on 26 Mar 2010, 22:27:47
I am also facing that same problem but mine is with the primary arguments.
[unitname,carname,damagename,timename] exec "damagecar.sqs"

_unit=_this select 0;
_car=_this select 1;
_damage=_this select 2;
_timedamage=_this select 3;
if (isNil "_damage") then {_damage=0.1};
if (isNil "_timedamage") then {_timedamage=11};
#loop
if (_timedamage ==0) then {exit};
_car setdammage getdammage _car + _damage;
_timedamage=_timedamage - 1;
~1
goto "loop"

As you can see the above script damages the car within the given time.
The problem is if you left both the damage and timedamage empty in the arguments
e.g    [player,jeep1] exec "damagecar.sqs"
An error popped out and says
"_timedamage=_this
error : zero divisor"
(Is there any solutions to this problem?)
Regards,
Haroon1992
Title: Re: Not more Zero Divisor Errors!
Post by: RKurtzDmitriyev on 26 Mar 2010, 23:01:38
The problem is if you left both the damage and timedamage empty in the arguments....

(Is there any solutions to this problem?)

Don't do that? :whistle:

Sorry, I couldn't resist. :D

First of all, isnil (http://www.ofpec.com/COMREF/index.php?action=details&id=605&game=All) is an ArmA command. This is the OFP scripting board.

If your script was intended for OFP, or if ArmA scripting is similar to OFP (which it is, as far as I've heard), then I think I know your problem. The zero divisor is caused by this line:

Code: [Select]
_timedamage=_this select 3;
_this is the array of arguments passed to a script. Therefore, if you only put 2 arguments in the script, select 3 is going to cause an error. OFP often gives zero divisor errors in this situation, as I described above.
Title: Re: Not more Zero Divisor Errors!
Post by: Lone~Wolf on 27 Mar 2010, 12:05:29
Thanks for all your help guys,  :D

I worked around my problem quite easily enough, but did so without touching upon the source of the error.
In other words, I resorted to using a totally different method that did not deal with any zero-divisor errors.

Hopefully this topic will help others in combatting their arch nemesises,

THE DREADED ZERO DIVISOR  ;)
Title: Re: Not more Zero Divisor Errors!
Post by: haroon1992 on 29 Mar 2010, 12:31:14
how did you solved it?