Jump to content

Recommended Posts

Posted

Hi,

 

I'm thinking about getting into mission scripting for DCS to some extent.

I am looking for information about the DCS scripting engine for a couple of days now but other than a short description about some key Objects/Classes/Singletons

on Hoggit I didn't find what I was looking for. Sure there are many tutorials on Youtube including the very nice ones from MOOSE/FlightControl.

But coming from a developer background with experiences in a couple of object-oriented programming languages I am not really looking for tutorials describing how to spawn a unit or how to write a trigger

in Lua. What I am interested in first is the big picture - how the scripting engine works in general and how it is integrated into DCS.

 

Starting with things like:

- How does the "main event loop" look like?

- Is it all single-threaded or does it run in a separate thread?

- How do events work? Who can emit, who can process events?

- What is the lifecycle and scope of objects and variables? (i know, this one is discussed in a coupe of videos on YT to some extent)

- What is the lifecycle of the execution context/runtime?

- Where can I hook into it? (other than creating a trigger and implementing an action, obviously)

- Is there any reasonably current API documentation? Maybe in code like Javadoc?

- What are the files and directories in DCS that are interesting when it comes to scripting?

 

A couple of these questions maybe relate not only to mission scripting but to scripting/modding in general.

Like for example: How are Tools like SRS or Tacview integrated into DCS with additions to the options UI? What API are these tools using to interact with DCS.

 

For these kinds of questions, I didn't find any good answer yet. Is there maybe a technical reference manual hidden anywhere for these kinds of topics?

 

Thank's in advance for any advice, very appreciated.

AH-64D | AV-8B | A-10C II | A-4E | F-4E | F-5E | F-14B | F-15E | F-16C | F/A-18C | M-2000C | UH-1H | Mig-21bis | L-39 | F-86F | P-47D | P-51D | BF 109 | Spitfire | BS3 | FC3 | SC | CA

Intel® Core™ i7-13700K | NVIDIA RTX 4090 | 64 GB DDR5 RAM | Aorus Elite Z790 | 50“ UHD LG Monitor | Windows 11 Pro

VPC Rotor TCS Plus Base | VPC Apache-64 Collective Grip | VPC Hawk-60 Collective Grip | VPC MongoosT-50CM3 Base | TM F-16/A-10 Stick  | TM F/A-18 Stick

TM HOTAS Warthog (DSE Slew Upgrade) | TM Hotas Cougar (FSSB) | TM Pendular Rudder | HP Reverb G2 | TrackIR 5

Posted

Thanks i will do that.

AH-64D | AV-8B | A-10C II | A-4E | F-4E | F-5E | F-14B | F-15E | F-16C | F/A-18C | M-2000C | UH-1H | Mig-21bis | L-39 | F-86F | P-47D | P-51D | BF 109 | Spitfire | BS3 | FC3 | SC | CA

Intel® Core™ i7-13700K | NVIDIA RTX 4090 | 64 GB DDR5 RAM | Aorus Elite Z790 | 50“ UHD LG Monitor | Windows 11 Pro

VPC Rotor TCS Plus Base | VPC Apache-64 Collective Grip | VPC Hawk-60 Collective Grip | VPC MongoosT-50CM3 Base | TM F-16/A-10 Stick  | TM F/A-18 Stick

TM HOTAS Warthog (DSE Slew Upgrade) | TM Hotas Cougar (FSSB) | TM Pendular Rudder | HP Reverb G2 | TrackIR 5

Posted

- How does the "main event loop" look like?

 

However you want I guess? Just make a function that you repeatedly call however often as you like.

 

local function main()
 timer.scheduleFunction(main, {}, timer.getTime() + 10)
 -- whatever you want to keep checking
end
main()

 

- Is it all single-threaded or does it run in a separate thread?

It is single threaded along with the game. If you have some bit of code that takes a long time to execute or generates an error box server side, then the missing will hang and in MP any connected clients will stop receiving updates of everything but themselves.

 

 

- How do events work? Who can emit, who can process events?

All scripting engine code is run by the server/ single player. Though there are some events that occur for the game when players do stuff that don't really provide any useful information to the scripting engine and might also occur for the player itself. For example players entering and exiting units. But there are events for a large number of actions, but to be honest, not all that we'd want.

 

- What is the lifecycle and scope of objects and variables? (i know, this one is discussed in a coupe of videos on YT to some extent)

 

Scope is mostly however you define it. All of the functions in the scripting engine are globally accessible within their environment. Using local variables works best because lua just likes to run faster when as much is local as possible. Even a local reference to a global value runs quicker. I don't believe there is an active garbage collector that removes anything that is still active.

 

- What is the lifecycle of the execution context/runtime?

As long as the mission is open I think? Not entirely certain what the question is.

 

 

- Where can I hook into it? (other than creating a trigger and implementing an action, obviously)

Thats about what all you *should* be doing as far as mission scripting is concerned. Could always use dofile() or whatever to run stuff located elsewhere on your drive. Doing that is great for mission testing because you can modify your code and just restart the mission without having to go back into the editor to copy/paste your changes or re-attach a file.

 

- Is there any reasonably current API documentation? Maybe in code like Javadoc?

I try to maintain a list here: https://wiki.hoggitworld.com/view/Simulator_Scripting_Engine_Documentation

 

- What are the files and directories in DCS that are interesting when it comes to scripting?

 

A couple of these questions maybe relate not only to mission scripting but to scripting/modding in general.

Like for example: How are Tools like SRS or Tacview integrated into DCS with additions to the options UI? What API are these tools using to interact with DCS.

 

Answering both of these since they are directly related. There are different lua environments that govern different aspects of the game. Mission scripting is one and is pretty much only accessible via code within a mission. Now you can obviously use dofile or the like to run code saved someplace, but it is best to keep it in the miz when you distribute the file.

 

The other environments are export and "gamegui", which is also referred to as net. Export is what srs and tacview use to get information from the game world or the player's aircraft for use in external applications. Both of those are installed like mods place code in savedgames/DCS/mods and savedgames/DCS/Scripts.

 

GameGUI provides information about the status of the game and is where all of the network tools are located for server admin scripting behavior like slmod or slot blocking occur at. There is limited access/information from the mission environment available.

 

For these kinds of questions, I didn't find any good answer yet. Is there maybe a technical reference manual hidden anywhere for these kinds of topics?

 

GameGUI documentation is provided in DCS/API/DCS_ControlAPI.html

Export has some documentation also in that file, but you can also check DCS/Scripts/Export.lua for additional information.

The right man in the wrong place makes all the difference in the world.

Current Projects:  Grayflag ServerScripting Wiki

Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread)

 SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum

Posted

...

GameGUI documentation is provided in DCS/API/DCS_ControlAPI.html

Export has some documentation also in that file, but you can also check DCS/Scripts/Export.lua for additional information.

 

Thanks a lot for a most informative post .. I will copy it onto my ME tips file :thumbup:

 

For work: iMac mid-2010 of 27" - Core i7 870 - 6 GB DDR3 1333 MHz - ATI HD5670 - SSD 256 GB - HDD 2 TB - macOS High Sierra

For Gaming: 34" Monitor - Ryzen 3600 - 32 GB DDR4 2400 - nVidia RTX2080 - SSD 1.25 TB - HDD 10 TB - Win10 Pro - TM HOTAS Cougar

Mobile: iPad Pro 12.9" of 256 GB

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...