Jump to content

Get the value of the variable from the property of the trigger Zone?


Go to solution Solved by cfrag,

Recommended Posts

Posted (edited)

Hi

Please help, is it possible to get the value of this variable (property PROPERTY_1) from the trigger Zone element in the script?

[3] = 
{
	["radius"] = 1800,
	["zoneId"] = 825,
	["color"] = 
	{
		[1] = 1,
		[2] = 1,
		[3] = 1,
		[4] = 0.15,
	}, -- end of ["color"]
	["properties"] = 
	{
		[1] = 
		{
			["key"] = "PROPERTY_1", <=====
			["value"] = "222",      <=====
		}, -- end of [1]
	}, -- end of ["properties"]
	["hidden"] = false,
	["y"] = 446977.74215361,
	["x"] = -2121.1766461198,
	["name"] = "zone3",
	["heading"] = 0,
	["type"] = 0,
}, -- end of [3]

 

Screenshot_1.png

Edited by Kros

AMD 9800X3D, RTX 4080, DDR5 2x32GB 6400MHz, SSD GIGABYTE AORUS 2TB, HP Reverb G2r1, joy ffbeast

  • Solution
Posted (edited)
22 hours ago, Kros said:

is it possible to get the value of this variable (property PROPERTY_1) from the trigger Zone element in the script?

It requires some strong understanding of both Lua scripting and MSE, in particular the env.mission table.

DML does this routinely, as it uses named properties to pass values to its modules, so you might get some strong hints from there. 

In essence, you need to look at the array env.mission.triggers.zones which contains all trigger zones that are placed with Mission Editor, and of which you are showing element index 3. For example

local myZone = env.mission.triggers.zones[3]

That contains a table with many attributes, among them the "properties" attribute. Access that to get all properties for that zone

local myProperties = myZone.properties

The properties are arranged as an array (not a dict as that obviously would have made too much sense) of tables that all have a "key" and "value" entry. You are interested in the table that has a key attribute equal to "PROPERTY_1", and would then fetch and return the value attribute. To do that, you'd normally iterate all property array entries. Since we know that in your example we are interested in the first array entry, we can simply return the value like so (without checking that the property's name is "PROPERTY_1"):

return myProperties[1].value

For a more in-depth solution, please look at DML 'cfxZones' module's methods readFromDCS (general ME zone parsing) and extractPropertyFromDCS (retrieving a named property with and without case sensitivity)

 

Edited by cfrag
  • Like 1
Posted (edited)
7 часов назад, cfrag сказал:
Спойлер

It requires some strong understanding of both Lua scripting and MSE, in particular the env.mission table.

DML does this routinely, as it uses named properties to pass values to its modules, so you might get some strong hints from there. 

In essence, you need to look at the array env.mission.triggers.zones which contains all trigger zones that are placed with Mission Editor, and of which you are showing element index 3. For example

local myZone = env.mission.triggers.zones[3]

That contains a table with many attributes, among them the "properties" attribute. Access that to get all properties for that zone

local myProperties = myZone.properties

The properties are arranged as an array (not a dict as that obviously would have made too much sense) of tables that all have a "key" and "value" entry. You are interested in the table that has a key attribute equal to "PROPERTY_1", and would then fetch and return the value attribute. To do that, you'd normally iterate all property array entries. Since we know that in your example we are interested in the first array entry, we can simply return the value like so (without checking that the property's name is "PROPERTY_1"):

return myProperties[1].value

For a more in-depth solution, please look at DML 'cfxZones' module's methods readFromDCS (general ME zone parsing) and extractPropertyFromDCS (retrieving a named property with and without case sensitivity)

 

Thank you very much, everything worked out. I got access to the variables.

You are a developer DML? Can I ask, is it possible to change the course (heading) of the group through your scripts?

Edited by Kros

AMD 9800X3D, RTX 4080, DDR5 2x32GB 6400MHz, SSD GIGABYTE AORUS 2TB, HP Reverb G2r1, joy ffbeast

Posted
38 minutes ago, Kros said:

Can I ask, is it possible to change the course (heading) of the group through your scripts?

To change the heading of a group that is already in-game, you usually need to assign a new task, with a new course. This is one of the least fun things to do in DCS via scripts. There are currently no modules in DML dedicated to achieving this.

Posted (edited)
 
Ok, thanks !!!
Edited by Kros

AMD 9800X3D, RTX 4080, DDR5 2x32GB 6400MHz, SSD GIGABYTE AORUS 2TB, HP Reverb G2r1, joy ffbeast

  • Recently Browsing   0 members

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