Jump to content
Sign in to follow this  
m1ndgames

Multi-Dimensional Arrays and Foreach + addAction

Recommended Posts

Hi.

i have a multi dimensional array filled with a name descriptor, the associated classname, and its cost. I want to create a Shop list on an object named 'shop_vehicle' but cant get it to work. Maybe because using variables in addAction is not allowed? How can i work around this?!

FAL_VEHICLES_LAND_NATO = [
				["M1126 ICV M134 CROWS","M1126_ICV_M134_DG1_NOSLATDES",100],
				["M1126 ICV M2 CROWS","M1126_ICV_M2_DG1_NOSLATDES",100],
				["M1126 ICV M2 GPK","M1126_ICV_M2NEST_DG1_NOSLATDES",100],
				["M1126 ICV Mk19 CROWS","M1126_ICV_mk19_DG1_NOSLATDES",100],
				["M1128 MGS","M1128_MGS_DG1_NOSLATDES",100],
				["M1129 MC MK19 CROWS","M1129_MC_DG1_NOSLATDES",100],
				["M1130 CV M2 CROWS","M1130_CV_DG1_NOSLATDES",100],
				["M1133 MEV","M1133_MEV_DG1_NOSLATDES",100],
				["M1135 ATGMV","M1135_ATGMV_DG1_NOSLATDES",100],
				["M1151 M2","DAR_M1151",100],
				["M1151 Mk 19","DAR_M115_MK19",100],
				["M1151 M2 Deployment","DAR_M1151_Deploy",100],
				["M1151 ECV","DAR_M1152",100],
				["M1151 TOW-2","DAR_M1167",100],
				["Nemmera","B_APC_Tracked_01_CRV_F",100],
				["Bardelas","B_APC_Tracked_01_AA_F",100],
				["Merkava Mk IV LIC","B_MBT_01_TUSK_F",100],
				["Merkava Mk IV M","B_MBT_01_cannon_F",100],
				["Namer","B_APC_Tracked_01_rcws_F",100],
				["Patria AMV","B_APC_Wheeled_01_cannon_F",100],
				["Seara","B_MBT_01_mlrs_F",100],
				["Sholef","B_MBT_01_arty_F",100]
				];

{
shop_vehicle addAction [_x, ""]
} forEach FAL_VEHICLES_LAND_NATO;

Share this post


Link to post
Share on other sites

Your _x is where the action's title should be. It can't be an array.

shop_vehicle addAction [_x select 0, ""] should work.

Edited by Greenfist

Share this post


Link to post
Share on other sites

shop_vehicle addAction ["Scroll Wheel Action Text", "someScript.sqf", _x, 6, true, true, "", "_this distance _target < 5"];

It's the third parameter of addAction that allows variables to be passed in, use "((_this select 3) select #)" in whatever script you execute with the addAction, where # is the index of the element passed through starting at 0.

Share this post


Link to post
Share on other sites

you will then need to call a script in the "" (or you can use code directly) that uses the addaction _this select 3 and pass your array select 1 and select 2 to that script.

e.g.

 [color=#333333]{[/color]    shop_vehicle [url="https://community.bistudio.com/wiki/addAction"]addAction [/url][_x select 0, "scriptNameGoesHere.sqf",[_x select 1,_x select 2]]
} forEach FAL_VEHICLES_LAND_NATO;

Edit: Ninjad ^^ ;)

Share this post


Link to post
Share on other sites

Thanks guys! I'm familiar with script languages (perl), but sometimes this syntax is weird, or, lacking ;)

Without trying, does this also work?

{ shop_vehicle addAction [_x select 0 " - " _x select 2, "scriptNameGoesHere.sqf",[_x select 1,_x select 2]]

} forEach FAL_VEHICLES_LAND_NATO;

I added a " - " between the _x selects so the players can see the cost next to the vehicle...

Share this post


Link to post
Share on other sites
_x select 0 + " - " + _x select 2

thanks a lot! i tried . to connect it, but didnt think of +

edit:

tried it like this, but it doesent show anything anymore:

{
shop_vehicle addAction [_x select 0 + " - " + _x select 2, "scripts\fal_shop.sqf",[_x select 1,_x select 2]]
} forEach FAL_VEHICLES_LAND_NATO;

Edited by m1ndgames

Share this post


Link to post
Share on other sites

try (not tested)

{	shop_vehicle addAction [[font=Verdana]format ["%1 - %2",_x select 0, _x select 2][/font], "scripts\fal_shop.sqf",[_x select 1,_x select 2]]
} forEach FAL_VEHICLES_LAND_NATO;

Share this post


Link to post
Share on other sites

Kevsno's way should do it, I smashed in a little Java with my sqf there :p.

Share this post


Link to post
Share on other sites
[color="#FF0000"]([/color]_x select 0[color="#FF0000"])[/color] + " - " + [color="#FF0000"]([/color]_x select 2[color="#FF0000"])[/color]

Also make sure your data will always be a string, otherwise there will be a script error and the script will end at this line (without doing anything)

Kevsno's way should do it, I smashed in a little Java with my sqf there :p.

Use more parenthesis

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  

×