MagicRiggs Posted December 20, 2022 Posted December 20, 2022 Good day to everyone. Please help me understand what I'm missing when working with functions for creating and deleting menu items. Trigger "Mission Start", I set the action "Run script". Using a script, I create a couple of items in the F10 menu, and also put sub-items in them. local A = missionCommands.addSubMenu('Columns') local A1 = missionCommands.addCommand('One column', A,function() trigger.action.setUserFlag('C1',1) end) local A2 = missionCommands.addCommand('Two columns', A,function() trigger.action.setUserFlag('C1',2) end) local B = missionCommands.addSubMenu('Combat missions') local B1 = missionCommands.addCommand('Mission 1', B,function() trigger.action.setUserFlag('M1',1) end) The menu is created as intended. When the conditions are met, the subparagraphs of the first paragraph are deleted by the functions below, but the subparagraph of the second paragraph is not deleted... missionCommands.removeItem({['A'] = 'Columns', ['A1'] = 'One column'}) missionCommands.removeItem({['A'] = 'Columns', ['A2'] = 'Two columns'}) missionCommands.removeItem({['B'] = 'Combat missions', ['B1'] = 'Mission 1'})
Grimes Posted December 21, 2022 Posted December 21, 2022 The tables you are passing it aren't valid, but also aren't nil. The tables stored within A1 and A2 for example are actually this: { [1] = "Columns", [2] = "One column", } { [1] = "Columns", [2] = "Two columns", } However if you wanted to remove both of those at the same time you could just pass missionCommands.removeItem({[1] = "Columns"}) or effectively what is stored in A if you save that variable somewhere. 1 The right man in the wrong place makes all the difference in the world. Current Projects: Grayflag Server, Scripting Wiki Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread) SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum
MagicRiggs Posted December 21, 2022 Author Posted December 21, 2022 8 часов назад, Grimes сказал: The tables you are passing it aren't valid, but also aren't nil. The tables stored within A1 and A2 for example are actually this: { [1] = "Columns", [2] = "One column", } { [1] = "Columns", [2] = "Two columns", } However if you wanted to remove both of those at the same time you could just pass missionCommands.removeItem({[1] = "Columns"}) or effectively what is stored in A if you save that variable somewhere. Thx Grimes. Understood. It works. Can you explain how to correctly set the values of the variables in letters (A, A1, A2, B, B1), so that later I can use them to delete sub-items and the items themselves in my case?
Grimes Posted December 21, 2022 Posted December 21, 2022 Say you have a table that is global you can assign table entries as what gets returned by adding a command. table = {} table["Columns"] = missionCommands.addSubMenu('Columns') table["One column"] = missionCommands.addCommand('One column', A,function() trigger.action.setUserFlag('C1',1) end) table["Two columns"] = missionCommands.addCommand('Two columns', A,function() trigger.action.setUserFlag('C1',2) end) table["Combat missions"] = missionCommands.addSubMenu('Combat missions') table["Mission 1"] = missionCommands.addCommand('Mission 1', B,function() trigger.action.setUserFlag('M1',1) end) You could then call a given table entry when removing the menu you want. missionCommands.removeItem(table["Columns"]) table["Columns"] = nil -- best to delete it 1 The right man in the wrong place makes all the difference in the world. Current Projects: Grayflag Server, Scripting Wiki Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread) SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum
MagicRiggs Posted December 22, 2022 Author Posted December 22, 2022 Thanks a lot for your help with my question. I think that this example will be useful not only to me.
Recommended Posts