Jump to content
Sign in to follow this  
lawman_actual

Stored array being corrupted?

Recommended Posts

Well I'm stumped.

As part of my script I'm using arrays to store information about who's doing what:

//	

       Objective:	        [  1,  2,  3,  4,  5,  6,  7,  8,  9,  10,  11,  12,  13]
condition = 	[  1,  1,  1,  1,  1,  0,  0, -1, -1,  -1,  -1,  -1,   0];
redarray =  	[  0,  0,  0,  0,  0,  0,  0,  0,  0,   0,   0,   0,   0];
bluearray = 	[  0,  0,  0,  0,  0,  0,  0,  0,  0,   0,   0,   0,   0];
usattacking = 	[  0,  0,  0,  0,  0,  0,  0,  0,  0,   0,   0,   0,   0];
opattacking = 	[  0,  0,  0,  0,  0,  0,  0,  0,  0,   0,   0,   0,   0];

speak = usattacking;

The 'speak' line is there because I suspected the array was somehow not behaving as expected. I have a trigger that side Chat's "speak".

But when I do this, the array doesn't return as expected (all zeros)

Instead, I get the following:

[0,0,0,0,0, Scalar NaN, Scalar NaN, 0,0,0,0,0,Scalar NaN]

What the *bleep* could cause the values to change like this?

---------- Post added at 18:45 ---------- Previous post was at 17:59 ----------

Help please :rolleyes:

Share this post


Link to post
Share on other sites

Like both guys above wrote, it's hard to tell because you basically give us no other info than:

"my array values are getting changed to Scalar NaN and I don't know why"

Share this post


Link to post
Share on other sites

Fair point. Guess I was tired >_<

Here's a bit more of the .init. There's a big gap in it that won't make much sense because I was in the middle of copying a script I wrote separately into it

init.sqf:

//***** MISSION STARTUP *****//

chosenside = 1;

obj = 0;

initAmbientLife;	


usattacking = 	[  0,  0,  0,  0,  0,  0,  0,  0,  0,   0,   0,   0,   0];
opattacking = 	[  0,  0,  0,  0,  0,  0,  0,  0,  0,   0,   0,   0,   0];





//*****GENERIC DEPLOYMENT SCRIPT*****//



//___US DEPLOYMENT___/

//US VEHICLES = ["B_MRAP_01_F","B_APC_Wheeled_01_cannon_F","B_Heli_Transport_01_camo_F","B_Truck_01_transport_F"];
//		(HUNTER)	(MARSHALL)		   (UH-80)			(HEMTT)




for "_i" from 0 to 15 do {


player setPosATL [20000,20000,500];

if (ustickets <= 11) then {setchoice = [4,8];} else {};

	if (ustickets < 8) 
	then {setchoice = [4];}
	else {setchoice = [4,8,12];};

setchoice = setchoice call BIS_fnc_selectRandom; 



if (setchoice == 4) then {_h_vehicle = 1;} else {

			if (setchoice == 8) then {_a_vehiclechoice = [2,3];_h_vehicle = _a_vehiclechoice call BIS_fnc_selectRandom;}	else {_h_vehicle = 4;};

};




													//[VEHICLE 4: HEMTT]





for "_x" from 1 to 20 step 1 do {

_register = 12;
_alist = usstarts;

				_subject =  [_alist call BIS_fnc_selectRandom];

				_trial = (markerlist find (_subject select 0));


						if (((usattacking select _trial) + _register) <= maxatobj) then {numbhandle = _trial; _x = 20;} else {_alist = _alist - _subject;};



			};															


newobj = markerlist select numbhandle;
_current = usattacking select numbhandle;

_new = _current + _register;
usattacking set [numbhandle, _new];











//END OF FOR I FROM//
};

Edited by Lawman_Actual
Making easier to follow

Share this post


Link to post
Share on other sites

Read about the difference between modifying arrays by reference and making array copy.

Share this post


Link to post
Share on other sites

I'm not sure I follow you?

These are the only times I reference us attacking after creating the array and assigning speak to it:

if ((([b]usattacking select _trial[/b]) + _register) <= maxatobj) then {numbhandle = _trial; _x = 20;} else {_alist = _alist - _subject;};

_current = [b]usattacking select numbhandle[/b];

[b]usattacking set [numbhandle, _new];[/b]

I don't see where I would need to make a copy

---------- Post added at 19:02 ---------- Previous post was at 18:46 ----------

I think I see what you're saying now.

I had been modifying usstarts which was throwing things off with usattacking.

Many thanks Killzone! Here's the script that seems to be working (though I'm sure it isn't flawless)


for "_x" from 1 to 20 step 1 do {

register = 12;
_alist = +usstarts;

				_subject =  [_alist call BIS_fnc_selectRandom];

				_trial = (markerlist find (_subject select 0));


						if (((usattacking select _trial) + register) <= maxatobj) then {numbhandle = _trial; _x = 20;} else {_alist = _alist - _subject;};



			};															





newobj = markerlist select numbhandle;
_current = usattacking select numbhandle;

_new = _current + register;
usattacking set [numbhandle, _new];

_x = 20;

//END OF FOR I FROM//
};

Edited by Lawman_Actual

Share this post


Link to post
Share on other sites

Also if a variable is first defined inside a scope it will be undefined outside of it. Don't forget -showScriptErrors

Share this post


Link to post
Share on other sites

Ahh, ok that might explain some errors I've had in the past.

Thanks once again

Edited by Lawman_Actual

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  

×