LFCChameleon_Silk Posted May 25, 2014 Posted May 25, 2014 (edited) trying to add a unit name to a pre-existing table, anyone help me to understand how to format the unitnametable, the table is already created elsewhere in the code. I'm guessing it something to do with do inpairs but I am a real novice, so far no one has been helping much and speaking to grimes through PM has gotten no answer and gotten me no where ahead in the past, so with all your best intentions suggesting something to that effect ain't really helping. thanks in advance. -------------------- function move_units_to_cap_zone(_groupname, _approach, _destination, _finish, _side) -------------------- local randomizer_speed = nil randomizer_speed = math.random(10,25) local _leader_pos = {} local _zone_pos = {} local _approach_pos = {} local _finish_pos = {} _leader_pos = mist.getLeadPos(_groupname) _approach_pos = mist.utils.zoneToVec3(_approach) _zone_pos = mist.utils.zoneToVec3(_destination) _finish_pos = mist.utils.zoneToVec3(_finish) local _path = {} _path[#_path + 1] = mist.ground.buildWP(_leader_pos, 'on road', 40) _path[#_path + 1] = mist.ground.buildWP(_approach_pos, 'rank', 20) _path[#_path + 1] = mist.ground.buildWP(_zone_pos, 'on road', randomizer_speed) _path[#_path + 1] = mist.ground.buildWP(_finish_pos, 'rank', randomizer_speed) mist.goRoute(_groupname, _path) local _u_table = {} if _side == "blue" then _u_table = blue_units_table end if _side == "red" then _u_table = red_units_table end [b] _u_table[#_u_table + 1] = ("[g]", _groupname)[/b] return end ------ Edited May 25, 2014 by =LFC=Chameleon_Silk
Bushmanni Posted May 25, 2014 Posted May 25, 2014 What exactly are you trying to do with this line as it has wrong syntax? _u_table[#_u_table + 1] = ("[g]", _groupname) Are you trying to add "[g]" and _groupname together as a single string? In that case you need to use .. instead of , ie. _u_table[#_u_table + 1] = ("[g]" .. _groupname) DCS Finland: Suomalainen DCS yhteisö -- Finnish DCS community -------------------------------------------------- SF Squadron
LFCChameleon_Silk Posted May 25, 2014 Author Posted May 25, 2014 (edited) well thats what im asking, how do i add to mist.makeUnitTable with the shortcut intact to add the whole group based on the groups name, the only answer i have seen was to check the wiki for more information. I'm well aware that the part you mention is wrong, thats what im here asking, i know how to add a variable to the end of another string. blue_units_table = mist.makeUnitTable( { '[g][bLUE FORTIFED TASK A]', })what i want to is to add to the makeUnitTable a new group name with a shortcut as i spawn new groups in. Edited May 25, 2014 by =LFC=Chameleon_Silk
Bushmanni Posted May 25, 2014 Posted May 25, 2014 First you need to make unit name table using the _groupname and then merge the unit name tables. I'm not exactly sure what would be the best method to do that so unless someone else beats me to it I will find the answer and report back. DCS Finland: Suomalainen DCS yhteisö -- Finnish DCS community -------------------------------------------------- SF Squadron
Bushmanni Posted May 26, 2014 Posted May 26, 2014 I didn't find any better methods to merge tables than for-loop using ipairs iterator. [font=Courier New]local tempUnitTable = mist.makeUnitTable( { "[g]" .. _groupname }) for index, val in ipairs([/font][font=Courier New][font=Courier New]tempUnitTable[/font]) do[/font] [font=Courier New][font=Courier New] _u_table[#_u_table + 1] = [/font][/font][font=Courier New][font=Courier New][font=Courier New]val [/font][/font]end [/font]This for-loop will go through tempUnitTable and in each pass it assigns the key of the next entry (with numerical key) to first variable (index) and value to the second variable (val). Inside the loop the val variable is then added to the end of the _u_table. Val has same value as tempUnitTable[index] and ipairs automatically picks the next entry with numerical key in the table for each pass of the for-loop until the table ends. There's more rules to how the ipairs picks the next entry but I don't want to repeat the lua documentation here. DCS Finland: Suomalainen DCS yhteisö -- Finnish DCS community -------------------------------------------------- SF Squadron
LFCChameleon_Silk Posted May 27, 2014 Author Posted May 27, 2014 thanks for the help, next time i get back to my script i will try it out. keep in mind that i'm not asking for script handouts -- i've been reading the lua documentation and understand you don't want to repeat it, I've also been working in lua console messing with ipairs and basically had very close to what you have there. in the end it maybe simply it doesn't work because the mist table is formatted differently then i suspect it is, but looking through google searches you find such stellar advice as go look at the mist wiki for more information instead of anyone elaborating on the actual layout of the table that the function expects.... which is understandable since there exists ways to write the data for the table to see how its laid out. anyways i appreciate the effort and the help.
Recommended Posts