Jump to content

Please expose a_mission_load as a callable function in the simulator scripting environment


torreypine

Recommended Posts

I run an A-10C training course and a server my students can use for practice and training.  The training and the server are offered free to the Tactical DCS community.

 

I've used the simulator scripting environment (SSE) to place comms menu F10 items so that students who come to the server can choose which training mission they wish to run and/or to reset their desired training mission so they have a known starting state (and targets to kill.)  I've done this using ADD_RADIO_ITEM_FOR_COALITION to set a flag and then set a SWITCHED CONDITION to LOAD_MISSION the requested mission based upon the flag value.

 

It works well--and if ED would like to see the result I'll be happy to share the server credentials with you--but there are three undesirable effects:

1. It's a pain to use the Mission Editor to duplicate this functionality for each mission,

2. Since the code exists in each training mission (multiple places) it's easily foreseeable that the code could get out-of-sync and defects introduced in one or more missions as a result of mis-typing or other inadvertent errors, and

3. I'm currently limited to 10 items in the comms menu--if I were able to use the ADD_RADIO_MENU_ITEM in the SSE I'd be able to offer a richer mission set via submenus to my students and the Tactical DCS community.

 

I've looked through the OpenBeta LUA code (grep is eminently helpful) to see if a_mission_load is exposed in the SSE but it doesn't seem to be.  If it is, please correct my misapprehension and advise on how I may access it from the SSE.

 

Otherwise, please consider exposing it as a callable function in the SSE.

 

Thank you!


Edited by torreypine
grammar & clarity
Link to comment
Share on other sites

  • torreypine changed the title to Please expose a_mission_load as a callable function in the simulator scripting environment
On 12/18/2020 at 1:41 PM, torreypine said:

I'm currently limited to 10 items in the comms menu--if I were able to use the ADD_RADIO_MENU_ITEM in the SSE I'd be able to offer a richer mission set via submenus to my students and the Tactical DCS community.

I literally just wrote a set of routines using this yesterday. Don't know how long it's been in there.. DId take an hour of searching though, but in the end I have this:

 

"Other"

    ParentMenu

        Child1

        Child2

        ...

 

 

Adds a menu to F10, then sub-menus (children) below that:

https://wiki.hoggitworld.com/view/DCS_func_addCommand

  • Like 1

i6700k 4.4mhz, 32Gb, nVidia 1080, Odyssey+, CH Products, Derek Speare Designs button box, Bass shaker w/SimShaker For Aviators

Link to comment
Share on other sites

  • 2 years later...
On 12/22/2020 at 3:40 AM, dorianR666 said:

IRC must be called from server lua context, not mission scripting context. but those two contexts can interact so its fine.

Could you expand the thought? I am struggling with the loading MIZ with this function, but so far I am receiving error, regardless if I use it from MOOSE, or directly from API.

Natural Born Kamikaze

-------------------------

AMD Ryzen 5 3600, AMD Fatal1ty B450 Gaming K4, AMD Radeon RX 5700 XT, 32 GB RAM Corsair Vengeance LPX, PSU Modecom Volcano 750W, Logitech G940 HOTAS, Turtle Beach VelocityOne Rudder.

Link to comment
Share on other sites

1 hour ago, Amarok_73 said:

Could you expand the thought?

‚From server context‘ means that the method cannot be invoked from within a mission, but needs to be invoked from a thread that runs on the server. There is a net.dostring_in() method that can do that for you, but afaik it currently only works in multiplayer, not single player. I see if I can whip up a small example for you tomorrow (on the road right now)


Edited by cfrag
Link to comment
Share on other sites

@cfrag I think it's clear now to me, but the example from You will be as always highly welcome.

Natural Born Kamikaze

-------------------------

AMD Ryzen 5 3600, AMD Fatal1ty B450 Gaming K4, AMD Radeon RX 5700 XT, 32 GB RAM Corsair Vengeance LPX, PSU Modecom Volcano 750W, Logitech G940 HOTAS, Turtle Beach VelocityOne Rudder.

Link to comment
Share on other sites

12 hours ago, Amarok_73 said:

the example from You will be as always highly welcome.

Happy to oblige 🙂

Ok, here's some code to restart the current mission:

mn = DCS.getMissionFilename() -- get current mission's name
success = net.load_mission(mn) -- tell DCS to load mission of that name

