Lua question involving ship

All discussions & material related to Command's Lua interface

Moderators: angster, RoryAndersonCDT, michaelm75au, MOD_Command

DWReese
Posts: 2607
Joined: Fri Mar 21, 2014 11:40 am
Location: Miami, Florida

Lua question involving ship

Post by DWReese »

(First off, I am no Lua expert, so please keep this in mind. Generally, any success that I have ever had with Lua has come from following the excellent work of others.)

Now, I have a question concerning a SHIP that is already assigned to a mission and then later being directed by Lua to perform a new mission. Specifically, I want it to first conduct a Land Attack with Tomahawks (I did that) on one target, and then two hours later I want the ship to begin a ASW search in another certain designated area. This is my goal.

Here's some background. I have previously managed to send planes out on a Mission to Marshal (Loiter in an area), and when the time was right, I then use a Lua Script to break them away from that Marshal mission and then send them off on another different (Support) mission. So, I figured that if I could do it with planes, then I should be able to do it with ships.

The exact situation:
--I first assigned a SHIP on a plotted course. (This is ONLY thing different than the planes. Perhaps it makes a difference?) So, the ship is sailing from point A to Point B.
--A few minutes into the scenario, I have a DELAYED land attack mission to that becomes active and it assigns the ship to conduct the attack. As expected, the ship fires its Tomahawk, and everything is working great.
--The Land Attack mission is still active (time-wise), but there are no more targets so the ship continues to sail from Point A to Point B.
--Approximately 2 hours later, I now want to assign the same ship to leave the Land Attack Mission and begin conducting a ASW Patrol Mission in an area that I have previously set up, but the ship currently is NOT within the boundaries of that area.

The mission does fire as indicated, but the ship does not get assigned to the new mission.

So, my questions are:
1. Does it matter that the SHIP was given a Plotted Course, and is that WHAT is keeping the Lua Script from allowing the ship to conduct the ASW mission?
2. Does it matter that the ship isn't INSIDE the ASW patrol area? Is that what is keeping the mission from occurring.
3. Are ships handled differently than planes when trying to do this? Is this why it isn't working?

I have used the following Lus Script with the plane (described above) and it worked:
ScenEdit_AssignUnitToMission('Redcock #1', 'Jammer')

I have used a similar one (the same format) with the ship and it doesn't work.
ScenEdit_AssignUnitToMission('USS Jacksonville', 'Sub Search')

What am I missing? What am I not doing correctly? I've spent hours on this, but I personally believe that there is some kind of syntax error, whatever that really entails. <lol>

I have uploaded this snippet. The ship has already conducted its land strike, and is now 90 seconds away from being assigned to the new mission, which is set to occur at 4:10 pm. The new mission fires, but the ship isn't removed from the land strike mission to the new mission.

Thanks in advance.


Doug
Attachments
Escort1a22.zip
(72.92 KiB) Downloaded 17 times
User avatar
stilesw
Posts: 1572
Joined: Wed Jun 25, 2014 10:08 pm
Location: Hansville, WA, USA

RE: Lua question involving ship

Post by stilesw »

Hi Doug,

Here is a test scenario that is similar to what I think you want:

