Cheetah7798 Posted August 27, 2022 Posted August 27, 2022 (edited) Just quickly, I'm relatively new to Lua and scripting for DCS, and even more so to Mist. Long story short, here's the line I'm working with: varX = mist.cloneGroup("rusInfGrp1") Relatively straight forward. Basically the first command I pulled out of the Mist hat to get a feel for the library. All I want is a reference to the newly cloned group in the variable 'varX'. Now, according to the PDF that comes with the download, this should return a table that is "a mission editor formatted table of the group". However, according to the online resources, it returns the string name of the group: Yet, after messing around in the editor, I'm not entirely sure either of those are true. It's definitely not a string. Also, attempting to print the value with the 'tostring()' function will print something like "Table: 00000FA283", but attempting to run any of the Group class member functions ends with an error. for instance, if I were to write: trigger.action.outTextForCoalition(1, varX:getName(), 10) will throw an error. Also, printing the count of varX prints the value '0'. Basically, what am I doing wrong? How can I get a handle for the group object that this function returns. PS: I tried other Mist functions with similar return values and the behaviour was all the same. EDIT: It's worth mentioning that the cloned group does actually get created. The Mist functions do work, but their return value doesn't appear to be what is advertised. Edited August 27, 2022 by Cheetah7798
cfrag Posted August 27, 2022 Posted August 27, 2022 Well, from my cursory inspection of the mist code, the cloneGroup() call returns the group table that was used (see here for an example of a group table) in coalition.addGroup() to spawn the group. Now, it has been my experience that addGroup clobbers (or put nicely: modifies) the table that was passed in, but some information may still be intact. The name attribute should probably still be available. 3 hours ago, Cheetah7798 said: It's definitely not a string. You can solve that mystery quickly in Lua: use type(varX) to find out what it is; I'm reasonably sure that the result is 'table' 3 hours ago, Cheetah7798 said: trigger.action.outTextForCoalition(1, varX:getName(), 10) will throw an error. This is to be expected, as most tables does not support OOP syntactic sugar to their attributes. Lua is usually often a lot simpler than people coming from a strong object background assume. Try a simple "varX.name" instead. So, from my point of view (and please note that I'm not overly familiar with mist other than that I think it's one hell of an accomplishment and filled to the brim with cool concepts to emulate), cloneGroup returns a table, not a string. To get the name of the group, access the table's 'name' attribute, and I'm somewhat sure that you'll receive the name of the group as it was spawned into the world. 1
Cheetah7798 Posted August 27, 2022 Author Posted August 27, 2022 Absolute legend. I don't know why it never occurred to me that it was returning the kind of table used in coalition.addGroup() and stored in the mission file. I guess it made more intuitive sense to me to return a handle to the group as opposed to the group's creation details. Also, the idea of complex, object-like data being stored in tables and not classes is a very foreign concept for someone coming from a 3rd gen background (C++, Java). Since DCS has a 'Group' class, but also a group data table that contains many of the same traits is still something I've got to get used to. Any way, thanks bunches.
Recommended Posts