Jump to content
Sign in to follow this  
commanderx

Subtracting multidimensional arrays and multiplayer hint

Recommended Posts

Good morning,

I have an array which is build like that.

if(isNil"city_pos") then {
city_pos = [[5095.67,11256,"Panochori",400,400]];
city_pos = [[3531.15,13117.6,"Kavala",400,800]] + city_pos;
city_pos = [[3821.85,13692,"Aggelochori",400,400]] + city_pos;
city_pos = [[19403.7,13248.6,"Dorida",400,400]] + city_pos;
publicVariable "city_pos";
};

After that I select randomly one of those arrays.

_random_city = city_pos call BIS_fnc_selectRandom;

Everything works well but then I subtract the selected values from the array with

city_pos = city_pos - _random_city;
publicVariable "city_pos";

The file will be executed several times again but this doesn´t work. I still get all the elements from city_pos. I don´t know if the problem is the if(isNil"city_pos") or if the subtraction doesn´t work?

Second problem is I execute a file with if(!isServer) exit with {}; at the beginning. Inside that files I need to execute hints that all players should be able to see. In Single Player everathing works fine but in Multiplayer not. Any ideas?

Thanks in advance for helping me out.

Share this post


Link to post
Share on other sites

Subract from array with brackets? Just like when you're adding to it.

city_pos = city_pos - [_random_city]; 

Share this post


Link to post
Share on other sites
Good morning,

I have an array which is build like that.

if(isNil"city_pos") then { //why all of this?
city_pos = [[5095.67,11256,"Panochori",400,400]];
city_pos = [[3531.15,13117.6,"Kavala",400,800]] + city_pos;
city_pos = [[3821.85,13692,"Aggelochori",400,400]] + city_pos;
city_pos = [[19403.7,13248.6,"Dorida",400,400]] + city_pos;
publicVariable "city_pos";
};

if(isNil"city_pos") then //this is much better, faster, and makes a lot more sense when you read it
{
city_pos = [[5095.67,11256,"Panochori",400,400], [3531.15,13117.6,"Kavala",400,800], [3821.85,13692,"Aggelochori",400,400], [19403.7,13248.6,"Dorida",400,400]];
publicVariable "city_pos";
};

The file will be executed several times again but this doesn´t work. I still get all the elements from city_pos. I don´t know if the problem is the if(isNil"city_pos") or if the subtraction doesn´t work?

Is your array declaration inside the script? Every time it runs, that variable will be reset. If not, this is really a very basic problem that you should be able to debug yourself. Also, I'm pretty sure you need to put a space after isNil (add -showScriptErrors to your startup parameters) tested this theory using:

if (isNil"blahblah") then {hint "it worked???"};

it totally worked

Second problem is I execute a file with if(!isServer) exit with {}; at the beginning. Inside that files I need to execute hints that all players should be able to see. In Single Player everathing works fine but in Multiplayer not. Any ideas?

["Hello all players","hint",nil,true] call BIS_fnc_MP;

Also,

I execute a file with if(!isServer) exit with {}; at the beginning

Stop

EDIT: @Greenfist _randomCity should already contain an array according to what was posted, there's probably a lot more going on in his script and something else is breaking it.

doesn´t work

