Jump to content
Sign in to follow this  
dreadedentity

Error zero divisor & Generic Error

Recommended Posts

So I'm making a small script that will display icons over the heads of units you specify (by classname). Commented where I get errors.

MISSION_ROOT = call {
   private "_arr";
   _arr = toArray __FILE__;
   _arr resize (count _arr - 8);
   toString _arr
}; //Kudos to Killzone_Kid for this

enemies = [];
{
enemies pushBack _x;
}forEach (allMissionObjects "O_SOLDIER_F"); //comment this forEach statement out and all is right
{
enemies pushBack _x;
}forEach (allMissionObjects "O_OFFICER_F");

onEachFrame
{
{
	_iSize = (0.5) - (0.01 / (player distance _x));
	hintSilent format ["%1", player distance _x];

	_unitPos = [(getPos _x) select 0, (getPos _x) select 1, ((getPos _x) select 2) + 2];
//		if (!alive _x) then //generic error here for some reason
//		{
		drawIcon3D[MISSION_ROOT + "target.jpg", [1,1,1,0.5], _unitPos, _iSize, _iSize, 0, "Kill"];
//		};
}forEach enemies;
};

Not sure why the first forEach throws an "Error Zero Divisor" error. Also not sure why my alive check throws a generic error. Any help is appreciated.

You can download "target.jpg" here (Dropbox)

EDIT: How do I use the passed arguments with BIS_fnc_addStackedEventHandler? I rewrote this code using it because of the overwrite issues Larrow explained to me.

MISSION_ROOT = call {
   private "_arr";
   _arr = toArray __FILE__;
   _arr resize (count _arr - 8);
   toString _arr
}; //Kudos to Killzone_Kid for this

_enemies = [];
{
_enemies pushBack _x;
}forEach (allMissionObjects "O_SOLDIER_F"); 
{
_enemies pushBack _x;
}forEach (allMissionObjects "O_OFFICER_F");

["eachFrame", "onEachFrame", 
{
_enemies = _this select 3; //Error Zero Divisor because _this select 3 doesn't exist
{
	_iSize = (0.5) - (0.01 / (player distance _x));
	hintSilent format ["%1", player distance _x];

	_unitPos = [(getPos _x) select 0, (getPos _x) select 1, ((getPos _x) select 2) + 2];
//		if (!alive _x) then
//		{
		drawIcon3D[MISSION_ROOT + "target.jpg", [1,1,1,0.5], _unitPos, _iSize, _iSize, 0, "Kill"];
//		};
}forEach _enemies;
}, [_enemies]] call BIS_fnc_addStackedEventHandler;

EDIT2: I replaced _this select 3 with _this select 0 and everything seemed to work fine, but there's now an "Error Zero Divisor" error in _iSize = (0.5) - (0.01 #/ (player distance _x)); (error location shown with "#" just like how -showscripterrors works). Uncommenting the alive check breaks everything again.

Edited by DreadedEntity

Share this post


Link to post
Share on other sites

Well I don't see where ths zero divisor comes into this code, but here is the page on that error: https://community.bistudio.com/wiki/Error_Zero_Divisor

And I think both your erros may be linked in a way, because the if statement is trying to pull from the array that seems to be getting undefined in a way, somehow. But I'm just talking out my a$$, what can I say, other than I hope that my mind is working in the right direction :p.

Share this post


Link to post
Share on other sites

The only thing I can think of is the pushback command, it seems simple enough, but does it do as it says? Maybe try a good op' classic count of the unit, then add into the array, similar to what I have for my redress script.

Share this post


Link to post
Share on other sites

Changed my pushBack's to "_enemies set [count _enemies, _x];" then previewed again. It seems the first "Error Zero Divisor" was being caused by using a normal onEachFrame function because now that I'm using a stacked event handler, that error cleared up and the swapped code had no effect. Error Zero Divisor still exists in the "_iSize" variable declaration.

EDIT: I was only using pushBack because it's about 43% faster than set (read notes)

Edited by DreadedEntity

Share this post


Link to post
Share on other sites

Ok, well the only reason why I would think that would come up is that player is not defined so calling for the distance of that player from _x is also returning undefined, and since no one has figured out how to divide by zero yet... :p

Maybe to test just name your player something (varname) and replace your players in the script with that name and see if it still pops up, and if it does then there is a logic error or something of the sorts somewhere in the code (always a pain to find).

Share this post


Link to post
Share on other sites

When are you running this? maybe worth placing in a time > 0 right at the top just to make sure the mission is up and running.

As JShock says, may all just be a timing issue and things are not initialized properly.

In you code for onEachFrame try wrapping everything in the foreach in the IF instead of just the drawIcon, why bother even finding the distance if your not going to draw the icon. Maybe even add a isnull check to the IF just to make sure nothing funky is being passed. Also your not one of the units are you ? just for testing? as player distance player will be divide by zero, just a thought.

Share this post


Link to post
Share on other sites

As JShock says, may all just be a timing issue and things are not initialized properly.

I'll take being partially correct than completley and utterly wrong any day :p.

Share this post


Link to post
Share on other sites

Not sure if it was a timing issue like you guys said but adding waitUntil {time > 0}; at the beginning of the script didn't/couldn't hurt.

@Larrow I actually was a "O_SOLDIER_F" while testing, because I didn't want to get shot at. So it makes sense that (player distance player) = 0

I'm going to throw some more things around in here and then I'll probably release it in 1-2 hours.

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  

×