Results 1 to 4 of 4

Thread: Help with arrays within arrays. (Need help selecting)

  1. #1

    Help with arrays within arrays. (Need help selecting)

    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
    Code:
    _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:
    Code:
    local _CustomAttach = {}
      _CustomAttach["Tank"] = Vector(0,2.8,-2)
      _CustomAttach["Truck"] = Vector(0,1.8,-2)
    And then to select you could do this:
    Code:
    local entClass = ent:GetClass()
    if not _CustomAttach[entClass] then return; end
    
    local attachToPos = _CustomAttach[entClass]
    Last edited by JonBons; Aug 15 2011 at 18:07.

  2. #2
    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.

    PHP Code:
    //Iterate over until a match is found:
    _vector nil;
    {
        
    //First entry in alist, eg. "Tank".
       
    _curType _x select 0;
       if (
    myVeh isKindOf _curTypeexitWith {_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/A...Class_Vehicles and you probably want to get the more specific vector.
    Last edited by Muzzleflash; Aug 15 2011 at 18:15.

  3. #3
    I'd use 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.

  4. #4
    Private First Class JonBons's Avatar
    Join Date
    Aug 15 2011
    Location
    Oklahoma
    Posts
    14
    Author of the Thread
    Quote Originally Posted by Muzzleflash View Post
    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.
    Last edited by JonBons; Aug 15 2011 at 18:57.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •