Jump to content

Recommended Posts

Posted

Does anyone know if using net.dostring_in() for scripting environment is available?

i.e

str, err = net.dostring_in("script", <lua code>)

 

or if there's a way to get data out of the scripting engine with minimal performance hit, other then using io and loadfile, or working with UDP/TCP sockets.

 

I know SPEED added this to an old wish list but not sure if anything was done with it, API documentation does not include any further information.

 

Thanks,

Xcom

Posted

From DCS_ControlAPI.txt in your DCS install/API folder.

 

net.dostring_in(state, string) -> string
  Executes a lua-string in a given internal lua-state and returns a string result
  Valid state names are:
      'config': the state in which $INSTALL_DIR/Config/main.cfg is executed, as well as $WRITE_DIR/Config/autoexec.cfg
                used for configuration settings
      'mission': holds current mission
      'export': runs $WRITE_DIR/Scripts/Export.lua and the relevant export API

 

 

Mission is the mission scripting environment. Or were you asking if such a function existed solely within the mission environment and not elsewhere like net?

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

What exactly is the "scripting" environment? Which files are being executed in its scope?

I was only aware of net, mission, config and export.

 

If you can define a function in the scripting environment and make it accessible from the mission environment, you might be able to use something like net.dostring_in("mission", "my_scripting_env_function(\"param 1\", \"param 2\")").

Posted (edited)

The environment that is used by net.dostring_in("mission", ...) seems to be the one where the Lua snippets from the mission file (i.e. the things that the Mission Editor autogenerates for trigger actions) are executed.

 

I have not found any way to use net.dostring_in to get data out of the mission scripting environment, other than reading and writing user flags the way Ciribob does it in the thread you linked to. You can get string data into the mission scripting environment with dostring_in("mission", [[a_do_script('some_var="mystring"')]]), but the only way to get string data out of it while avoiding file and network I/O would be to spawn a new group with a specific missionId and then use DCS.getUnitProperty(missionId, DCS.UNIT_GROUPNAME) to retrieve the group name, and I am pretty sure that would have a very significant performance impact.

Edited by [FSF]Ian
  • 8 years later...
Posted (edited)
On 5/10/2016 at 3:33 AM, FSFIan said:

You can get string data into the mission scripting environment with dostring_in("mission", [[a_do_script('some_var="mystring"')]]), but the only way to get string data out of it while avoiding file and network I/O would be to spawn a new group [...]

  As of DCS 2.9.13, a_do_script() finally has return value pass-thru:

Quote

Scripting API. Added possibility to pass args and return values from mission scripting a_do_script() and a_do_file() APIs.

Example code for the control/hooks environment that fetches a string value from the mission scripting environment:

return net.dostring_in("mission", [=[
    return a_do_script([[
        return "42"
    ]])
]=])

P.S.: Sorry for necro-posting. As these forum posts are DCS' scripting "documentation", it appeared appropriate to update said docs.

Edited by Actium
  • Recently Browsing   0 members

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