Loophole Posted December 2, 2022 Posted December 2, 2022 (edited) I just discovered an amazingly useful feature in the mission editor! When you set an Advanced Waypoint Action, and select "Perform Command" -> "Run Script", according to the tooltip, you can access the Group of the triggering unit as a parameter passed in to the script! This is amazingly useful. There is so much that could be done with this! ... at least, there *would* be, if there was any documentation as to WHAT THIS PARAMETER IS CALLED! Maybe its "_"? Maybe its not! I could start at "a" and work my way through to "zzzzz99999" until I hit on the correct variable name - or maybe Eagle Dynamics could actually write it down in a manual somewhere? Or add some text to the ME UI? Pretty please?? Just teasing us that there is a variable that we *could* use if only they told us what it was is just plain cruel! Edited December 2, 2022 by Loophole null
TEMPEST.114 Posted December 2, 2022 Posted December 2, 2022 The name of it is up to you. Call it 'thisGroup' or whatever. It's the data that's passed in that's important. What you call it in your function prototype is up to you. Just create a function called <scriptName>:MyAdvancedWaypoint(thisGroup) and use it with this Adv Waypoint Action.
Loophole Posted December 2, 2022 Author Posted December 2, 2022 @Elphaba - sorry, but I can't see how that works. As I understand it, the text we put into the script specified in the "Run Script" is itself actually a function - we just don't have any visibility to the "function XXX(yyy) ... end that wraps it. My understanding of the above tooltip is that this wrapper has some (yyy) parameter passed, with the Group of the triggering unit - but in order to access it, we'd need to know its name. E.g. we should be able to do something like below, if we knew what name to use in place of "thisGroup" Indeed, maybe the magic name is "this"? Hmm, or maybe it uses the LUA vararg construct - "..." So the script could be: Group.destroy(...) That rings a bell from something I read several years ago. I'll have to run some tests on that one!
Solution Grimes Posted December 2, 2022 Solution Posted December 2, 2022 11 hours ago, Loophole said: Hmm, or maybe it uses the LUA vararg construct - "..." Correct. Though you may have to declare it as a value first. Don't remember if it would like Group.destroy(...) local gp = ... gp:destroy() 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
funkyfranky Posted December 2, 2022 Posted December 2, 2022 I think `...` should directly reference the DCS group object. So something like Group.destroy(...) should be fine. But always listen to @Grimes first;) 1 A warrior's mission is to foster the success of others. i9-12900K | RTX 4090 | 128 GB Ram 3200 MHz DDR-4 | Quest 3 RAT - On the Range - Rescue Helo - Recovery Tanker - Warehouse - Airboss
Loophole Posted December 3, 2022 Author Posted December 3, 2022 If '...' is the Group object, then in theory you should also be able to do something like: ...:destroy() or even ....destroy(...) which makes me shudder to even write! (and probably wouldn't parse anyway!) I think Grime's recommendation is good, and I'd be able to sleep at night writing code that way. Thank you for the confirmation! @Grimes, Do you know if '...' is only available in scripts run as Advanced Waypoint actions of a Group? Or is it also available in scripts executed by the Triggered Actions of a Group?
TEMPEST.114 Posted December 3, 2022 Posted December 3, 2022 12 hours ago, funkyfranky said: I think `...` should directly reference the DCS group object. So something like Group.destroy(...) should be fine. But always listen to @Grimes first;) Ouch... do I need aloe? I will handily agree Grimes is the resident expert on scripting but I was only trying to help.
funkyfranky Posted December 3, 2022 Posted December 3, 2022 18 minutes ago, Elphaba said: Ouch... do I need aloe? I will handily agree Grimes is the resident expert on scripting but I was only trying to help. Sorry, my remark had nothing to do with you. I just wanted to say that he should listen to Grimes more than to me. 1 A warrior's mission is to foster the success of others. i9-12900K | RTX 4090 | 128 GB Ram 3200 MHz DDR-4 | Quest 3 RAT - On the Range - Rescue Helo - Recovery Tanker - Warehouse - Airboss
TEMPEST.114 Posted December 3, 2022 Posted December 3, 2022 6 minutes ago, funkyfranky said: Sorry, my remark had nothing to do with you. I just wanted to say that he should listen to Grimes more than to me. I get it. Grimes saved my bacon at 02:30 this morning too.
skypickle Posted December 3, 2022 Posted December 3, 2022 could you wizards please post a full example for the obtuse ones like me. Is this correct: I write a lua script in a file named GroupDestroy.lua What is in that file? Where do I put that file? What do I write in the 'perform command-run script' box? 4930K @ 4.5, 32g ram, TitanPascal
cfrag Posted December 3, 2022 Posted December 3, 2022 Easiest would be simply to use the runScript command (as opposed to the ScriptFile command) since the script that you'll be running usually is short if you put this as scrip into the script box to execute upon reaching the waypoint 2 local theGroup = ... trigger.action.outText("there's something happening here", 30) trigger.action.outText("what it is ain't exactly clear", 30) trigger.action.outText("but the group is called " .. theGroup:getName(), 30) (looking like this) in-game looks like this: That '...' is a dirty trick. 2
Grimes Posted December 4, 2022 Posted December 4, 2022 15 hours ago, Loophole said: @Grimes, Do you know if '...' is only available in scripts run as Advanced Waypoint actions of a Group? Or is it also available in scripts executed by the Triggered Actions of a Group? Its the same task, so yes it works no matter how the group executes it. 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
Recommended Posts