Jump to content

missionCommands.addCommandForGroup


609_Relentov

Recommended Posts

I'm having difficulty with the missionCommands.addCommandForGroup method. Not so much adding menus (which is working), but when a Client actually hits the F10 radio item, the function that's supposed to be called isn't being called. For example,

 

...

local gid = group:getID()

local menuID = missionCommands.addSubMenuForGroup(gid, "Level 2 Commands")

missionCommands.addCommandForGroup(gid, "Command 1", menuID, ProcessCommand, {lu="L", un=pUnitName, n=6, t=S1})

missionCommands.addCommandForGroup(gid, "Command 2", menuID, ProcessCommand, {lu="U", un=pUnitName, n=6, t=S2})

...

 

In this case, the correct group (e.g. Client) is getting the added sub menu and the commands within it, so the missionCommands.addSubMenuForGroup call is working fine, and the first part of the missionCommands.addCommandForGroup is working fine. However, when as a client I use the F10 radio menu and traverse down to the commands above and hit the appropriate Fxx key, nothing happens. In the called function, I have some debug text via trigger.action.outText(....) but it never displays it.

 

In all of the examples I've seen searching this forum, missionCommands.addCommandForGroup is called using one argument for the called function (i.e. the last parameter of the call to missionCommands.addCommandForGroup. In my case, I need 4 arguments, but it doesn't appear to be getting through to the called function. Also, given examples I've seen on this forum, if more than one argument to the called function is needed, a table format is used (i.e. "{....}"), so my assumption is that in this case the called function needs to have one parameter/argument: a table, that is then de-referenced to get at the individual fields.

 

If anyone has successfully utilized missionCommands.addCommandForGroup to call a function with multiple parameters I'd love to see how you got it to work.

 

Thanks!

Relent

Link to comment
Share on other sites

is the debug line at the very first line of your function? Because i DO confirm that the menu item logic IS working ...

 

Also, in which environment are you executing the mission. In multi player, there is an error. Groups with units with skill level Client will return NIL. So you getID() call would return NIL in MP.

[TABLE][sIGPIC][/sIGPIC]|

[/TABLE]

Link to comment
Share on other sites

Thanks for the response FlightControl.

 

My outText is near the top, but I tested (using witchcraft) calling the "to be called" function directly and it works fine - I get the outText text and it goes and does what it's supposed to do.

 

The group that I'm sending the F10 menu commands via missionCommands.addCommandForGroup(...) does contain a Client (i.e. it's the only unit within the group), but I'm seeing the menu items OK whether I run the mission in single player mode (i.e. Mission) or in multiplayer (as the host). So I haven't seen this issue where group:getID() returns a nil (unless you mean for a client connecting to the server that is not the host? I haven't tested this yet).

 

I'll keep plugging away, but in your case when you've called missionCommands.addCommandForGroup(...) you've been able to pass the called function more than one argument? Can you provide an example?

 

Thanks!

Relent

Link to comment
Share on other sites

Thanks for the response FlightControl.

 

My outText is near the top, but I tested (using witchcraft) calling the "to be called" function directly and it works fine - I get the outText text and it goes and does what it's supposed to do.

 

The group that I'm sending the F10 menu commands via missionCommands.addCommandForGroup(...) does contain a Client (i.e. it's the only unit within the group), but I'm seeing the menu items OK whether I run the mission in single player mode (i.e. Mission) or in multiplayer (as the host). So I haven't seen this issue where group:getID() returns a nil (unless you mean for a client connecting to the server that is not the host? I haven't tested this yet).

 

I'll keep plugging away, but in your case when you've called missionCommands.addCommandForGroup(...) you've been able to pass the called function more than one argument? Can you provide an example?

 

Thanks!

Relent

 

The problem that i have is, i am not using these low-level APIs anymore directly. I've made a framework around it...

 

Anyway, to answer your question on the argument... No, you cannot call the function with more than one argument. So, i do the same as you do, wrap the arguments in a table... And that works fine.

 

I can only give an example what i do in my MENU classes in MOOSE, where the "menu ids" are replace with objects. As such, the objects are handling the menus, and removing a menu with subtrees becomes one statement: Menu:Remove()

 

So, the following is an example of how i code menus:

 

self.EscortMenuHoldPosition[#self.EscortMenuHoldPosition+1] = MENU_CLIENT_COMMAND
     :New(
       self.EscortClient,
       MenuText,
       [b]self.EscortMenuHold[/b],
       ESCORT._HoldPosition,
       { ParamSelf = self,
         ParamOrbitGroup = self.EscortGroup,
         ParamHeight = Height,
         ParamSeconds = Seconds
       }
     )

The bolded is an object, which is created like this:

 

if not self.EscortMenuHold then
     self.EscortMenuHold = MENU_CLIENT:New( self.EscortClient, "Hold position", [b]self.EscortMenu[/b] )
   end

which again has a bolded class menu:

 

self.EscortMenu = MENU_CLIENT:New( self.EscortClient, self.EscortName )

 

 

Ohh, and the first parameter in these functions is a CLIENT object...


Edited by FlightControl

[TABLE][sIGPIC][/sIGPIC]|

[/TABLE]

Link to comment
Share on other sites

Thanks FlightControl - actually after doing some more digging and looking at the DCS.log I was able to determine one of the parameters in the table I was passing to the called function was in the wrong format. After fixing that the F10 command was calling the function correctly, so it was simply human error! :).

 

I'm still interested in the bug you mentioned:

Groups with units with skill level Client will return NIL. So you getID() call would return NIL in MP.
I guess I'll find out when I try my mission with a squad mate.

 

Any hints as to how to best get around this bug in MP (to save me some more digging :) )?

 

