Jump to content
Sign in to follow this  
Fuzzy Bandit

Error: Zero Devisor

Recommended Posts

Hello!

Having a slight problem with one of my scripts...

It works fine when I am the server, but if I host it on a Dedicated Server I get the error below, and the script goes all crazy.

Error: Zero Divisor

Now from the Biki entry it would appear that in my specific code I'm calling an element of an array that doesn't exist... but it should...

Here's some example code (cut down) to show what's going on:

init.sqf

if (isServer) then {
opGunArray = [];
[] execVM "debug.sqf";
};

debug.sqf

for "_c" from 0 to 13 do {
opGunArray set [(count opGunArray), ("D30_RU" createVehicle _pos)];
_gun = (opGunArray [color="Red"]|#|[/color]select _c);
_gun setPos getPos (opGunArray select _c);
};

publicVariable "opGunArray";

The '|#|' is where the error is appearing.

Cheers!

Share this post


Link to post
Share on other sites

How big is your array? 13 Guns? You've done 14 iterations. (0,1,2,3,4,5,6,7,8,9,10,11,12,13 == 14 numbers)

It means your selecting out of bounds.

Share this post


Link to post
Share on other sites

Surely though, in that piece of code, there shouldn't be any problems?

First time through For loop:

opGunArray = ["D30_RU" createVehicle _pos];
_gun = (opGunArray select 0);
_gun setPos getPos (opGunArray select 0);

Second time through For loop:

opGunArray = ["D30_RU" createVehicle _pos, "D30_RU" createVehicle _pos];
_gun = (opGunArray select 1);
_gun setPos getPos (opGunArray select 1);

And so on and so forth. Surely I'm simply selecting them as I make them? I don't see why I'd be 'overshooting' as it were?

Share this post


Link to post
Share on other sites

Well, your code seems to work when I tested it (modified of course). Just clarify for me; is there more to debug.sqf? I ask because _pos is undefined in your code.

Other than that, it should work. Have you tried printing the values of opGunArray and your other variables? It should help you debug the problem. I mean the array might not be getting populated properly or something, so check all your variables or the return values of all your expressions. It might also be something in another part of the code that doesn't give you an error but messes with your variables, which is why it's always a good idea to check their values when debugging.

Share this post


Link to post
Share on other sites

There is more, but absolutely nothing that would interfere with the array. I just do a few things to _gun. And apologies - _pos is identified in the full code as:

_pos = getMarkerPos "opSpawn";

When I get the chance I'll put some fun hint format debug code around the shop and see what's what.

The really annoying thing is that it works absolutely flawlessly when I am the host. But if I slap it on a dedicated server it gives me that error and spawns roughly three times as many guns as it should and generally everything goes to hell.

I thought it might be a speed thing, so I tried putting a small wait of 0.1 seconds in between adding to the Array and selecting the next element in it. Didn't seem to help much - just slowed the process ever-so-slightly. :P

Cheers for the help!

Share this post


Link to post
Share on other sites

The really annoying thing is that it works absolutely flawlessly when I am the host. But if I slap it on a dedicated server it gives me that error and spawns roughly three times as many guns as it should and generally everything goes to hell.

Read the bold part again.

You are running the script on every client including the server (locality issue).

I must admit that I have never ever used the MP mission editor or tested my missions or scripts in a hosted environment because of the problems it can cause.

Xeno

Share this post


Link to post
Share on other sites

That sounds feasible, but how can that happen if I use the (isServer) code inside the init.sqf?

e.g.

if (isServer) then {
[] execVM "debug.sqf";
};

I understand the concept, but not sure how it's possible that it's running on all clients. I've trawled through all the code - there's nothing that initiates debug.sqf for anything but the server.

Besides, you must do some testing!

Or have you got to a point now where you write 5000 lines of code, load up the game and you've got your newest version of Domination? :P

Cheers!

Share this post


Link to post
Share on other sites
I understand the concept, but not sure how it's possible that it's running on all clients. I've trawled through all the code - there's nothing that initiates debug.sqf for anything but the server.

No idea without seeing the rest of your mission or code.

Besides, you must do some testing!

Or have you got to a point now where you write 5000 lines of code, load up the game and you've got your newest version of Domination? :P

Basically yes. Most of the time I do not have ArmA 2 started but only my script editor.

Once all changes are in I do a first test in the mission editor (preview), when there are no errors the next step would be a test on a dedicated server. Though that doesn't allways happen.

It's just a question of experience. Once you have "mastered" things like locality or JIP, the rest is easy (beside working around game bugs).

But it takes a long time to get to such a point and it doesn't make you "immune" against bugs.

Xeno

Share this post


Link to post
Share on other sites

Well I'm using the 'Find in Files...' search tool in Notepad++ and the only place 'debug.sqf' can be found is in the init.sqf, under the (isServer) command.

Upon further testing, it seems it's actually the beginning part of the code that's causing problems. For the moment it just seems to stop on the culprit line, ignoring it everything below it. Highlighted in red.

//Define position variables
_pos = getMarkerPos "opShipSpawn";
_regpos = getMarkerPos "opRegOffice";

//Reset opGunArray to an empty Array
opGunArray = [];
publicVariable "opGunArray";

//Create the OPFOR Plane
opship = "C130J" createVehicle _pos;
opship setDir 120;
opship setPos getPos opship;
opship setFuel 0;
[color="Red"]opship addAction ["Engage Thrusters", "blastoff.sqf"];[/color]

//Create the OPFOR Ship
opmain = "Land_Destroyer" createVehicle _pos;
opmain attachTo [opship, [0, -35, 0]];
this2 = [opmain,10,time,false,false] spawn BIS_Effects_Burn;

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  

×