Jump to content

where can I find detailed descriptions of the a_do_script() and net.dostring_in() functions?


Go to solution Solved by Actium,

Recommended Posts

Posted

Hey, guys, where can I find detailed descriptions of the a_do_script() and net.dostring_in() functions? I've been looking for a long time but still can't find it. Can someone tell me? Thank you!

Posted

Unfortunately, the DCS scripting API documentation – or the lack thereof – is incredibly disappointing. The scripting FAQ contains nothing on either function. The only other source I found is %DCS_INSTALL_DIR%/API/Sim_ControlAPI.html, which is very superficial and erroneous. Expand this spoiler at your discretion to read another short rant about the state of DCS scripting engine:

Spoiler

Changes occur without any mention in the changelog and the community managers do not respond when asked in the respective topics. Apparently, scripting engine changes do not even receive basic testing, as bug after bug after bug after bug have proven. What adds insult to injury is that reporting these bugs appears to be a total waste of time. All my recent scripting engine bug reports have gone unacknowledged.

I implemented my WebConsole.lua with the primary intent to figure out how the DCS scripting engine works through trial and error. I've summarized the understanding I developed from that in this post. Take it with a grain of salt. Relevant quote here:

On 7/26/2025 at 9:56 PM, Actium said:

DCS relies on multiple Lua interpreter instances to isolate different scripting zones/environments/namespaces from each other. They contain entirely separate global environments (_G variable). These are called lua_State in the Lua documentation and are also referred to as states in DCS' documentation. The states are isolated from each other, but some applications require to run code and get return values from other states. That is where net.dostring_in() comes in:

net.dostring_in(state, string) -> string: Executes a lua-string in a given internal lua-state and returns a string result

AFAIK, the following Lua states exist: "config", "export", "gui", "mission", "server", "scripting" (new since DCS 2.9.18; separate from a_do_script()), and "userhooks" (new since DCS 2.9.18).
Some of these states are trusted and privileged, e.g., "gui", "server", and "userhooks". These are allowed to read and write arbitrary files and call external programs, which is how SRS launches the client automatically on SRS-enabled servers. Other, unprivileged states run untrusted code from mission files, e.g., the "mission" state. Potentially dangerous Lua functions, e.g., for writing files and calling executables, are sanitized from these unprivileged states.

The a_do_script() function provides access to the actual mission scripting environment, i.e., all LUA code run via the mission editor, e.g., thru trigger. For examples of a_do_script() use, see the links here.

@BIGNEWY Please do chime in if you have any additional information and please encourage your developers to improve the documentation.

 

 

Posted
5小时前,Actium说:

Unfortunately, the DCS scripting API documentation – or the lack thereof – is incredibly disappointing. The scripting FAQ contains nothing on either function. The only other source I found is %DCS_INSTALL_DIR%/API/Sim_ControlAPI.html, which is very superficial and erroneous. Expand this spoiler at your discretion to read another short rant about the state of DCS scripting engine:

  展现隐藏的内容

Changes occur without any mention in the changelog and the community managers do not respond when asked in the respective topics. Apparently, scripting engine changes do not even receive basic testing, as bug after bug after bug after bug have proven. What adds insult to injury is that reporting these bugs appears to be a total waste of time. All my recent scripting engine bug reports have gone unacknowledged.

I implemented my WebConsole.lua with the primary intent to figure out how the DCS scripting engine works through trial and error. I've summarized the understanding I developed from that in this post. Take it with a grain of salt. Relevant quote here:

The a_do_script() function provides access to the actual mission scripting environment, i.e., all LUA code run via the mission editor, e.g., thru trigger. For examples of a_do_script() use, see the links here.

@BIGNEWY Please do chime in if you have any additional information and please encourage your developers to improve the documentation.

 

 

译文

 

I just want to obtain the data list or template of the group from mission. But it always fails. However, small lists can be output, such as the position of the target eye. Is it true that net.dostring_in() cannot output very large strings?

Posted
6 hours ago, Qazplm said:

I just want to obtain the data list or template of the group from mission.

The easier way to accomplish that would be to unzip the .miz file (it is just a regular ZIP archive file). The group templates are part of the file named mission.

6 hours ago, Qazplm said:

Is it true that net.dostring_in() cannot output very large strings?

From my experience, net.dostring_in() can return very large strings. Dozens of megabytes worked for me in the past.

Posted
1小时前,Actium说:

The easier way to accomplish that would be to unzip the .miz file (it is just a regular ZIP archive file). The group templates are part of the file named mission.

From my experience, net.dostring_in() can return very large strings. Dozens of megabytes worked for me in the past.

