[ADDED] Cannot add ship to ferry mission via Lua, but can through GUI (Full Version)

All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Tech Support



Message


TheOttoman -> [ADDED] Cannot add ship to ferry mission via Lua, but can through GUI (10/30/2018 4:44:17 PM)

I have a big Lua script to set up a scenario that among other things, adds ports, creates a ferry mission to that port, creates some units, and then adds those units to the mission. I've included the script for troubleshooting.

The germane portion of my issue is this. I create the mission using this script:
ports = {"Port of Singapore","Port of Batu Ampar","Port of Jakarta"...} <- I've created the facilities earlier in the script

for i, nameofport in ipairs(ports) do
    ScenEdit_AddMission('Commercial','Transit to '..nameofport,'Ferry',{destination=nameofport})
end


and then
-- [[Commercial Container Vessel - Panamax]]
ccvpname = {"[VTM] M/V Vinalines Queen","[VTM] M/V Hai Nam 89","[VTM] M/V Vinalines Sunrise","[VTM] M/V Vinalines Brave","[VTM] M/V Inlaco Express"}

for i, name in ipairs(ccvpname) do
    RandomNumber()  
    RandomPort()
    ScenEdit_AddUnit({type="ship",unitname=name,side="Commercial",dbid="2028",base=PortName})
    RandomNumber()
    ScenEdit_AssignUnitToMission(name,'Transit to '..PortName)
end


RandomNumber is a 1,24 random number generator, and RandomPort assigns the variable PortName to a specific port based on the number randomly generated..


When I run this in Lua, I get the message in the game message window "[VTM] M/V Vinalines Queen is not an aircraft and cannot be added to a Ferry mission" or something similar for each ship it tries to process.


However.... if I go into the Mission Editor (F11), I see all of the missions created as expected, and I see all of the ships as unassigned units, and I can manually assign them to any of the missions.

Am I doing something wrong in the Lua script?




michaelm75au -> RE: Cannot add ship to ferry mission via Lua, but can through GUI (10/31/2018 8:21:23 AM)

I will take a look.




michaelm75au -> RE: Cannot add ship to ferry mission via Lua, but can through GUI (10/31/2018 8:57:34 AM)

The base code doesn't allow a non-aircraft unit to be assigned to a mission.
I don't believe it has been updated for ship/submarines as the Editor Mission has empty settings for the ship/submarine also.
---
Okay, ships can be assigned to mission, but the code hasn't been fully updated.

I will look into it.

Thanks for heads up.




michaelm75au -> RE: Cannot add ship to ferry mission via Lua, but can through GUI (10/31/2018 12:35:38 PM)

for i, name in ipairs(ccvpname) do
    RandomNumber()
    RandomPort()
    ScenEdit_AddUnit({type="ship",unitname=name,side="Commercial",dbid="2028",base=PortName})
    RandomNumber()
    ScenEdit_AssignUnitToMission(name,'Transit to '..PortName)
end


Is this structured correctly? You are adding a ship to 'PortA', and then assigning it to 'transit to portA'.
Isn't this just going to leave the port, and then follow the mission to go back to the port?? It isn't going anywhere.
Shouldn't it be doing
        RandomNumber()
RandomPort()
[with some sort of check that it is not going to the port it is based at]
    ScenEdit_AssignUnitToMission(name,'Transit to '..PortName)





TheOttoman -> RE: Cannot add ship to ferry mission via Lua, but can through GUI (10/31/2018 1:21:03 PM)

In theory, the first random number generator will deliver a number and based off of that number assign it to the corresponding Port. It then runs the random number generator again and uses that result to set the destination for the Ferry mission.

There's currently 24 numbers, so yes, there's a 1:24 chance that the ship will be assigned to the port it's currently in.




michaelm75au -> RE: Cannot add ship to ferry mission via Lua, but can through GUI (11/1/2018 8:53:24 AM)

I was trying to point out that the variable PortName is set in RandomPort(). You run RandomNumber, but don't set a new PortName.




TheOttoman -> RE: Cannot add ship to ferry mission via Lua, but can through GUI (11/1/2018 6:23:15 PM)


quote:

ORIGINAL: michaelm75au

I was trying to point out that the variable PortName is set in RandomPort(). You run RandomNumber, but don't set a new PortName.

Gotcha.

I guess I'll have to do RandomPort() again




TheOttoman -> RE: Cannot add ship to ferry mission via Lua, but can through GUI (11/9/2018 12:02:44 AM)

998.13 seems to have mention of a fix for my issue.... at least it says "Part 1"

I've installed the build and the script works as expected.

Thanks!




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
0.84375