1. DDG is on a plotted course.
2. There is an inactive mission to strike a command center in Western Iraq.
3. Mission activates when the DDG enter a specified area (Iraq also declared hostile.
4. When the building is destroyed it activates a trigger to assign the DDG to a pre-defined ASW mission.

Not exactly like yours but the mission assignment works.

Hope this helps,

-Wayne
Attachments
MissionChange.zip
(28.79 KiB) Downloaded 19 times
“There is no limit to what a man can do so long as he does not care a straw who gets the credit for it.”

Charles Edward Montague, English novelist and essayist
~Disenchantment, ch. 15 (1922)
DWReese
Posts: 2607
Joined: Fri Mar 21, 2014 11:40 am
Location: Miami, Florida

RE: Lua question involving ship

Post by DWReese »

Thanks, Wayne.

I will try it out right now.

Admittedly, I am not very good with Lua, so I sincerely thank anyone who takes time out of their day to help me.

Doug
DWReese
Posts: 2607
Joined: Fri Mar 21, 2014 11:40 am
Location: Miami, Florida

RE: Lua question involving ship

Post by DWReese »

Wayne,

I just tried your scenario. It had some mixed results.

Your scenario DID manage to change the assigned mission from the land strike to the ASW mission, so that part was great. Unfortunately, as soon as the ship was given its new mission, while it did appear in the Mission Box, the ship instead resumed its original plotted path (just like with my scenario). The ship proceeded along the plotted path to the NE, then to the S, then it began heading W before the time ran out. It never attempted to head for the ASW zone.

Also, did you take a look at my Lua script for sending MY ship on the ASW mission? I can't see any difference between mine and yours, except that yours worked and mine didn't. <lol>

Thanks again for taking time out of your day to look into this for me. I sincerely appreciate your efforts.

Doug
User avatar
stilesw
Posts: 1572
Joined: Wed Jun 25, 2014 10:08 pm
Location: Hansville, WA, USA

RE: Lua question involving ship

Post by stilesw »

Very strange! I just reran it (thinking that I had not let it run long enough). When the building was destroyed, the DDG was assigned to the ASW mission, dropped its previous plotted course, went right to the mission area and started patrolling.

I did see that there were no apparent differences between our Lua script assignments.

Could we be running different versions? I am using CMANO public build v1.14, B998.10 with DB3K_475.db3 (07/29/18) and DBInfo.dat (07/30/18).

Also, check your mission doctrine. Probably not the issue but who knows...

If you are using the same one let me know so that I can dig around some more.

-Wayne


Image
Attachments
Doctrine2Phone.jpg
Doctrine2Phone.jpg (47.01 KiB) Viewed 429 times
“There is no limit to what a man can do so long as he does not care a straw who gets the credit for it.”

Charles Edward Montague, English novelist and essayist
~Disenchantment, ch. 15 (1922)
DWReese
Posts: 2607
Joined: Fri Mar 21, 2014 11:40 am
Location: Miami, Florida

RE: Lua question involving ship

Post by DWReese »

Wayne,

I am using the same as you, and the Doctrine is the same, too.

Doug
DWReese
Posts: 2607
Joined: Fri Mar 21, 2014 11:40 am
Location: Miami, Florida

RE: Lua question involving ship

Post by DWReese »

I ran it again, and this time it worked fine.

Can you try to get my scenario to send my ship off on the ASW mission? I'm thinking that if my Lua Script is the same as yours, then it SHOULD work the same.

Can you see if it works for you?

Doug
User avatar
stilesw
Posts: 1572
Joined: Wed Jun 25, 2014 10:08 pm
Location: Hansville, WA, USA

RE: Lua question involving ship

Post by stilesw »

Doug,

Think I found it! The mission is named "Sub Seach" but the Lua event is ScenEdit_AssignUnitToMission("USS Jacksonville", "Sub Search"). Easy to miss the fact that Seach != Search. Much to my chagrin, I've likely done it hundreds times during my programming life.

Also noticed that the land strike mission has no designated targets which could be ok except that the box is checked for Pre-planned targets (in target list) only. And, Engage opportunity targets is set to no. In all likely hood the four targets (or any for that matter) should never be fired on.

Let me know if this fixes things.

-Wayne
“There is no limit to what a man can do so long as he does not care a straw who gets the credit for it.”

Charles Edward Montague, English novelist and essayist
~Disenchantment, ch. 15 (1922)
DWReese
Posts: 2607
Joined: Fri Mar 21, 2014 11:40 am
Location: Miami, Florida

RE: Lua question involving ship

Post by DWReese »

Wayne,

As the Bon Jovi song goes, "we're halfway there..."

First, I guess that I need to request that they add a "spell check" mechanism to their mission planning. <lol>

Okay, that did indeed fix the Mission part of the problem. It now fires and it assigns the ship to the mission. But,......I am back to the issue of the ship continuing along the plotted course instead of heading toward the ASW area.

I know that there are three different Doctrines that can alter the ship's performance (one in the Side Doctrine (Game Options); one found in the Unit Orders; one found in the Mission Editor Doctrine. I have all three set to "Yes" to "Ignore the plotted course....", and I have the Side Doctrine and the Unit Orders set to "No" as far as firing at targets of opportunity. If I don't do this, then the ship starts firing Tomahawks everywhere. Even if I remove every enemy unit from the globe, and set the Doctrine to engage any enemy targets, the ship still sails on the plotted course.

I can't figure it out.

Doug
DWReese
Posts: 2607
Joined: Fri Mar 21, 2014 11:40 am
Location: Miami, Florida

RE: Lua question involving ship

Post by DWReese »

Here is the revised file:
Attachments
Escort1a22.zip
(72.89 KiB) Downloaded 13 times
User avatar
stilesw
Posts: 1572
Joined: Wed Jun 25, 2014 10:08 pm
Location: Hansville, WA, USA

RE: Lua question involving ship

Post by stilesw »

Hah!

Really got me going (The Kinks - 4 August 1964). More digging in the morning. My wife just got home and it's 17:52 PDT here.

-Wayne
“There is no limit to what a man can do so long as he does not care a straw who gets the credit for it.”

Charles Edward Montague, English novelist and essayist
~Disenchantment, ch. 15 (1922)
Whicker
Posts: 665
Joined: Tue Jun 19, 2018 9:54 pm

RE: Lua question involving ship

Post by Whicker »

I think the problem is that the course was manually plotted, and that takes precedence.

if you do:
local a = ScenEdit_GetUnit({name="USS Jacksonville"})
print(a.course)

you get:
{ [1] = { latitude = 34.7302302023159, longitude = 24.7867751562778, TypeOf = 'ManualPlottedCourseWaypoint' } }

and that last bit - ManualPlottedCourse.... I think is important. I think this is good, plenty of times I want a unit to go over here first, then go back to your patrol areas.

One way I think to get rid of the plotted course is to set the course to empty {}

so this works for me:

local a = ScenEdit_GetUnit({name="USS Jacksonville"})
a.course = {}
ScenEdit_AssignUnitToMission('USS Jacksonville', 'Sub Search')

DWReese
Posts: 2607
Joined: Fri Mar 21, 2014 11:40 am
Location: Miami, Florida

RE: Lua question involving ship

Post by DWReese »

Thanks for chiming in.

I would agree with you, but.....in the scenario that Wayne created, which is very similar to mine, his ship also has a plotted course and his ship abandons that plotted course when given the new ASW Mission. He has included his scenario a few messages back. Perhaps, if you have the time, you can look at both and see if you can find the problem. Essentially both appear to be the same, but one works and the other does not, even with the plotted course.

Doug
User avatar
stilesw
Posts: 1572
Joined: Wed Jun 25, 2014 10:08 pm
Location: Hansville, WA, USA

RE: Lua question involving ship

Post by stilesw »

Hey Doug,

Still here. Just tried Whicker's code and it does indeed work. However, as you point out, my test seemed to work also.

I have a suspicion that there may be a timing issue involved. The land strike mission will(may)continue until all the targets have been destroyed. I've observed that the DDG is listed Status: Engaged Offensive (Underway) until the strike is complete. It may be that only then will it be able to cleanly change to the ASW patrol. I could well be wrong but that's what I'm going to check next.

-Wayne
“There is no limit to what a man can do so long as he does not care a straw who gets the credit for it.”

Charles Edward Montague, English novelist and essayist
~Disenchantment, ch. 15 (1922)
DWReese
Posts: 2607
Joined: Fri Mar 21, 2014 11:40 am
Location: Miami, Florida

RE: Lua question involving ship

Post by DWReese »

Okay, I got it to work, and it did have something to do with the plotted course (or so it appears).

The ship was plotted to sail at 83 degrees at 10 kts. When the new mission was assigned, it would be transferred to the mission, but never head to the area.

So, in setting up the unit with the plotted course, I clicked on it and prepared to plot another course. But, instead of plotting a course, I just clicked hit the escape button which eliminated the course. I then clicked off of the ship. The ship still showed that it was programed to sail at 83 degrees at 10 knots. When the scenario began it sailed at that heading until being given the new mission. Once assigned to the ASW mission, it turned and headed for it at 10 knots.

So, actually having the line on the screen indicating that it is plotted makes a difference. This will be a problem if you were developing a larger scale scenario with several turns planned BEFORE your mission is supposed to take place, but this probably isn't a big issue.

Check it out.

Doug
User avatar
stilesw
Posts: 1572
Joined: Wed Jun 25, 2014 10:08 pm
Location: Hansville, WA, USA

RE: Lua question involving ship

Post by stilesw »

Still don't know how the test case with a plotted course appeared to work. A thought - for my DDG I had the speed set at 12 knots but did not have the Manual Override box checked. I'll have to check that.

-Wayne
“There is no limit to what a man can do so long as he does not care a straw who gets the credit for it.”

Charles Edward Montague, English novelist and essayist
~Disenchantment, ch. 15 (1922)
User avatar
stilesw
Posts: 1572
Joined: Wed Jun 25, 2014 10:08 pm
Location: Hansville, WA, USA

RE: Lua question involving ship

Post by stilesw »

Doug,

Just rechecked your scenario and your Manual Speed Override box is checked. Could be a culprit.

-Wayne
“There is no limit to what a man can do so long as he does not care a straw who gets the credit for it.”

Charles Edward Montague, English novelist and essayist
~Disenchantment, ch. 15 (1922)
Whicker
Posts: 665
Joined: Tue Jun 19, 2018 9:54 pm

RE: Lua question involving ship

Post by Whicker »

there is a difference between the two - Wayne has a target, and has a course that goes away from the target at times. With Ignore plotted course = yes, if you highlight his ship and leave it there you will see the AI change the course a couple times, I think this breaks the ManuallyPlottedCourse bit that keeps the original course.

Dougs doesn't have a target, and is also pointed directly at the possible target - even with ignore = yes, the ship doesn't change course (AI) so the manually plotted course still takes precedence.

Also, on Waynes, I did it 3 times, one time it actually did the same as Dougs and kept the original course, I think this had to do with the AI course kept reverting back to the original course.

I would guess that if Doug added a target and changed the plotted course to be not pointed right at it then it would act the same most of the time. But I don't think the expected behavior is to drop the manually plotted course when it is assigned to a mission.
DWReese
Posts: 2607
Joined: Fri Mar 21, 2014 11:40 am
Location: Miami, Florida

RE: Lua question involving ship

Post by DWReese »

The beginning of my scenario (which I didn't provide) assigned the ship to contact one attack on one of the buildings, using one missile. At the beginning of the scenario the ship had been given that course, generally toward the target building. Since the ship was assigned to attack just one specific building, the ship never attacked anything else. That mission worked perfect.

Then, after a few minutes, the ship was to given a new mission to head for the ASW area. This is the point where I provided the scenario. It was just a few minutes before the ASW mission was to take place. Originally, I suspected that the plotted course might be the problem, but I also figured that it was a syntax error somewhere. Wayne found that one, so now the scenario fires as it should. But, at the point where you jumped aboard, the ship still wouldn't head to the area.

I believe that you are correct that the plotted course was the problem. I tried Wayne's and it worked more often than not, but I also had a failure with Wayne's, as well. With my scenario, it would not work at all.

That is, until I made the change that I spoke about with the plotted course and hitting the escape button. Certainly, this isn't the way that it was designed to work, but as long as the ship is headed forward, it continues on that course until something changes it. As you said, once the cycle gets broken, then it reverts to what it is supposed to do.

One final thing about this. I set the ship (via the Mission Editor) to proceed to the patrol area at Cruise Speed (which is 20 kts for the ship) and then at Creep Speed (5 kts.) for the actual patrol. But, the ship (which had originally been on that 10 kt speed) stayed on that 10 kt speed all the way to the patrol area, instead of the desired and expected 20 kts. I believe that this data was left over from the original plot. Once inside the patrol zone, and upon reaching the end point, the ship dropped down to 5 kts. So, it would appear that once the cycle is broken, the ship does, in fact, revert to what it is supposed to do.

Doug
DWReese
Posts: 2607
Joined: Fri Mar 21, 2014 11:40 am
Location: Miami, Florida

RE: Lua question involving ship

Post by DWReese »

I tried out your last hypothesis, but it didn't work. I changed the course to the NW before beginning the scenario. The ship was headed away from the target buildings when the new ASW mission order was given. Even though it was headed in the opposite direction, it continued to move on the plotted course.

I then did what I said, clicking on the unit, and highlighting the direction, but then hitting the Escape button without making a new plot. The old plot was gone, but the direction and speed were still listed with the ship. The ship continued on that path until the new ASW mission was assigned.

Agai, the only potential problem was that you did not get the desired speed for the ship to head to the ASW patrol zone. The ship was still stuck at 10 kts.

It's an interesting situation.

Doug
Post Reply

Return to “Lua Legion”