'''

local GetMoban=[[
function New()
  local qpa={}
  for i,k in pairs(mission.coalition.red.country[1].plane.group[2]) do
  qpa[#qpa+1]=k
  end
  return qpa
end
function ToStringEx(value)
  if value~=nil then
    if type(value)=='table' then
       return TableToStr(value)
    elseif type(value)=='string' then
       return "\'"..value.."\'"
    elseif type(value)=="function" then
       return "\'这是一个函数\'"
    else 
       return tostring(value)
    end
  end
end
function TableToStr(t)
    if t == nil then return "" end
    local retstr= "{"
    local i = 1
    for key,value in pairs(t) do
        if type(value) == "function" then
          key=nil
        end
        local signal = ","
        if i==1 then
          signal = ""
        end
        if key == i then
            retstr = retstr..signal..ToStringEx(value)
        else
            if type(key)=='number' or type(key) == 'string' then
                retstr = retstr..signal..'['..ToStringEx(key).."]="..ToStringEx(value)
            else
                if type(key)=='userdata' then
                    retstr = retstr..signal.."*s"..TableToStr(getmetatable(key)).."*e".."="..ToStringEx(value)
                else
                    retstr = retstr..signal..key.."="..ToStringEx(value)
                end
            end
        end
        i = i+1
    end
     retstr = retstr.."}"
     return retstr
end
----
local Templates=New() 
local TemplateList=TableToStr(Templates)
return TemplateList 
]]
local result, success = net.dostring_in('mission',GetMoban)
local TemplateList=loadstring("return"..result)()

'''

Is there anything wrong with my writing like this? Find the group list, convert it to a string output, and then convert it to code.

Posted

The parameter of the ne.dostring_in() function is a string, and the output is also a string. The parameter of the a_do_script() function is code and the output is a string. Is that what it means?

  • Solution
Posted

Both functions take Lua code as a string argument. net.dostring_in() can only return a string, but a_do_script() can return tables, too. However, its return value pass-thru is currently somewhat broken.

If all you want is getting a group template, just unzip the .miz file, open the extracted file named "mission" with a text editor and get the group data from there. No need to deal with traversing and converting the table programatically. Just copy & paste.

Posted
2小时前,Actium说:

Both functions take Lua code as a string argument. net.dostring_in() can only return a string, but a_do_script() can return tables, too. However, its return value pass-thru is currently somewhat broken.

If all you want is getting a group template, just unzip the .miz file, open the extracted file named "mission" with a text editor and get the group data from there. No need to deal with traversing and converting the table programatically. Just copy & paste.

Thank you. Finally, I'd like to ask, what could be the reason for this? [string"..."] :5: stack overflow

Posted
2025/10/28 AM6点01分,Actium说:

You're welcome. Most likely explanation would be infinite recursion.

I think I must have found a way to obtain the data of groups or units. But when I wanted to write to a new file, there was a problem. io.open() couldn't be used. I really don't understand. I won't do it anymore. This has already achieved my goal. Thank you for your help! Thank you!

Posted
19 hours ago, Qazplm said:

io.open() couldn't be used.

The Lua io module is not available in the mission scripting environment, unless you remove the sanitization in %DCS_INSTALL_DIR%/Scripts/MissionScripting.lua (not recommended).

The io module is however usable from the server Lua environment, which also has access to the mission data in _G.env.mission. I did some digging in my unit spawn code to find what you might have been looking for:

-- minimal table deepcopy (copies only tables, skips metatables)
-- NOTE: use to copy the group table before modifying it to spawn a new group
function deepcopy(tbl)
    local _copy = {}
    for _key, _value in pairs(tbl) do
        if type(_value) == "table" then
            _copy[_key] = deepcopy(_value)
        else
            _copy[_key] = _value
        end
    end
    return _copy
end

-- find aircraft group by name in _G.env.mission
function find_group_by_name(grp_name)
    -- find aircraft group by name in _G.env.mission
    for _, _coalition in pairs(env.mission.coalition) do
        for _, _country in pairs(_coalition.country) do
            -- TODO: support different categories (not just Group.Category.AIRPLANE)
            if _country.plane ~= nil then
                for _, _group in pairs(_country.plane.group) do
                    if _group.name == grp_name then
                        return _group
                    end
                end
            end
        end
    end

    -- name not found
    return nil
end

return find_group_by_name("Aerial-1")

Run that in *a_do_script, scripting, or mission environment with my WebConsole to get the group definition. My console does not support Lua serialization, so it will be returned as JSON.

Posted
4小时前,Actium说:

The Lua io module is not available in the mission scripting environment, unless you remove the sanitization in %DCS_INSTALL_DIR%/Scripts/MissionScripting.lua (not recommended).

  • Since it's not recommended, then let's not do it. I think I can now meet my needs based on your suggestions.
  • Thank you! You have been of great help to me. I can now smoothly export the data of the group and regenerate the group with them. There is just one problem: the newly generated group cannot perform the tasks of the original group. I think I completely copied the data of the group.
  • Like 1
Posted
17 hours ago, Qazplm said:

There is just one problem: the newly generated group cannot perform the tasks of the original group. I think I completely copied the data of the group.

Sorry, no immediate idea about that. I don't have extensive experience wrt. spawning units with tasks and everything.

Posted
5小时前,Actium说:

Sorry, no immediate idea about that. I don't have extensive experience wrt. spawning units with tasks and everything.

I think I can add tasks to it again. Thank you

  • Like 1
  • Recently Browsing   0 members

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