Thanks.

Relent

Link to comment
Share on other sites

Mr,

 

Maybe you want to consider this development to be used within your missions?

 

http://flightcontrol-master.github.io/MOOSE/Moose%20Training/Documentation/Menu.html

 

When it comes to the MP bug, you can easily get around it if you declare your planes as "CLIENTS", using the client class. You can then set menus using MENU_CLIENT. This will work in MP. There are a couple of examples within the framework that can be found here:

 

https://github.com/FlightControl-Master/MOOSE/tree/master/Moose%20Test%20Missions/Moose_Test_MENU_CLIENT

 

 -- This demo creates a menu structure for the two clients of planes.
 -- Each client will receive a different menu structure.
 -- To test, join the planes, then look at the other radio menus (Option F10).
 -- Then switch planes and check if the menu is still there.
 -- And play with the Add and Remove menu options.
 
 -- Note that in multi player, this will only work after the DCS clients bug is solved.

 local function ShowStatus( PlaneClient, StatusText, Coalition )

   MESSAGE:New( Coalition, 15 ):ToRed()
   PlaneClient:Message( StatusText, 15 )
 end

 local MenuStatus = {}

 local function RemoveStatusMenu( MenuClient )
   local MenuClientName = MenuClient:GetName()
   MenuStatus[MenuClientName]:Remove()
 end

 --- @param Client#CLIENT MenuClient
 local function AddStatusMenu( MenuClient )
   env.info(MenuClient.ClientName)
   local MenuClientName = MenuClient:GetName()
   -- This would create a menu for the red coalition under the MenuCoalitionRed menu object.
   MenuStatus[MenuClientName] = MENU_CLIENT:New( MenuClient, "Status for Planes" )
   MENU_CLIENT_COMMAND:New( MenuClient, "Show Status", MenuStatus[MenuClientName], ShowStatus, MenuClient, "Status of planes is ok!", "Message to Red Coalition" )
 end

 SCHEDULER:New( nil,
   function()
     local PlaneClient = CLIENT:FindByName( "Plane 1" )
     if PlaneClient and PlaneClient:IsAlive() then
       local MenuManage = MENU_CLIENT:New( PlaneClient, "Manage Menus" )
       MENU_CLIENT_COMMAND:New( PlaneClient, "Add Status Menu Plane 1", MenuManage, AddStatusMenu, PlaneClient )
       MENU_CLIENT_COMMAND:New( PlaneClient, "Remove Status Menu Plane 1", MenuManage, RemoveStatusMenu, PlaneClient )
     end
   end, {}, 10, 10 )

 SCHEDULER:New( nil,
   function()
     local PlaneClient = CLIENT:FindByName( "Plane 2" )
     if PlaneClient and PlaneClient:IsAlive() then
       local MenuManage = MENU_CLIENT:New( PlaneClient, "Manage Menus" )
       MENU_CLIENT_COMMAND:New( PlaneClient, "Add Status Menu Plane 2", MenuManage, AddStatusMenu, PlaneClient )
       MENU_CLIENT_COMMAND:New( PlaneClient, "Remove Status Menu Plane 2", MenuManage, RemoveStatusMenu, PlaneClient )
     end
   end, {}, 10, 10 )

 

 

Sven

[TABLE][sIGPIC][/sIGPIC]|

[/TABLE]

Link to comment
Share on other sites

Thanks FlightControl - looks like quite a framework,nice work... at this point I'm just trying to learn the DCS API and Lua so it's sort of fun to dig and test as well :).

 

 

 

Let me know when you are ready to start using it. You won't regret it. It will avoid you to reinvent the wheel.

 

Sent from mTalk on Windows 10 mobile

[TABLE][sIGPIC][/sIGPIC]|

[/TABLE]

Link to comment
Share on other sites

  • Recently Browsing   0 members

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