number3 Posted December 19, 2013 Posted December 19, 2013 Is there a way to retrieve the names of units within a group? And do unit names have to be unique across groups? Example: if I have 2 groups of 2 units. Can both groups have units with the names 'Unit truck' and 'Unit AAA'? 314-я смешанная авиационная дивизия 314th Mixed Aviation Division: The "Fighting Lemmings"- Forums: http://314thsquadron.enjin.com/ - ED Forum Group: http://forums.eagle.ru/group.php?groupid=119
Wrecking Crew Posted December 19, 2013 Posted December 19, 2013 Unit names are unique. You would end up with 'Unit truck', 'Unit truck #001', Unit truck #002', ... Can't answer the other question, though. WC Visit the Hollo Pointe DCS World server -- an open server with a variety of COOP & H2H missions including Combined Arms. All released missions are available for free download, modification and public hosting, from my Wrecking Crew Projects site.
ENO Posted December 20, 2013 Posted December 20, 2013 I might be inclined to look at the CTTS script since you seem to know your way around code and he seems to have figured out to pull certain units into his script ( with particular unit names) Sorry I can't be more help. "ENO" Type in anger and you will make the greatest post you will ever regret. "Sweetest's" Military Aviation Art
Grimes Posted December 20, 2013 Posted December 20, 2013 If you have a group name or group object you can use Group.getUnits() which returns a table of unit objects. From there you can iterate through each item and use Unit.getName() on the object. Likewise if you have a single units name or unit object you can use Unit.getGroup() followed by what was described above. for i, unitTable in pairs(Unit.getByName('myUnit'):getGroup():getUnits()) do env.info(Unit.getName(unitTable)) end 1 The right man in the wrong place makes all the difference in the world. Current Projects: Grayflag Server, Scripting Wiki Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread) SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum
number3 Posted December 20, 2013 Author Posted December 20, 2013 If you have a group name or group object you can use Group.getUnits() which returns a table of unit objects. From there you can iterate through each item and use Unit.getName() on the object. Likewise if you have a single units name or unit object you can use Unit.getGroup() followed by what was described above. for i, unitTable in pairs(Unit.getByName('myUnit'):getGroup():getUnits()) do env.info(Unit.getName(unitTable)) end That was straight forward. But I don't see any mention of Unit.getName in part 1 or 2 of the scripting engine pages http://wiki.hoggit.us/view/Simulator_Scripting_Engine_Documentation. 314-я смешанная авиационная дивизия 314th Mixed Aviation Division: The "Fighting Lemmings"- Forums: http://314thsquadron.enjin.com/ - ED Forum Group: http://forums.eagle.ru/group.php?groupid=119
Grimes Posted December 20, 2013 Posted December 20, 2013 The Unit class extends the Object class: http://wiki.hoggit.us/view/Part_2#Object So all of the functions for Object can be used on units. The right man in the wrong place makes all the difference in the world. Current Projects: Grayflag Server, Scripting Wiki Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread) SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum
number3 Posted December 20, 2013 Author Posted December 20, 2013 Thanks. I remember reading that in one of the scripting engine pages now that you mention it. 314-я смешанная авиационная дивизия 314th Mixed Aviation Division: The "Fighting Lemmings"- Forums: http://314thsquadron.enjin.com/ - ED Forum Group: http://forums.eagle.ru/group.php?groupid=119
Yuriks Posted April 16, 2022 Posted April 16, 2022 On 12/20/2013 at 2:55 AM, Grimes said: for i, unitTable in pairs(Unit.getByName('myUnit'):getGroup():getUnits()) do env.info(Unit.getName(unitTable)) end @Grimes I am trying to get a unit name from a 'banditGroup' could you explain this syntax pairs(Unit.getByName('myUnit'):getGroup():getUnits()) especially the use 1) ":" 2) and where to you call for particular group to dig in?
toutenglisse Posted April 16, 2022 Posted April 16, 2022 (edited) 4 hours ago, Yuriks said: ...could you explain this syntax... the complete line means for each value, refered as unitTable, inside the table of Units made of all units from the group that the Unit named 'myUnit' belongs to, do what follows in the code. Unit.getByName('myUnit'):getGroup():getUnits() is the same than Group.getUnits(Unit.getGroup(Unit.getByName('myUnit'))) Edited April 16, 2022 by toutenglisse corrected 1
toutenglisse Posted April 16, 2022 Posted April 16, 2022 3 hours ago, Yuriks said: ":" here is not the same as Self in functions? yes (and I forgot to add the Group. and Unit. for functions without the ":"). 1
Recommended Posts