Jump to content

Problem with removeItem (Lua Script)


hardnick

Recommended Posts

I created the Radio submenu to trigger the AI vehicles

But I try any kind of path. It can't delete the items in the submenu

Sometimes it will removes all Radio item (F10 is wiped)

What am I doing wrong? On the path?

I just want to delete that single item after the trigger (Like F-18 or Su-27)

thank you very much!

 

local function setFlags(v)

trigger.action.setUserFlag(v.flag, v.val)

missionCommands.removeItem(v.path)

end

 

local _path1 = missionCommands.addSubMenu("Fighters", nil)

local _path2 = missionCommands.addSubMenu("Tanks", nil)

 

local ai_1 = missionCommands.addCommand("F-18", _path1, setFlags, {flag=101, val=true, path=ai_1})

local ai_2 = missionCommands.addCommand("Su-27", _path1, setFlags, {flag=102, val=true, path=ai_2})

local ai_3 = missionCommands.addCommand("T-90", _path2, setFlags, {flag=201, val=true, path=ai_3})

local ai_4 = missionCommands.addCommand("T-72", _path2, setFlags, {flag=202, val=true, path=ai_4})


Edited by hardnick
Link to comment
Share on other sites

If I recall correctly, the string used to removeItem function is the first string passed to addCommand function, in your case "F-18" and not the path. Here's the documentation from SSE :

 

Adds a command to the "F10 Other" radio menu allowing players to run specified scripting functions. Command is added for both teams. The string name is the text that will be displayed in the F10 Other menu and is also used in the function to remove the command from the menu.

Path is an optional value that defines whether or not the command will be in a named submenu.

 

table missionCommands.addCommand(string name, table/nil path, function functionToRun , any anyArguement)

 

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

[sIGPIC]OK[/sIGPIC]

Link to comment
Share on other sites

Path is a table not a string.

 

With the above code you could change it like this:

 

local paths = {}

 

path['ai_1'] = missionCommands.addCommand("F-18", _path1, setFlags, {flag=101, val=true, path='ai_1'})

path['ai_2'] = missionCommands.addCommand("Su-27", _path1, setFlags, {flag=102, val=true, path='ai_2'})

 

etc.

 

For the remove item, you can use the following, which will look up the table value for it and remove that item.

 

missionCommands.removeItem(path[v.path])

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

Link to comment
Share on other sites

I got it! Example ForCoalition

removeItem Path will be :

 

actually

missionCommands.removeItemForCoalition(coalition.side.BLUE, {[1] = "Fighters", [2] = "F-18"})

 

so After understanding

missionCommands.removeItemForCoalition(coalition.side.BLUE, {[1] = v.path[1], [2] = v.path[2]})

 

Thank you guys!!!


Edited by hardnick
Link to comment
Share on other sites

  • 1 year later...
Path is a table not a string.

 

With the above code you could change it like this:

 

local paths = {}

 

path['ai_1'] = missionCommands.addCommand("F-18", _path1, setFlags, {flag=101, val=true, path='ai_1'})

path['ai_2'] = missionCommands.addCommand("Su-27", _path1, setFlags, {flag=102, val=true, path='ai_2'})

 

etc.

 

For the remove item, you can use the following, which will look up the table value for it and remove that item.

 

missionCommands.removeItem(path[v.path])

 

There must be something wrong here .... shouldn't it read:

path[b][u]s[/u][/b]['ai_1'] = missionCommands.addCommand("F-18", _path1, setFlags, {flag=101, val=true, path='ai_1'})
path[b][u]s[/u][/b]['ai_2'] = missionCommands.addCommand("Su-27", _path1, setFlags, {flag=102, val=true, path='ai_2'}) 


Edited by TOViper
got out how it should work, but found an obvious code bug ...

Visit https://www.viggen.training
...Viggen... what more can you ask for?

my computer:
AMD Ryzen 5600G | NVIDIA GTX 1080 Ti OC 11GB | 32 GB 3200 MHz DDR4 DUAL | SSD 980 256 GB SYS + SSD 2TB DCS | TM Warthog Stick + Throttle + TPR | Rift CV1

 

Link to comment
Share on other sites

I was saying he could use that within his function call where he passes the table v. There was a typo

 

 

So you'd keep a table that saves the value returned from adding the menu.

 

local path = {}

local function setFlags(v)
  trigger.action.setUserFlag(v.flag, v.val)
  missionCommands.removeItem(path[v.path])
end

local _path1 = missionCommands.addSubMenu("Fighters", nil)

path['ai_1'] = missionCommands.addCommand("F-18", _path1, setFlags, {flag=101, val=true, path='ai_1'})
path['ai_2'] = missionCommands.addCommand("Su-27", _path1, setFlags, {flag=102, val=true, path='ai_2'})

 

What happens when he selects F-18 from the list it calls the setFlags() function with the table {flag=101, val=true, path='ai_1'}

 

It then sets the flag based on what is in v.flag and v.val. The removeItem function looks at the path table and index 'ai_1' which is what was stored when creating the mission command and then removes it.

 

local whatever = missionCommands.addCommand('Hello World', nil, removeItem)

local function removeItem()
  missionCommands.removeItem(whatever)
end

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

Link to comment
Share on other sites

Thanks Grimes, adding items works fine now.

Currently I define the table "path" globally (without the word "local"), since I have to access it from the whole mission from everywhere.

 

One important thing regarding removing items:

This topic is still relevant, the bug is reproducable on my machine right now: https://forums.eagle.ru/showthread.php?t=116389

 

The menu containing the item is removed as well, not only the item!!!

How do you avoid that, just re-build the whole menu ... every second?


Edited by TOViper

Visit https://www.viggen.training
...Viggen... what more can you ask for?

my computer:
AMD Ryzen 5600G | NVIDIA GTX 1080 Ti OC 11GB | 32 GB 3200 MHz DDR4 DUAL | SSD 980 256 GB SYS + SSD 2TB DCS | TM Warthog Stick + Throttle + TPR | Rift CV1

 

Link to comment
Share on other sites

  • Recently Browsing   0 members

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