Jump to content

Simple IF THEN ELSE question


BFQ

Recommended Posts

How should I write a script in DCS to achive the following:

 

If "heli1" is inside "zone1", then:

Message: "Heli1 is inside zone1"

Flag 1=1

 

If "heli2" is inside "zone1", then:

Message: "Heli2 is inside zone1"

Flag 2=1

 

If "heli3" is inside "zone1", then:

Message: "Heli2 is inside zone1"

Flag 3=1

 

else

 

do nothing

 

Thx!

Link to comment
Share on other sites

You've basically already written exactly what you need to do. :)

 

Open up the mission editor and check out the triggers menu and it should be pretty self explanatory. If you want the message to only occur once, choose the ONCE type trigger; if you want it to occur every time the helicopter enters the zone, choose SWITCHED CONDITION. Doing nothing is assumed, you only need to write triggers for the three messages. The first one would look like this.

 

1 ONCE (Heli 1 enters zone 1, NO EVENT)

==

UNIT INSIDE ZONE (Heli 1, zone 1)

==

FLAG INCREASE (1, 1) -- alternately you could use FLAG ON (1) if you don't need a counter

MESSAGE TO ALL ("Heli 1 is inside zone 1", 10, true)

Link to comment
Share on other sites

You've basically already written exactly what you need to do. :)

 

Open up the mission editor and check out the triggers menu and it should be pretty self explanatory. If you want the message to only occur once, choose the ONCE type trigger; if you want it to occur every time the helicopter enters the zone, choose SWITCHED CONDITION. Doing nothing is assumed, you only need to write triggers for the three messages. The first one would look like this.

 

1 ONCE (Heli 1 enters zone 1, NO EVENT)

==

UNIT INSIDE ZONE (Heli 1, zone 1)

==

FLAG INCREASE (1, 1) -- alternately you could use FLAG ON (1) if you don't need a counter

MESSAGE TO ALL ("Heli 1 is inside zone 1", 10, true)

 

Yes, but I have a lot more helicopters and zones, so I thought it would be easier with a script, but I don't get the IF THEN part of scripting

Link to comment
Share on other sites

Yes, but I have a lot more helicopters and zones, so I thought it would be easier with a script

 

You'll need to use sets and iterators then.

Depending on what you're trying to achieve with those flags, it could be done without them, which would make the script shorter and simpler.

 

Now, if you really need all those flags, then you could do something like this (MOOSE script example, required fields marked in red):

 

 

local HeliSET = SET_GROUP:New()

:FilterPrefixes( "Common group prefix in ME" ) -- All the relevant helicopter groups must use this prefix in their ME group names

:FilterStart()

 

local Loop = 1

 

local function ZoneDetection(Loop , time)

 

--- Do the following for each relevant zone in ME

 

local ZoneX = ZONE:New("Name of the zone in ME") -- X should be the number of the zone (give it one)

local ZoneXName = ZoneX:GetName() -- X should be the same number as before

 

HeliSET:ForEachGroupCompletelyInZone(ZoneXName , -- X should be the same number as before

function(HeliGroup)

 

local HeliName = HeliGroup:GetName()

 

MESSAGE:New(HeliName.." is inside zone "..ZoneXName,10):ToAll() -- X should be the same number as before

 

if HeliName == "Name of the first heli group in ME" then

 

trigger.action.setUserFlag("Relevant flag in ME",1)

 

elseif HeliName == "Name of the second heli group in ME" then

 

trigger.action.setUserFlag("Relevant flag in ME",1)

 

elseif HeliName == "Name of the third heli group in ME" then

 

trigger.action.setUserFlag("Relevant flag in ME",1)

 

-- etc.

 

end

end

)

 

--- End of snippet for relevant zone. Copy/paste and modify it for each additional zone

 

if Loop == 1 then

return time + 10

end

end

 

timer.scheduleFunction(ZoneDetection, Loop , timer.getTime() + 10)

 

 

As I said, this would be much less of a hassle without all those specific flags. Depending on what you want to achieve, they might not be needed.

 

 

 

but I don't get the IF THEN part of scripting

 

What do you mean exactly? Are you referring to syntax?

 

Here's an example:

 

 

Sum = 5+5

Your_Guess = number

 

if Your_Guess == Sum then

 

print("Your guess is correct!") -- You'll only get this message if your guess is either 10 or 5+5

 

end

 

if Your_Guess ~= Sum then

 

print("Your guess is incorrect!") -- You'll get this message if your guess is neither 10 nor 5+5

 

end

 

 

--- It can also be written like this

 

Sum = 5+5

Your_Guess = number

 

if Your_Guess == Sum then

 

print("Your guess is correct!") -- You'll only get this message if your guess is either 10 or 5+5

 

 

elseif Your_Guess ~= Sum then

 

print("Your guess is incorrect!") -- You'll get this message if your guess is neither 10 nor 5+5

 

end

 

 

--- Or simply

 

 

Sum = 5+5

Your_Guess = number

 

if Your_Guess == Sum then

 

print("Your guess is correct!") -- You'll only get this message if your guess is either 10 or 5+5

 

else

 

print("Your guess is incorrect!") -- You'll get this message if your guess is neither 10 nor 5+5

 

end

 

 


Edited by Hardcard
Link to comment
Share on other sites

  • Recently Browsing   0 members

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