Jump to content
Sign in to follow this  
csj

Error Zero Divisor

Recommended Posts

I am trying to set damage on all crew in vehicle for given status quo of vehicle.

Anyway the code worked on player and driver _vehicle etc

but I want to do the whole group session thing.

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_vehicle = _this select 0

_crew = crew _vehicle

_c = count _crew

_i = 0

-(bla bla bla)-

#loop

_unit = _crew select _i

_unit setdammage _VehStatus

_i = _i + 1

?_i < _c: goto "loop"

goto "eslewhere"

-(bla bla bla)-

_unit = _crew select _i -  gives err "Error Zero Divisor"

Why is it so ?

I have simular/same setup in other scripts with no problems.

Share this post


Link to post
Share on other sites

Zero Divsor is always down to trying to select an array element that does not exist. Try changing your script to:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_c = count _crew

If (_c>0) Then {_c=_c-1} Else {goto "elsewhere"}

_i = 0

It's the age old problem of combining Count with arrays that start indexing from 0. If you don't need to add a pause between each line, use the foreach command. It avoids you having to include all the counts, re-indexing and empty array checks.

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_vehicle = _this select 0

_crew = crew _vehicle

-(bla bla bla)-

{_x setdammage _VehStatus} ForEach (_crew)

goto "eslewhere"

-(bla bla bla)-

Share this post


Link to post
Share on other sites

biggrin_o.gif woohoo cool bananas

Thanks UNN, that's another one I owe yah wink_o.gif

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×