PDA

View Full Version : Help with arrays within arrays. (Need help selecting)



JonBons
Aug 15 2011, 18:04
My goal is to compare the type of an object and if it is of "Tank" then it selects the vector with the position.

I'm just having trouble applying the new syntax and some of the things I'm used to being able to do easily in the Lua scripting language.

I have an array set up like this


_CustomAttach = [
["Car", [0,1.2,-1.8]],
["Truck", [0,1.8,-2]],
["Wheeled_APC", [0,2.6,-2]],
["Tank", [0,2.8,-2]],
["Tracked_APC", [0,2,-2.4]]
];




In the Lua scripting language you could just do this:


local _CustomAttach = {}
_CustomAttach["Tank"] = Vector(0,2.8,-2)
_CustomAttach["Truck"] = Vector(0,1.8,-2)


And then to select you could do this:


local entClass = ent:GetClass()
if not _CustomAttach[entClass] then return; end

local attachToPos = _CustomAttach[entClass]

Muzzleflash
Aug 15 2011, 18:10
You still need to check which of these the vehicle is like. Sure you can get the classname with typeOf but that's not the same as checking whether it is derived from something.


//Iterate over until a match is found:
_vector = nil;
{
//First entry in alist, eg. "Tank".
_curType = _x select 0;
if (myVeh isKindOf _curType) exitWith {_vector = (_x select 1);};
} forEach _CustomAttach;

Also you need to put Car and Tank below Wheeled_APC and Tracked_APC since they are more specific: http://community.bistudio.com/wiki/ArmA_2:_CfgVehicles#Land_Class_Vehicles and you probably want to get the more specific vector.

kylania
Aug 15 2011, 18:11
I'd use switch (http://community.bistudio.com/wiki/switch) for that. One problem might be the car vs truck thing though, since a truck is a car as far as the game is concerned. Might need to lock it down by classname? Depends on the scope you want for this.

Or the magic that Muzzleflash pulled out of nowhere there. ;)

JonBons
Aug 15 2011, 18:55
You still need to check which of these the vehicle is like. Sure you can get the classname with typeOf but that's not the same as checking whether it is derived from something.

I was using a if else with the isKindOf but it got really annoying when you wanted to add more, I don't want to make a list of every single vehicle I want to support custom positions on so I'm going to keep it to the type system and maybe make it allow exceptions for certain vehicles that might need further adjustment. Such as the M6 Linebacker due to the height not being the best for attachTo inside of the C130.

First time scripting for ArmA, I've had experience in other languages but it just takes a while to adjust to the different things that each language does differently.

Your method worked great, thanks for all the help. I think I understand how to use the forEach function now, it is a bit different than what I'm used to but I'll figure it out.