Why do people still keep saying this. (also possible that he didn't explain his problem properly)

Edited by DreadedEntity

Share this post


Link to post
Share on other sites
Everything works well but then I subtract the selected values from the array with

city_pos = city_pos - _random_city;
publicVariable "city_pos";

The file will be executed several times again but this doesn´t work. I still get all the elements from city_pos. I don´t know if the problem is the if(isNil"city_pos") or if the subtraction doesn´t work?

https://community.bistudio.com/wiki/Array#Subtraction

Share this post


Link to post
Share on other sites

Thanks for helping me out!

the call BIS_fnc_Mp command is great. Thanks.

Yes, there is a lot more inside the script going on.

It´s not easy to explain what I´m doing. Even in my native language (German) it would be not easy to explain it properly :D

From the init.sqf I load a file where is decided which further script will be loaded. In this loaded script is a mission and at the end of this script the same file which is called from the init.sqf is loaded again and there again it will be decided which further script with a mission will be loaded.

I thought the command

if(isNil"city_pos") then {

makes sure that the array will just set once? I thought if the script is called again the variable city_pos is set it won´t be executed again?

I´m sorry for making probably noobish errors, making my first steps in scripting Arma :D

Haha, you wrote

if(isNil"city_pos") then //this is much better, faster, and makes a lot more sense when you read it

is funny because I think that it´s much better readable for me because there are 30+ entries in the complete array.

if(isNil"city_pos") then {
city_pos = [[5095.67,11256,"Panochori",400,400]];
city_pos = [[3531.15,13117.6,"Kavala",400,800]] + city_pos;
city_pos = [[3821.85,13692,"Aggelochori",400,400]] + city_pos;
city_pos = [[8984.53,12042.3,"Zaros",400,800]] + city_pos;
city_pos = [[10670.5,12266.4,"Therisa",400,400]] + city_pos;
city_pos = [[10956.8,13441.1,"Poliakko",400,400]] + city_pos;
city_pos = [[11721.3,13742.2,"Katalaki",400,400]] + city_pos;
city_pos = [[12573.9,14353.5,"Neochori",400,400]] + city_pos;
city_pos = [[12948.5,15069.5,"Stavros",400,400]] + city_pos;
city_pos = [[12346.9,15683.8,"Lakka",400,400]] + city_pos;
city_pos = [[11131.7,14561.5,"Alikampos",400,400]] + city_pos;
city_pos = [[14488.2,17671.5,"Gravia",400,400]] + city_pos;
city_pos = [[14042.6,18730.3,"Athira",500,500]] + city_pos;
city_pos = [[9290.31,15861.3,"Agios Dionysios",500,300]] + city_pos;
city_pos = [[7107.94,16439.3,"Kore",400,400]] + city_pos;
city_pos = [[4871.94,16145.7,"Negades",400,400]] + city_pos;
city_pos = [[8625,18285.6,"Syrta",400,400]] + city_pos;
city_pos = [[16327.4,17221.7,"Telos",300,300]] + city_pos;
city_pos = [[18109.9,15240.5,"Charkia",400,400]] + city_pos;
city_pos = [[16812.1,12722.7,"Pyrgos",550,550]] + city_pos;
city_pos = [[20791.6,6744.61,"Selakano",400,400]] + city_pos;
city_pos = [[20964,16969.2,"Paros",400,400]] + city_pos;
city_pos = [[21380.6,16368.5,"Kalochori",400,400]] + city_pos;
city_pos = [[20246.8,11672.3,"Chalkeia",400,400]] + city_pos;
city_pos = [[25696.5,21349.5,"Sofia",400,400]] + city_pos;
city_pos = [[27044.4,23253.4,"Molos",400,400]] + city_pos;
city_pos = [[18820.7,16601.9,"Rodopoli",400,400]] + city_pos;
city_pos = [[10326.1,19076.7,"Galati",250,250]] + city_pos;
city_pos = [[14643.9,20748.3,"Frini",400,400]] + city_pos;
city_pos = [[16611.9,16093.5,"Anthrakia",400,400]] + city_pos;
city_pos = [[19403.7,13248.6,"Dorida",400,400]] + city_pos;
publicVariable "city_pos";
};

Share this post


Link to post
Share on other sites

Even more readable would be:

city_pos =[
		[16812.1,12722.7,	"Pyrgos",		550,550],
		[20791.6,6744.61,	"Selakano",		400,400],
		[20964,16969.2,		"Paros",		400,400],
		[21380.6,16368.5,	"Kalochori",		400,400],
		[20246.8,11672.3,	"Chalkeia",		400,400],
		[25696.5,21349.5,	"Sofia",		400,400],
		[27044.4,23253.4,	"Molos",		400,400],
		[18820.7,16601.9,	"Rodopoli",		400,400],
		[10326.1,19076.7,	"Galati",		250,250],
		[14643.9,20748.3,	"Frini",		400,400],
		[16611.9,16093.5,	"Anthrakia",		400,400],
		[19403.7,13248.6,	"Dorida",		400,400]
		];

:)

(damn indentation on this forum. But you get the idea)

Edited by Greenfist

Share this post


Link to post
Share on other sites

After rereading the https://community.bistudio.com/wiki/Array#Subtraction site, it´s probably like Greenfist has mentioned earlier the city_pos = city_pos - [_random_city]; I knew this article but obviously didn´t read it carefully enough. Thanks @ Schatten for pointing that out.

@ Greenfist. Thanks, I will do it this way then. Looks a lot better than mine :D

EDIT: I will try yll your suggestions when I´m back at home.

Edited by CommanderX

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  

×