The problem: the DCS and net singletons are mostly not available in mission space, they must run on the server environment. Enter net.dostring_in(), which passes a string of Lua commands to a different environment, and has it executed there. So we package the above code into a string, and then have it executed on the server environment. We just have to navigate another potential cliff: what is the server environment called? I have found that one environment called "gui" works (warning: case sensitive, all lowercase!)

So we end up with this short beauty of code that you can use in your mission to restart the mission at any time without knowing the mission's file name (anyone who has designed missions with changing names - like, for example, containing the vesion number - knows how difficult it can be to do that).

local res = net.dostring_in("gui", "mn = DCS.getMissionFilename(); success = net.load_mission(mn); return success")

That single line in a DOSCRIPT will restart your mission. Provided, of course, that it is run as multiplayer.

And that's how you use net.dostring_in()

Enjoy,

-ch

 


Edited by cfrag
Link to comment
Share on other sites

So if I'll assign to the "mn" variable the path with file name to other mission file, this mission will be loaded?

EDIT:

It doesn't seems to work as I assumed. No any action on this line, and no error in log file:

local res = net.dostring_in("gui", "mn = 'd:\\DCS World User\\Missions\\304\\15e_tren_night.miz'; success = net.load_mission(mn); return success")

 


Edited by Amarok_73

Natural Born Kamikaze

-------------------------

AMD Ryzen 5 3600, AMD Fatal1ty B450 Gaming K4, AMD Radeon RX 5700 XT, 32 GB RAM Corsair Vengeance LPX, PSU Modecom Volcano 750W, Logitech G940 HOTAS, Turtle Beach VelocityOne Rudder.

Link to comment
Share on other sites

Changed the string to single backslashes, and received the following error:

Quote

2023-07-26 21:11:48.373 ERROR   SCRIPTING (Main): Mission script error: [string "e:\temp\DCS\/~mis000031C7.lua"]:2: escape sequence too large near '"mn = 'd:DCS World UserMissions'

No worries @cfrag, there's no big deal about it. Do not feel any obligation to waste the time on this investigation.

Natural Born Kamikaze

-------------------------

AMD Ryzen 5 3600, AMD Fatal1ty B450 Gaming K4, AMD Radeon RX 5700 XT, 32 GB RAM Corsair Vengeance LPX, PSU Modecom Volcano 750W, Logitech G940 HOTAS, Turtle Beach VelocityOne Rudder.

Link to comment
Share on other sites

10 hours ago, Amarok_73 said:

Changed the string to single backslashes

I remember that when I faced that issue I assembled the string to execute in Lua outside of the doString_in to catch mistakes like that, printed it to screen, and only when I was convinced that I did not screw up, ran the doScript, something along the lines of

mn = "" -- mission name, including all escapes
exec = 'mn = "' .. mn .. '"'
exec = exec .. ";  success = net.load_mission(mn); return success"
env = "gui"
trigger.action.outText(exec, 30) -- show what we got 

local res = net.dostring_in(env, exec)

-ch 

Link to comment
Share on other sites

I given it a shot, but the only effect was the error message saying that the "info" field from the last line (second call of env.info in the script) is of the 'nil' value, meaning that the context indeed has changed, but the night mission was not loaded.

env.info("#### Loading...")
mn = "d:\\DCS World User\\Missions\\304\\15e_tren_night.miz" -- mission name, including all escapes
exec = 'mn = "' .. mn .. '"'
exec = exec .. ";  success = net.load_mission(mn); return success"
env = "gui"
trigger.action.outText(exec, 30) -- show what we got 

local res = net.dostring_in(env, exec)

env.info("#### Not loaded.")

 

Natural Born Kamikaze

-------------------------

AMD Ryzen 5 3600, AMD Fatal1ty B450 Gaming K4, AMD Radeon RX 5700 XT, 32 GB RAM Corsair Vengeance LPX, PSU Modecom Volcano 750W, Logitech G940 HOTAS, Turtle Beach VelocityOne Rudder.

Link to comment
Share on other sites

7 hours ago, Amarok_73 said:

error message saying that the "info" field from the last line

Ha. Silly me. Yes. Rename the env variable in lines 5 and 7 to ‘cntx’, so it does not redefine the existing env singleton that you are using for env.info

Link to comment
Share on other sites

  • Recently Browsing   0 members

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